Making a UnicastRemoteObject Activatable


This page shows you the steps for migrating an existing UnicastRemoteObject to an activatable object, by extending java.rmi.activation.Activatable.  This page is just for developers who wish to change an existing class from being a sub-class of UnicastRemoteObject to being a sub-class of java.rmi.activation.Activatable. If you are interested in finding out about Creating an Activatable Object or Activating an object that does not extend java.rmi.activation.Activatable, these are also available as tutorials.

Prior to the release of the JDK1.2, an instance of a UnicastRemoteObject could be accessed from a server program that (1) created an instance of the remote object, and (2) ran all the time. Now with the introduction of the class java.rmi.activation.Activatable and the RMI daemon, rmid, programs can be written to register information about remote object implementations that should be created and execute "on demand", rather than running all the time. The RMI daemon, rmid, provides a JVM from which other JVM instances may be spawned.

Note:  For the remainder of this tutorial, the terms "activatable object implementation", "activatable object," and "implementation" may be used interchangeably to refer to  the class, examples.activation.MyRemoteInterfaceImpl, which implements a remote interface and is activatable.

This tutorial is organized as follows:

The files needed for this tutorial are: You may notice that while the client code is included, it is not discussed in a step-by-step manner, like the implementation and setup classes. The reason for this omission, is that the client code for activatable objects is no different than the RMI client code for accessing non-activatable remote objects.  Activation is strictly a server-side implementation decision.

For all of the source code used in the activation tutorials, you may choose from these formats:



Creating the implementation class

For this example, the implementation class will be examples.activation.MyRemoteInterfaceImpl. There are four steps to migrate an existing implementation class that extends from UnicastRemoteObject:

  1. Make the appropriate imports in the implementation class
  2. Modify the class declaration so that the class now extends from java.rmi.activation.Activatable
  3. Remove or comment out the old no-argument constructor
  4. Declare a two-argument constructor in the implementation class

Creating the "setup" class

Unlike the RMI server class that must stay alive as long as the implementation needs to be made available, the job of the "setup" class is to create all the information necessary for the activatable class, without necessarily creating an instance of the remote object. For this example the setup class will be examples.activation.Setup2.

The setup class passes information about the activatable class to rmid, registers a remote reference (an instance of the activatable class's stub class) and an identifier (name) with the rmiregistry, and then the setup class may exit.  There are six steps to create a setup class:

  1. Make the appropriate imports
  2. Install a SecurityManager
  3. Create an ActivationDesc instance
  4. Remove the reference to the implementation class creation,  and register with rmid
  5. Bind the stub to a name in the rmiregistry
  6. Quit the setup application
  7. Step 1:
    Make the appropriate imports in the setup class


Compile and run the code

There are six steps to compile and run the code:

  1. Compile the remote interface, implementation, client  and setup classes
  2. Run rmic on the implementation class
  3. Start the rmiregistry
  4. Start the activation daemon, rmid
  5. Run the setup program
  6. Run the client
  7. Step 1:
    Compile the remote interface, implementation, client and setup classes

    % javac -d . MyRemoteInterface.java
    % javac -d . MyRemoteInterfaceImpl.java
    % javac -d . Client2.java
    % javac -d . Setup2.java

    Step 2:
    Run rmic on the implementation class

    % rmic -d . examples.activation.MyRemoteInterfaceImpl

    Step 3:
    Start the rmiregistry

    In order to run this code on your system, you'll need to change the location of the policy file to be the location of the directory on your system, where you've installed the example source code.


Copyright © 1998 Sun Microsystems, Inc. All Rights Reserved.