/* * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * -Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * -Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that Software is not designed, licensed or * intended for use in the design, construction, operation or * maintenance of any nuclear facility. */ package examples.activation; import java.rmi.*; import java.rmi.activation.*; import java.rmi.registry.*; import java.util.Properties; /** * This program registers information about a remote object * with the activation system (rmid), and then binds a stub * for the remote object in the rmiregistry so that clients * can look it up. The remote object's implementation class must be * supplied on the command line. When a client invokes a remote method on * the stub acquired from the registry, the remote object will activate. * *

This program should be run as follows: *

 *	java -Djava.security.policy=setup.policy        \
 *	    -Djava.rmi.server.codebase=codebase         \
 *	    -Dexamples.activation.setup.codebase=setupCodebase  \
 *	    -Dexamples.activation.impl.codebase=implCodebase \
 *	    -Dexamples.activation.name=name	      \
 *	    [-Dexamples.activation.file=filename]       \
 *	    [-Dexamples.activation.policy=group.policy] \
 *	    examples.activation.Setup implClass
 * 
* *

where:

* *

Note: rmid must be running on its default port, and * rmiregistry must be running on its default port prior to * running this program. **/ public class Setup { /** * Prevents instantiation. */ private Setup() {} public static void main(String[] args) throws Exception { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } /* * Get the impl class argument from the command line. */ String implClass = ""; if (args.length < 1) { System.err.println( "usage: java [options] examples.activation.Setup "); System.exit(1); } else { implClass = args[0]; } /* * Construct an activation group descriptor. * * First, create a properties map containing overrides for system * properties in the activation group VM. Add a value for the * "java.security.policy" system property to the properties map. * The value for the security policy file is specified by the * "examples.activation.policy" system property which defaults to * the file named "group.policy" in the working directory. * * Also add the value for the "examples.activation.impl.codebase" system * property to the map, which is specified by the * "examples.activation.impl.codebase" system property. This property * is used in the group's policy file. **/ String policy = System.getProperty("examples.activation.policy", "group.policy"); String implCodebase = System.getProperty("examples.activation.impl.codebase"); String filename = System.getProperty("examples.activation.file", ""); Properties props = new Properties(); props.put("java.security.policy", policy); props.put("java.class.path", "no_classpath"); props.put("examples.activation.impl.codebase", implCodebase); if (filename != null && !filename.equals("")) { props.put("examples.activation.file", filename); } ActivationGroupDesc groupDesc = new ActivationGroupDesc(props, null); /* * Register the activation group descriptor with the activation * system to obtain a group ID. */ ActivationGroupID groupID = ActivationGroup.getSystem().registerGroup(groupDesc); System.err.println("Activation group descriptor registered."); /* * Construct an activation descriptor for the activatable object. * * The location specifies a URL from where the implementation class * can be loaded when this object is activated. The value of the * URL is specified by the "examples.activation.impl.codebase" system * property. * * The data (optional) specifies initialization data passed to the * remote object when being constructed as part of the activation * process. Here, the value of "data" is specified by the * "examples.activation.filename" system property and represents * the name of a file containing the object's persistent state (to * be read in when the object is activated). */ MarshalledObject data = null; if (filename != null && !filename.equals("")) { data = new MarshalledObject(filename); } ActivationDesc desc = new ActivationDesc(groupID, implClass, implCodebase, data); /* * Register the activation descriptor with the activation system. * Use the convenience method 'Activatable.register' which returns * a constructed stub for the activatable object after registering * the activation descriptor. */ Remote stub = Activatable.register(desc); System.err.println("Activation descriptor registered."); /* * Bind the activatable object's stub to a name in the registry * running on port 1099. The name is specified by the system * property "examples.activation.name". */ String name = System.getProperty("examples.activation.name"); LocateRegistry.getRegistry().rebind(name, stub); System.err.println("Stub bound in registry."); } }