Compiling and running of a RMI application

First please download Find.java, FindImpl.java, and FindClient into a directory, say $HOME/cmpt401/java. Now take the following 10 steps.

1. Compile the server and client programs

Type

 %javac FindImpl.java FindClient.java 

This will generate Find.class, FindImpl.class, and FindClient.class.

2. Run the RMI compiler (stub generator)

Type

 %rmic FindImpl 

Note that the argument is acually FindImpl.class, which contains all the information needed to construct the stubs. Thus, unlike the RPC stub generator we introduced in class, rmic processes the server implementation class (in byte code), not the interface definition file. The stub generator generates two files, FindImpl_Stub.class and FindImpl_Skel.class. (The latter is no longer used for RMI in Java 2.)

3. Set up the server codebase

Copy the two class files, Find.class and FindImpl_Stub.class to the codebase, say, $HOME/java/codebase for copying to the rmiregistry and future downloading to client machines. Suppose that the server machine is called orion.csil.sfu.ca in sequel.

4. Prepare for the client

ftp the files, FindClient.class and Find.class to the client machine (we call it xyz thereinafter) anywhere in the Internet, where you will run FindClient. For now, ftp the file FindImpl_Stub.class as well to the client machine. (We will delete it from there later; See Step 10.)

5. Start Registry

Type

 %rmiregistry 2099 & 

from any directory in your server (orion.csil.sfu.ca) host. This directory should not contain the file FindImpl_Stub.class generated above. Once started rmiregistry will keep running forever.

For a Windows machine, you need to type

 C:\>start rmiregistry 2099 

6. Prepare the target file

Create a file, e.g., phonebook.txt, in the current directory (where you will run FindImpl.class), which consists of a name and his/her phone number on each line. This file will be the argument to the server when you start it. (see Step 8).

7. Set up an http server

As discussed in class, we know that the client stub will be downloaded to the client side. To this end, we need an http server running on the server machine.

Since a full-edged http server (e.g., Appache) is very heavy, a simple http server called ClassFileServer written in Java is provided. To run it, read the instructions given in Set up a mini http Server. We will assume that this server uses port 2001.

8. Start up the server

We assume that the server machine is orion.csil.sfu.ca. If not, use the appropriate host name where the codebase is located. (You also need to change the relevant statement in FindClient.java.)

Type

 %java -Djava.security.policy==mypolicy.txt -Djava.rmi.server.codebase=http://orion.csil.sfu.ca:2001/ FindImpl phonebook.txt

Do not forget the "/" after the port number. This command should be typed all in one line; do not insert any extra space, except for the four places, i.e., before two -D's, FindImpl. The second -D field informs the rmiregistry where the stub class, FindImpl_Stub.class is available. Note that an http-based URL is used here, since the client stub will be commonly read from the codebase by an http server (We have just started). When the server is started, observe the output from ClassFileServer.

Important: Before starting rmiregistry on the server machine, make sure that CLASSPATH on the server machine does not contain paths to the stubs to be downloaded to clients.

The option -Djava.security.policy==mypolicy.txt in the command line is to inform the Security Manager of your permission policy. mypolicy.txt is a file in the current directory specifying the "security policy", and may contain just one line.

grant { permission java.security.AllPermission; }; 

Note the spelling of AllPermission; it has no s at the end.

9. Start and test Client

telnet to the client machine xyz (assuming that you are still at the server machine) to which you ftp'ed the relevant files in Step 4 above.

In the directory where the ftp'ed class files are located, type

 %java -Djava.security.policy==mypolicy.txt FindClient ABC

Make sure that you have a copy of mypolicy.txt in the current directory on this client machine as well. Here you are trying to find the phone number of a person named ABC.

10. Simplify it

If everything works fine, then delete FindImpl_Stub.class from the current (client) directory, and run FindClient again.

Watch the output from the ClassFileServer (http server) on the server machine. Can you explain why?