SDSU CS 696 Emerging Technologies: Java Distributed Computing
Spring Semester, 1999
More RMI Activation
Previous    Lecture Notes Index    Next    
© 1999, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 04-May-99

Contents of Doc 33, More RMI Activation


References

Re: RMID and Activation FAQ questions, Bob Scheifler email message, May 3 1999, JINI-USERS@JAVA.SUN.COM, list server for JINI
List server archives: http://archives.java.sun.com/archives/jini-users.html
Scheifler's mail message: http://archives.java.sun.com/cgi-bin/wa?A2=ind9905&L=jini-users&F=&S=&P=2040


Doc 33, More RMI Activation Slide # 2

Activation and JVMs


In activation one has some control over which JVM is used to run the activatable object upon activation. The options are the JVM used to register the object with rmid or a new JVM.

Activation in the Current JVM

You must create an activation group in current JVM with ActivationGroup.createGroup

When you create an ActivationDesc to use to register the activatable object, have that use the activation group in the current JVM

Activation in a New JVM

No not create an activation group with ActivationGroup.createGroup.


Doc 33, More RMI Activation Slide # 3

Activation in Current JVM - Example

package whitney.rmi.examples.activation;
import java.rmi.*;
import java.rmi.activation.*;
import java.util.Properties;
public class RegisterHelloServer 
   {
      public static void main(String[] args) throws Exception 
      {
      Properties policyFileLocation = new Properties(); 
      policyFileLocation.put("java.security.policy", 
         "/export/home/whitney/.java.policy");
      ActivationGroupDesc.CommandEnvironment ace = null; 
      ActivationGroupDesc exampleGroup = new 
         ActivationGroupDesc(policyFileLocation, ace);
 
       ActivationSystem localActivationSystem = 
         ActivationGroup.getSystem();
      ActivationGroupID agi = 
         localActivationSystem.registerGroup(exampleGroup);
      //The activation group is what creates the activatible object in a JVM
      // Sets the activation group for the current JVM
      ActivationGroup.createGroup(agi, exampleGroup, 0);
      String classLocation = "file:/export/home/whitney/java/classes/";
      String serverClass = 
         "whitney.rmi.examples.activation.HelloServer";
      MarshalledObject data = null;
      // Since the ActivationGroupID is not given in the constructor of desc, the 
      // current JVM’s activation group is used
      boolean restart = true;
      ActivationDesc desc = 
         new ActivationDesc(serverClass, classLocation, data, restart);

Doc 33, More RMI Activation Slide # 4
Activation in Current JVM - Example Continued

      Hello stub = (Hello)Activatable.register(desc);
         
      Naming.rebind("HelloServer", stub);
      //Access the server to force activation. Object is created in 
      // current JVM
      System.out.println( stub.sayHello());
      //This is bad news, exit here kills the JVM that the server is using.
      // 
      System.exit(0);
      }
   }

Doc 33, More RMI Activation Slide # 5

Activation in New JVM - Example

package whitney.rmi.examples.activation;
import java.rmi.*;
import java.rmi.activation.*;
import java.util.Properties;
public class RegisterHelloServer 
   {
      public static void main(String[] args) throws Exception 
      {
      Properties policyFileLocation = new Properties(); 
      policyFileLocation.put("java.security.policy", 
         "/export/home/whitney/.java.policy");
      ActivationGroupDesc.CommandEnvironment ace = null; 
      ActivationGroupDesc exampleGroup = 
         new ActivationGroupDesc(policyFileLocation, ace);
 
       ActivationSystem localActivationSystem = ActivationGroup.getSystem();
      ActivationGroupID agi = 
         localActivationSystem.registerGroup(exampleGroup);
      String classLocation = "file:/export/home/whitney/java/classes/";
      String serverClass = "whitney.rmi.examples.activation.HelloServer";
      MarshalledObject data = null;
      // Note that the ActivationGroupID is an argument in the constructor. rmid
      //  will create a new JVM and an activationGroup in the JVM
      // to activate this object.
      boolean restart = true;
      ActivationDesc desc = 
         new ActivationDesc(agi, serverClass, classLocation, data, restart);
      
      Hello stub = (Hello)Activatable.register(desc);
         
      Naming.rebind("HelloServer", stub);

Doc 33, More RMI Activation Slide # 6
Activation in New JVM – Example Continued

      //Access the server to force activation. Object is created in 
      // current JVM
      System.out.println( stub.sayHello());
      //This exit is ok here. The server is running in a different JVM
      System.exit(0);
      }

Doc 33, More RMI Activation Slide # 7

HelloServer

For completeness of the example here is the HelloServer code
package whitney.rmi.examples.activation;
import java.net.InetAddress;
import java.rmi.*;
import java.rmi.activation.*;
public class HelloServer  extends Activatable implements Hello 
   {
   public HelloServer(ActivationID id, MarshalledObject data) 
      throws RemoteException 
      {
      super( id, 0 );
      }
   public String sayHello() 
      {
      return  "Hello World from " + getHostName();
      }
   protected static String getHostName() 
      {
      try 
         {
         return InetAddress.getLocalHost().getHostName();
         }
      catch (java.net.UnknownHostException who) 
         {
         return "Unknown";
         }
      }
   }

Doc 33, More RMI Activation Slide # 8

Hello

package whitney.rmi.examples.activation;
public interface Hello extends java.rmi.Remote 
   {
   String sayHello() throws java.rmi.RemoteException;
   }

Copyright ©, All rights reserved.
1999 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

Previous    visitors since 04-May-99    Next