02152  Concurrent Systems - NP Lab 3: Java RMI
Technical University of Denmark DTU
02152 Concurrent Systems        Fall 2008
NP Lab 3: Java RMI
Home Plan Material  

Purpose

This lab should give you a basic experience with the use of Remote Method Invocation (RMI) in Java.

Time and Place

Assistance for this programming lab will be available in the G-databar, Building 308, Rooms 15 + 16, Monday, November 10, 10.00-12.00.

Preparations

This describes the third set of practical exercises for the Network Programming part of the course in Concurrent Systems. The exercises assume that you have read at least Sections 1 to 10 of ``The Poor Man's Guide to Computer Networks and their Applications'' [PMG].

Java RMI

Develop a simple program for querying system properties on a remote server using Java RMI. The remote service which supplies the system properties should have the interface defined by the following Java source code.
  import java.rmi.*;
  import java.rmi.server.*;

  public interface RemoteSysinfo extends Remote
  { public String getSysinfo(String systemProperty) 
                             throws java.rmi.RemoteException;
  }  

The implementation of this remote interface is to use the System.getProperty() method to find the value of the property whose name is given by the systemProperty argument to the getSysinfo method.

You will need to write the following pieces of software:

  1. An implementation of a (remote) class which implements this interface.
  2. A client which uses the method of the interface to look up properties on a given remote system. The client should accept names of properties from the user, look up the value of the property and print it out on the user's console. It should catch any exceptions that are caused and react suitably to inform the user.
You are advised to use the remote object and the client shown in PMG Figures 10.5 and 10.6 as inspiration for how to do this. It should not be necessary to deal with security policies when the remote stub-class is directly available for the client program, eg. by being located in the same directory/project at the remote class.

Then follow the instructions given in [PMG 10], pages 75-78 in order to start the rmiregistry, activate the remote object and finally activate the client.

Since the rmiregistry will use port 1099 by default, only the first group to start it will succeed. Therefore, each group should chose an arbitrary port (> 1024) and pass that as a parameter to the registry. E.g.

  rmiregistry 39192

Correspondingly, the client should use that port in the URI used for the Naming.bind and Naming.lookup.

Test out your program in two ways:

  1. Simple test of functionality: The user inputs names of various properties to the client.

    Look in the documentation of method System.getProperties() to see what properties are available.

  2. Timing test: Measure how long time it takes for the remote method to return its return value.

    To get an accurate measurement, you are advised to modify your client so that it can make the same remote call a large number of times in succession.

IMPORTANT: When you have finished, make sure that you kill the process in which the RMI registry that you started is running. Otherwise, subsequent users may not be able to start their RMI programs. Use ps | fgrep rmi to see if you have any registries running and if so, kill them with kill -9 <processid>.

More on truly distributed RMI

If you are going deploy your client and server programs in a truly distributed setting, ie. running on different machines, you are likely to experience issues with security policies and firewalls.

For a more comprehensive discussion, see the page on RMI details

[Originally by Robin Sharp, 2002-2003. Modified by Hans Henrik Løvengreen 2004-2007.]
Hans Henrik Løvengreen, Nov 7, 2008