WhiteBoard Using RMI
WSU CEG 7370 WhiteBoard Using Java RMI
WbClientImpl.java
Go to the documentation of this file.
1 // file: WbClientImpl.java by pmateti@wright.edu
2 
3 package WhiteBoard;
4 
5 import java.io.*;
6 import java.util.*;
7 import java.rmi.*;
8 import java.awt.Color;
9 
10 public class WbClientImpl
11  extends java.rmi.server.UnicastRemoteObject
12  implements WbClient {
13 
14  private WbServer wbServer;
15  private String thisMcnm, myBoardNm, myURL, myServerURL;
16  private Color myColor;
18 
19  // create our lines frame process, which will do recvDisplayObj()
20  private void makeMyLinesFrame(String [] args) throws Exception {
21  Invoke.javaVM
22  ('L', args[1] + " " + args[2] + " " + thisMcnm + " " + args[0]);
23  }
24 
25  public WbClientImpl(String [] args) throws Exception {
26  // args = [clientId, brdNm, displayMcnm, wbserverURL, color]
27  super();
28 
29  myBoardNm = args[1];
30  myURL = Invoke.makeURL('C', args[0]);
31  Naming.rebind(myURL, this);
32  Invoke.myPrint("WbClientImpl", "did Naming.rebind " + myURL);
33 
34  thisMcnm = java.net.InetAddress.getLocalHost().getHostName();
35  makeMyLinesFrame(args);
36  myServerURL = args[3];
37  wbServer = (WbServer) Invoke.lookup(myServerURL);
38  myColor = new Color(Integer.parseInt(args[4], 16));
39  Invoke.myPrint("WbClient waiting for", "recvDisplayObj");
40  // addClient() occurs in recvDisplayObj()
41  }
42 
43  // this comes from wbServer
44  public void updateBoard(LineCoords ln) throws java.rmi.RemoteException {
45  myLinesFrame.recvOneLine(ln);
46  }
47 
48  // the rest come from our LinesFrame
49 
50  public void sendAllLines() throws java.rmi.RemoteException {
51  wbServer.sendAllLines(this, myBoardNm);
52  }
53 
54  public void sendLine(LineCoords ln) {
55  ln.c = myColor;
56  try {wbServer.addLine(ln, myBoardNm);}
57  catch (Exception e) {e.printStackTrace();}
58  }
59 
60  public void recvDisplayObj(LinesFrame s) {
61  Invoke.myPrint("WbClient waiting Ended", "" + s);
62  myLinesFrame = s;
63  try {wbServer.addClient(this, myBoardNm);}
64  catch (Exception e) {e.printStackTrace();}
65  }
66 
67  public void pleaseDie() throws java.rmi.RemoteException {
68  try {
69  wbServer.delClient(this, myBoardNm);
70  Naming.unbind(myURL);
71  } catch (Exception e) {e.printStackTrace();}
72  Invoke.myPrint("WbClient ", myURL + " exits");
73  System.exit(0);
74  }
75 
76  public static void main(String args[]) {
77  try {WbClientImpl me = new WbClientImpl(args);}
78  catch (Exception e) {e.printStackTrace();}
79  }
80 }
81 
82 // -eof-
void sendLine(LineCoords ln)
static void main(String args[])
WbClientImpl(String[] args)
static Remote lookup(String url)
Definition: Invoke.java:77
void makeMyLinesFrame(String[] args)
void updateBoard(LineCoords ln)
void recvDisplayObj(LinesFrame s)
Copyright © 2014 www.wright.edu/~pmateti;   thanks to doxygen