home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / guide / rmi / activation / code / Setup3.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  3.7 KB  |  99 lines

  1. /*
  2.  * Copyright (c) 1998, 1999 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  5.  * modify and redistribute this software in source and binary code form,
  6.  * provided that i) this copyright notice and license appear on all copies of
  7.  * the software; and ii) Licensee does not utilize the software in a manner
  8.  * which is disparaging to Sun.
  9.  *
  10.  * This software is provided "AS IS," without a warranty of any kind. ALL
  11.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  12.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  13.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  14.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  15.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  16.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  17.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  18.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  19.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  20.  * POSSIBILITY OF SUCH DAMAGES.
  21.  *
  22.  * This software is not designed or intended for use in on-line control of
  23.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  24.  * the design, construction, operation or maintenance of any nuclear
  25.  * facility. Licensee represents and warrants that it will not use or
  26.  * redistribute the Software for such purposes.
  27.  */
  28. package examples.activation; 
  29.  
  30. import java.rmi.*;
  31. import java.rmi.activation.*;
  32. import java.util.Properties;
  33.  
  34. public class Setup3 {
  35.  
  36.     // This class registers information about the MyClass
  37.     // class with rmid and the rmiregistry
  38.     //
  39.     public static void main(String[] args) throws Exception {
  40.     
  41.     System.setSecurityManager(new RMISecurityManager());
  42.     
  43.     // After JDK1.2Beta4, ActivationGroups are no longer created
  44.     // implicitly as a side-effect of creating or registering the
  45.     // first Activatable object
  46.     //
  47.     // Because of the 1.2 security model, a security policy should 
  48.     // be specified for the ActivationGroup VM. The first argument
  49.     // to the Properties put method, inherited from Hashtable, is 
  50.     // the key and the second is the value 
  51.     // 
  52.     Properties props = new Properties(); 
  53.     props.put("java.security.policy", 
  54.        "/home/rmi_tutorial/activation/policy"); 
  55.     
  56.     ActivationGroupDesc.CommandEnvironment ace = null; 
  57.     ActivationGroupDesc exampleGroup = new ActivationGroupDesc(props, ace);
  58.     
  59.     // Once the ActivationGroupDesc has been created, register it 
  60.     // with the activation system to obtain its ID
  61.     //
  62.     ActivationGroupID agi = 
  63.        ActivationGroup.getSystem().registerGroup(exampleGroup);
  64.     
  65.     // Now explicitly create the group
  66.     //
  67.     ActivationGroup.createGroup(agi, exampleGroup, 0);
  68.  
  69.     // Don't forget the trailing slash at the end of the URL
  70.     // or your classes won't be found
  71.     //    
  72.     String location = "file:/home/rmi_tutorial/activation/";
  73.  
  74.     // Create the rest of the parameters that will be passed to
  75.     // the ActivationDesc constructor
  76.     //
  77.     MarshalledObject data = null;
  78.  
  79.     // The second argument to the ActivationDesc constructor will be used 
  80.     // to uniquely identify this class; it's location is relative to the 
  81.     // URL-formatted String, location.
  82.     //
  83.     ActivationDesc desc = new ActivationDesc 
  84.         ("examples.activation.MyClass", location, data);
  85.     
  86.     AnotherRemoteInterface ari = 
  87.         (AnotherRemoteInterface)Activatable.register(desc);
  88.     System.out.println("Got the stub for MyClass");
  89.  
  90.     // Bind the stub to a name in the registry running on 1099
  91.     //
  92.     Naming.rebind("MyClass", ari);
  93.     System.out.println("Exported MyClass");
  94.  
  95.     System.exit(0);
  96.     }
  97.  
  98. }
  99.