WhiteBoard Using RMI
WSU CEG 7370 WhiteBoard Using Java RMI
Invoke.java
Go to the documentation of this file.
1 // @file: InvokeSystem.java @author pmateti@wright.edu */
2 
3 package WhiteBoard;
4 
5 import java.io.*;
6 import java.rmi.*;
7 
8 public class Invoke {
9  public static int verbosity = 1; // controls myPrint()
10  private static BufferedReader stdIn; // stdinput, buffered
11  private static int pid = 0; // pseudo process-id
12 
13  //! The following Srings isolate path related issues.
14 
15  private static String javaCmd = "java"; // Verify the path
16  // On Linux, e.g.: "/usr/lib/jvm/jdk1.7.0_51/bin/java";
17  // On Windows, e.g.: "e:\\jdk1.6.10\\bin\\java";
18 
19  private static final String rmiRegistryPfx = "//localhost/";
20  private static final String serverClass = "WhiteBoard.WbServerImpl";
21  private static final String clientClass = "WhiteBoard.WbClientImpl";
22  private static final String linesClass = "WhiteBoard.LinesFrameImpl";
23  private static final String classNames[]
25 
26  public static void setJavaCmdPath(String s) {
27  javaCmd = s;
28  }
29 
30  // for use during development
31  public static void myPrint(String who, String what) {
32  if (verbosity > 0)
33  System.out.println(who + ": " + what);
34  }
35 
36  // post: return the users input; make sure it is non-empty
37  public static String promptAndGet(String msg) {
38  if (stdIn == null)
39  stdIn = new BufferedReader(new InputStreamReader(System.in));
40 
41  String s = null;
42  try {
43  System.out.print(msg + ": ");
44  System.out.flush();
45  s = stdIn.readLine();
46  } catch (Exception e) {e.printStackTrace();}
47  if (s == null || s == "") s = "empty";
48  return s;
49  }
50 
51  /** Invoke java on the given class in a separate process.
52  Also, take care of any exceptions. */
53 
54  public static void javaVM(char c, String args) {
55  pid ++;
56  String classNm = classNames[c == 'S'? 0 : c == 'C' ? 1 : 2];
57  String cmd = javaCmd + " " + classNm + " " + pid + " " + args;
58 
59  try {
60  Runtime r = Runtime.getRuntime();
61  myPrint("Runtime " + r, cmd);
62  try {
63  Process p = r.exec(cmd);
64  myPrint("Process", "" + p);
65  } catch(Exception e) {
66  System.out.println("Error executing r.exec(" + cmd + ")");
67  }
68  } catch(Exception e) {
69  System.out.println("Runtime Error executing [" + cmd + "]");
70  }
71  }
72 
73  public static String makeURL(char c, String id) {
74  return rmiRegistryPfx + c + id;
75  }
76 
77  public static Remote lookup(String url) {
78  for (int j = 0; j < 10; j++)
79  try {
80  return Naming.lookup(url);
81  } catch (Exception e) {
82  myPrint("Naming.lookup(", url + ") not found yet ...");
83  try {Thread.sleep(1000);}
84  catch (Exception x) {x.printStackTrace();}
85  }
86  return null;
87  }
88 
89  public static void main(String[] args) {
90  Invoke.javaVM('S', "");
91  }
92 }
93 
94 // -eof-
static final String rmiRegistryPfx
Definition: Invoke.java:19
static final String serverClass
Definition: Invoke.java:20
static void myPrint(String who, String what)
Definition: Invoke.java:31
static final String classNames[]
Definition: Invoke.java:24
static Remote lookup(String url)
Definition: Invoke.java:77
static String javaCmd
The following Srings isolate path related issues.
Definition: Invoke.java:15
static String promptAndGet(String msg)
Definition: Invoke.java:37
static int pid
Definition: Invoke.java:11
static void javaVM(char c, String args)
Invoke java on the given class in a separate process.
Definition: Invoke.java:54
static final String linesClass
Definition: Invoke.java:22
static void setJavaCmdPath(String s)
Definition: Invoke.java:26
static BufferedReader stdIn
Definition: Invoke.java:10
static String makeURL(char c, String id)
Definition: Invoke.java:73
static final String clientClass
Definition: Invoke.java:21
static int verbosity
Definition: Invoke.java:9
static void main(String[] args)
Definition: Invoke.java:89
Copyright © 2014 www.wright.edu/~pmateti;   thanks to doxygen