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 / Setup4.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  3.8 KB  |  100 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.io.File;
  31. import java.rmi.*;
  32. import java.rmi.activation.*;
  33. import java.util.Properties;
  34.  
  35. public class Setup4 {
  36.  
  37.     // This class registers information about the MyPersistentClass
  38.     // class with rmid and the rmiregistry
  39.     //
  40.     public static void main(String[] args) throws Exception {
  41.     
  42.     System.setSecurityManager(new RMISecurityManager());
  43.     
  44.     // After JDK1.2Beta4, ActivationGroups are no longer created
  45.     // implicitly as a side-effect of creating or registering the
  46.     // first Activatable object
  47.     //
  48.     // Because of the 1.2 security model, a security policy should 
  49.     // be specified for the ActivationGroup VM. The first argument
  50.     // to the Properties put method, inherited from Hashtable, is 
  51.     // the key and the second is the value 
  52.     // 
  53.     Properties props = new Properties(); 
  54.     props.put("java.security.policy", 
  55.        "/home/rmi_tutorial/activation/policy"); 
  56.     
  57.     ActivationGroupDesc.CommandEnvironment ace = null; 
  58.     ActivationGroupDesc exampleGroup = new ActivationGroupDesc(props, ace);
  59.     
  60.     // Once the ActivationGroupDesc has been created, register it 
  61.     // with the activation system to obtain its ID
  62.     //
  63.     ActivationGroupID agi = 
  64.        ActivationGroup.getSystem().registerGroup(exampleGroup);
  65.     
  66.     // Now explicitly create the group
  67.     //
  68.     ActivationGroup.createGroup(agi, exampleGroup, 0);
  69.  
  70.     // Don't forget the trailing slash at the end of the URL
  71.     // or your classes won't be found
  72.     //    
  73.     String location = "file:/home/rmi_tutorial/activation/";
  74.  
  75.     // Pass the file that we want to persist to as the Marshalled
  76.     // object
  77.     MarshalledObject data =  new MarshalledObject (new File(
  78.         "/home/rmi_tutorial/activation/persistentObjectStore.ser"));
  79.  
  80.     // The second argument to the ActivationDesc constructor will be used 
  81.     // to uniquely identify this class; it's location is relative to the  
  82.     // URL-formatted String, location.
  83.     //
  84.     ActivationDesc desc = new ActivationDesc 
  85.         (agi, "examples.activation.MyPersistentClass", location, data);
  86.     
  87.     YetAnotherRemoteInterface yari = 
  88.         (YetAnotherRemoteInterface)Activatable.register(desc);
  89.     System.out.println("Got the stub for MyPersistentClass");
  90.  
  91.     // Bind the stub to a name in the registry running on 1099
  92.     //
  93.     Naming.rebind("MyPersistentClass", yari);
  94.     System.out.println("Exported MyPersistentClass");
  95.  
  96.     System.exit(0);
  97.     }
  98.  
  99. }
  100.