COMP 310
Fall 2010

Lec25:  Remote Method Invocation (RMI)

Home  Info  Owlspace  Resources

Before we start on RMI, let's finish our discussion on deletion from self-balancing trees using extended visitors...

ABC Music Player Issues:

Remote Method Invocation

Today we will start exploring the world of Remote Method Invocation or "RMI".  

Information on RMI can be found in the Comp310 Java Resources web pages.

The demo code for today can be obtained by creating a  new project in Eclipse and setting the svn:externals property for the "src" folder to "provided".

The demo code consists of two executable classes, a "client" and a "server" plus an interface that defines the remote service that the server offers to the client.   

Be sure that the Server machine has the Server.REGISTRY_PORT and Server.SERVER_PORT open through its firewall!!

To run the server:

  1. Highlight the Server file and click Run.   
  2. Highlight the Client file and click Run.

To stop the running server:

  1. Change to the server's console by either closing the console of the client if it open by clicking the "x" on the console tab or by selecting the server's console by pulling down the "Display Selected Console" drop-list on the console tab.
  2. Click the red square "Terminate" button on the console tab. 


RMI Hello World

What's going on:

  1. The server binds a Server stub (a Hello interface implementation just like Server itself) to the name "Hello" in the Registry.

  2. The client asks for the name "Hello" in the server's Registry and receives the stub to the Server object.

  3. The client calls sayHello() on the stub object.

  4. The stub transparently delegates the call all the way across the network to the actual Server object on the server machine.

  5. The Server object runs its sayHello() method and returns the result.

  6. The stub returns the result across the network back to the waiting client.


Things to try:

To create your own modifications, simply create your own Client, Server, and Hello classes in your own package by copying the code from the provided package and then adjusting the package references.   Do NOT edit the code in the provided package as you will not be able to commit your code!

  1. Bind multiple Server implementations to the same name in the Registry:
    1. Start the original Server.
    2. Change the return value of sayHello() method of the Server class to return a different value.
    3. Without terminating the previous Server , run the Server again.
    4. Without modifying it, run the Client again.
    5. Even though the original Server is still running, what is the value retrieved by the Client?
  2. Bind multiple Server implemenations to different names in the Registry.
    1.  Start a version of the Server.
    2. Run the Client to verify the value returned is what you expect.
    3. Modify the Server's sayHello() method to return a different value.
    4. Modify the Server's run() method to bind the Hello object with a different name.
    5. Without terminating the previous Server , run the Server again.
    6. Without modifying it, run the Client again.   What value is returned?
    7. Modify the Client so that it accesses the new Registry binding name being used in the modified Server code above.
    8.  Run the Client again.   What value is returned?










© 2010 by Stephen Wong and Scott Rixner