Does there exist a minimal "Hello" kind of an example for getting started with the Remote Object Activation feature of RMI?

Avi Kak

The minimal "Hello" programs have played an important role in helping people get started with the various programming languages and paradigms. Here is a "Hello" program for Remote Object Activation in Java. This program does basically the same thing as what is achieved by an RMI implementation of a typical "HelloServer" program. The main difference here is that we no longer have a continuously running "Hello" server. Instead, the HelloImpl server object is activated only when it is needed by a client. (Note that this simple example here does not illustrate how Java's remote object activation deals with data persistence. But it does illustrate how to set up the activation framework for an activatable server object.)

Getting this code to run consists of executing the following steps:

  • Step 1: Compile all class files
  • Step 2: On the server side, run rmic on the HelloImpl class and copy the stub over to the client side.
  • Step 3: On the server side, execute the shell file activate.sh.
  • Step 4: On the client side, execute the bat file runclient.bat.

Since I used a Solaris machine as a server and an NT machine as a client, for command line invocations I have a shell file on the server side and a bat file on the client side. Although these files are trivial in this example and are not really needed, I have included them so that the reader can compare the simple invocations here with those found elsewhere in the remote object activation tutorials.

For a detailed discussion of the classes and methods used in the code shown below, the reader is referred to the RMI Specification document and to the remote object activation tutorials.

//////  server and client file:  Hello.java   //////

import java.rmi.*;

public interface Hello extends Remote {
    public String sayHello() throws RemoteException;

//////      server file:  HelloImpl.java      //////

import java.rmi.*;
import java.rmi.activation.*;

public class HelloImpl extends Activatable implements Hello {

  public HelloImpl( ActivationID id, MarshalledObject data )
        throws RemoteException
    super( id, 0 );

  public String sayHello()
    return "Hello from Avi Kak";

//////   server file:  ActivationSetup.java   //////

import java.rmi.*;
import java.rmi.activation.*;

public class ActivationSetup {

  public static void main( String[]  args ) throws Exception
    ActivationGroupID agi = ActivationGroup.getSystem().registerGroup(
         new ActivationGroupDesc( null, null ) );
    ActivationDesc desc = new ActivationDesc( agi, "HelloImpl", null, null );
    Hello helloserver = (Hello) Activatable.register( desc );
    Naming.rebind( "rmi://localhost/HelloServer", helloserver );

//////      server file:  activate.sh       //////

rmid -C-Djava.rmi.server.logCalls=true &
rmiregistry &
sleep 1
java ActivationSetup

//////    client file:  HelloClient.java   //////

import java.rmi.*;

public class HelloClient {
  public static void main( String[] args ) throws Exception
    Hello server = ( Hello ) Naming.lookup( "rmi://RVL4.ecn.purdue.edu/HelloServer" );
    System.out.println( server.sayHello() );

///////   client file:  runclient.bat    ///////

java HelloClient

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.