A White Board Project using Java RMI
The bundle of Java src code in this directory implements the Whiteboard P0 in Java using RMI, but leaves out a few pieces for you TODO. It should work equally well on both Linux and Windows. The overall behavior is nearly identical to the C-RPC Whiteboard P0.
1 Compilation + Build
I did not use any fancy IDE, but you are welcome to use Intellij Idea, Eclipse, …
1.1 Original v Generated Files
The following files are written by me. All others are generated.
java7370.sh // bash file, do: source java7370.sh Invoke.java // support methods LineCoords.java // public data structure for a line LinesFrame.java // our little window of lines LinesFrameImpl.java // implementation of window of lines WbAdmin.java // interface of wbadministrator WbServer.java // interface of WhiteBoard server WbClient.java // interface of WhiteBoard client WbClientImpl.java // implementation of WhiteBoard client WbServerImpl.java // implementation of WhiteBoard server
1.2 Java Env
Make sure your CLASSPATH
includes .
and ..
. The rmic
is similar to
rpcgen
but examines .class
files, not .java
files, in producing
several _Stub.class
files
Make sure you are invoking the proper javac
java
, et al. On many
systems, there are multiple versions of JDK installed. The java
javac rmic rmiregistry rmid
should all be from the same package and
version.
which java # check where your java JVM is located java -version
1.3 Simple Build
You can call wb7370build
defined in java7370.sh
. This is the
simplest way to build, as javac
subsumes some of the Makefile
features. Before invoking it, make sure you are in the parent dir of
*.java
files.
2 How to Run It
source java7370.sh
to define the various bash
methods used below.
2.1 java.policy
JDK installations will have their own system wide java.policy
file;
e.g., on my machine the full path name is
/usr/lib/jvm/jdk1.7.0_45/jre/lib/security/java.policy
The
SocketPermission
s may not be good enough. So, create a
~/java.policy
file in your home directory. It can be much more
detailed than the one below.
% cat << EOF > ~/java.policy grant { permission java.net.SocketPermission "*:1024-65535", "connect,accept"; permission java.net.SocketPermission "*:80", "connect"; }; EOF
2.2 rmiregistry
Before starting the WB server and clients, do wb7370rmi
to establish
rmiregistry
.
For rmiregistry
: If port 1099 is in use already, you need to make
corresponding edits in Invoke.java
.
2.3 Starting the WB Servers and Clients
There are several ways of running our Java WB program. wb7370run
defined in java7370.sh
is one such example that starts one server
and two clients each on two boards.
Server will print its URL, e.g.,
//localhost/S1
.
In general, to start a client do: % java WhiteBoard.WbClientImpl
<idn> <boardnm> <displayMcnm> <URL-of-server>
The idn is an arbitrary
non-neg integer used as a pseudo process id. An example URL for the
server is //localhost/S1
. The client will start a LinesFrame.
Or you may invoke these text-interactively from % java
WhiteBoard.WbAdmin
The disadvantage here is that the stdout
is then
not seen.
You may find the pj
alias defined in java7370.sh
useful.
2.4 How Does It Work
No client draws a line, even in its own window, the moment you click in its window. Instead, the client sends the coordinates to its server, the server informs all clients on this board, including this one, of this update.
pleaseDie()
: If we really die in a remote method, the caller will
get an exception. So, we make sure the method returns normally, and
die a little later. A pragmatic solution.
addClient()
occurs in recvDisplayObj()
3 Subtleties
Window Expose(s): I did not find what the expose event is called in
Java. So did a work around using public void
windowActivated(WindowEvent e)
Please send me a better solution!
So to see lines of a window that was just uncovered, click on the
title bar.
You may also find that occasionally some mouse clicks are "lost".
I do not think it is worth our time to properly fix these.
I did not focus at all on a nice GUI. If that interests, by all means improve it.