The Setup class

The Setup class creates all the information necessary for the activatable class, without creating an instance of the remote object. This class registers information about the LazyServerImpl class with rmid and the rmiregistry.


Listing 13.3 Setup.java


import java.rmi.*;
import java.rmi.activation.*;
import java.util.Properties;
public class Setup {

  //This class registers information 
  //about the LazyServerImpl
  //class with rmid and the rmiregistry
  public static void main(String[] args) throws Exception {
	
	//install a security manager
	RMISecurityManager sm = new RMISecurityManager();
	System.setSecurityManager(sm);

	//The first argument
	//to the Properties put method, is 
	//the key and the second is the value 
	Properties props = new Properties(); 
	props.put("java.security.policy", 
	 "file:/c:/Lazy/policy.txt");
	ActivationGroupDesc agd = 
		new ActivationGroupDesc(props, null);
	
	//Register the group 
	//with the activation system to obtain its ID
	ActivationGroupID agi = 
		ActivationGroup.getSystem().registerGroup(agd);
	 
	//Explicitly creating the group
	ActivationGroup.createGroup(agi, agd, 0);
	
	//The "location" String specifies a 
	//URL from where the class 
	//definition will be loaded.
	String location = "file:/c:/Lazy/";
	
	//A Marshaled Object contains a 
	//byte stream with the serialized 
	//representation of an object 
	MarshalledObject data = null;

	//Construct an object descriptor 
	ActivationDesc desc = new ActivationDesc 
		("LazyServerImpl", location, data);
	
	 //Register with rmid
	 LazyInterface li = 
		(LazyInterface)Activatable.register(desc);
	 System.out.println("Registered");
	
	 //Bind the stub to a name in the 
	 //registry running on 1099
	 Naming.rebind("LazyServer", li);
	 System.out.println("Exported LazyServerImpl");
	System.exit(0);
    }
}

Explanation of Code


Here is the Setup class declaration:

public class Setup {

Installing a security manager.

RMISecurityManager sm = new RMISecurityManager();
System.setSecurityManager(sm);

Creating an ActivationGroup instance.

Properties props = new Properties(); 
props.put("java.security.policy", 
 "file:/c:/Lazy/policy.txt");
ActivationGroupDesc agd = new ActivationGroupDesc(props, null);

//Register the group 
//with the activation system to obtain its ID
ActivationGroupID agi = 
	ActivationGroup.getSystem().registerGroup(agd);
	 
//Explicitly creating the group
ActivationGroup.createGroup(agi, agd, 0);

An activation group descriptor contains the necessary information to create an activation group in which to activate objects. The descriptor contains the following information:

  • the group(s) class name,
  • the location of the group(s) class, and
  • a marshalled object that contains initialization data.

The ActivationGroupID object:

  • identifies the group uniquely within the activation system, and
  • contains a reference to the group(s) activation system so that the group can contact its activation system when necessary.

Creating an ActivationDesc.

String location = "file:/c:/Lazy/";
	
//A Marshaled Object contains a byte stream with the serialized 
//representation of an object 

MarshalledObject data = null;

//Construct an object descriptor 

ActivationDesc desc = new ActivationDesc 
	("LazyServerImpl", location, data);

 

An activation descriptor contains the information necessary to activate an object. It contains the following:

  • object(s) group identifier,
  • object(s) class name,
  • object(s) code location,
  • a marshalled object that contains initialization data.

 

The following lines declare a reference of remote interface and register the activation descriptor with rmid.

LazyInterface li = (LazyInterface)Activatable.register(desc);
System.out.println("Registered");

Binding the stub to a name in the rmiregistry and exiting.

 Naming.rebind("LazyServer", li);
 System.out.println("Exported LazyServerImpl");
 System.exit(0); 


 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com