THE UNIVERSITY OF WESTERN AUSTRALIA
School of Computer Science & Software Engineering
CITS3213 CONCURRENT SYSTEMS
Mini Laboratory Sheet on Java Remote Method Invocation (RMI)
The purpose of this lab is to learn how to use Java RMI. Some examplefiles and step-by-step instructions are supplied. If you missed the lecture on RMI, .
Please note that javac is supposed to generate the stub class in Java 1.6. However, I had to run rmic (as described below) even though I have java 1.6 in my machine.You should follow the instructions below and report if you have any problem.
Tasks
- contains the interface.
- contains the server code.
- contains the client code.
Note : You will find the following line in this code :
private static final String registry = "//bilby.cs.uwa.edu.au/";
You have to change 'bilby' to the name of your machine. - is the file with security policy. This will be needed later.
- We will first run both the client and the server on the same machine under the same login i.e., your login.
- Compile the two files HelloImplementation.java and RemoteHelloClient.java in the usual way, i.e., by using javac
- Use the RMI compiler rmic to compile the HelloImplementation class file :
rmic HelloImplementation
This will create the stub file : HelloImplementation_Stub.class
- Now start the RMI registry in the background :
rmiregistry&
- Now bind the server to the RMI registry :
java -Djava.security.policy=test.policy HelloImplementation
- Now execute the client :
java -Djava.security.policy=test.policy RemoteHelloClient
- You will get the output from the server.
- Remember to set read permission for all your files including test.policy
To run this from another machine :
Additional Larger Tasks
You can also run the larger example that I covered in the Here is the to the relevant section of Java tutorial. You can cut and paste the code from the above link.
Modify the Java code for the producer-consumer example () so that the Producer and Consumer objects are clients running on different computers that use RMI to invoke methods on a remote Buffer object.
- Here's the code to modify: , , and .
- You will need to create an appropriate interface, and follow roughly the steps in the first example (above).
- You'll also need to write main methods for both clients (Producer and Consumer) and the server (Buffer). Again, follow the above example.
May, 2008.