CS 696 Emerging Technologies: Java Distributed Computing Spring Semester, 1999 More RMI Activation |
||
---|---|---|
© 1999, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 04-May-99 |
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.
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);
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); } }
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);
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); }
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"; } } }
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