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 / Setup.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  4.0 KB  |  102 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 Setup {
  35.  
  36.     // This class registers information about the ActivatableImplementation
  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.     // The "location" String specifies a URL from where the class   
  70.     // definition will come when this object is requested (activated).
  71.         // Don't forget the trailing slash at the end of the URL 
  72.         // or your classes won't be found.
  73.         //       
  74.     String location = "file:/home/rmi_tutorial/activation/";
  75.  
  76.     // Create the rest of the parameters that will be passed to
  77.     // the ActivationDesc constructor
  78.     //
  79.     MarshalledObject data = null;
  80.  
  81.     // The second argument to the ActivationDesc constructor will be used  
  82.     // to uniquely identify this class; it's location is relative to the  
  83.     // URL-formatted String, location.
  84.     //
  85.     ActivationDesc desc = new ActivationDesc 
  86.         ("examples.activation.ActivatableImplementation", location, data);
  87.     
  88.     // Register with rmid
  89.     //
  90.     MyRemoteInterface mri = (MyRemoteInterface)Activatable.register(desc);
  91.     System.out.println("Got the stub for the ActivatableImplementation");
  92.         
  93.     // Bind the stub to a name in the registry running on 1099
  94.     // 
  95.     Naming.rebind("ActivatableImplementation", mri);
  96.     System.out.println("Exported ActivatableImplementation");
  97.  
  98.     System.exit(0);
  99.     }
  100.  
  101. }
  102.