home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / rmi / activation / ActivationDesc.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  9.9 KB  |  254 lines

  1. /*
  2.  * @(#)ActivationDesc.java    1.11 98/03/18
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.rmi.activation;
  16.  
  17. import java.lang.reflect.Method;
  18. import java.security.CodeSource;
  19. import java.rmi.MarshalledObject;
  20.  
  21. /**
  22.  * An activation descriptor contains the information necessary to
  23.  * activate an object: <ul>
  24.  * <li> the object's group identifier,
  25.  * <li> the object's class name,
  26.  * <li> the object's code source (the location of the class), and
  27.  * <li> a "marshalled" object that can contain object specific
  28.  * initialization data. </ul> <p>
  29.  *
  30.  * A descriptor registered with the activation system can be used to
  31.  * recreate/activate the object specified by the descriptor. The
  32.  * <code>MarshalledObject</code> in the object's descriptor is passed
  33.  * as the second argument to the remote object's constructor for
  34.  * object to use during reinitialization/activation.
  35.  *
  36.  * @author     Ann Wollrath
  37.  * @version    1.11, 03/18/98
  38.  * @since     JDK1.2
  39.  */
  40. public final class ActivationDesc implements java.io.Serializable
  41. {
  42.     /** the group's identifier */
  43.     private ActivationGroupID groupID;
  44.     /** the object's class name */
  45.     private String className;
  46.     /** the object's code source */
  47.     private CodeSource source;
  48.     /** the object's initialization data */
  49.     private MarshalledObject data;
  50.     /** indicates whether the object should be restarted */
  51.     private boolean restart;
  52.  
  53.     /** indicate compatibility with JDK 1.2 version of class */
  54.     private static final long serialVersionUID = 7455834104417690957L;
  55.  
  56.     /**
  57.      * Constructs an object descriptor for an object whose class name
  58.      * is <code>className</code>, that can be loaded from the
  59.      * CodeSource, <code>source</code>, and whose initialization
  60.      * information is <code>data</code>. If this form of the constructor
  61.      * is used, the <code>groupID</code> defaults to the current id for
  62.      * <code>ActivationGroup</code> for this VM. All objects with the
  63.      * same <code>ActivationGroupID</code> are activated in the same VM.
  64.      * Objects specified by a descriptor created by this constructor
  65.      * will not restart automatically when the RMI activation daemon
  66.      * starts, but will be activated on demand (via a method call to
  67.      * the activatable object).<p>
  68.      *
  69.      * Note: as a side-effect of creating an <code>ActivationDesc</code>,
  70.      * if an <code>ActivationGroup</code> for this VM is not currently
  71.      * active, a default one is created. The default activation group
  72.      * uses the <code>java.rmi.RMISecurityManager</code> as a security
  73.      * manager and upon reactivation will set the properties in the
  74.      * activated group's VM to be the current set of properties. If
  75.      * your application needs to use a different security manager,
  76.      * it must set the group for the VM before creating a default
  77.      * <code>ActivationDesc</code>. See the method
  78.      * <code>ActivationGroup.createGroup</code> for details on how
  79.      * to create an <code>ActivationGroup</code> for the VM.
  80.      *
  81.      * @param className the object's fully package qualified class name
  82.      * @param source the object's code source (from where the class is loaded)
  83.      * @param data the object's initialization (activation) data contained
  84.      * in marshalled form.
  85.      * @exception ActivationException if the current group is inactive,
  86.      * a default group could not be created, or a security manager is not
  87.      * set.
  88.      */
  89.     public ActivationDesc(String className,
  90.               CodeSource source, 
  91.               MarshalledObject data)
  92.     throws ActivationException
  93.     {
  94.     this(ActivationGroup.internalCurrentGroupID(),
  95.          className, source, data, false);
  96.     }
  97.     
  98.     /**
  99.      * Constructs an object descriptor for an object whose class name
  100.      * is <code>className</code>, that can be loaded from the
  101.      * CodeSource, <code>source</code>, and whose initialization
  102.      * information is <code>data</code>. If this form of the constructor
  103.      * is used, the <code>groupID</code> defaults to the current id for
  104.      * <code>ActivationGroup</code> for this VM. All objects with the
  105.      * same <code>ActivationGroupID</code> are activated in the same VM.<p>
  106.      *
  107.      * Note: as a side-effect of creating an <code>ActivationDesc</code>,
  108.      * if an <code>ActivationGroup</code> for this VM is not currently
  109.      * active, a default one is created. The default activation group
  110.      * uses the <code>java.rmi.RMISecurityManager</code> as a security
  111.      * manager and upon reactivation will set the properties in the
  112.      * activated group's VM to be the current set of properties. If
  113.      * your application needs to use a different security manager,
  114.      * it must set the group for the VM before creating a default
  115.      * <code>ActivationDesc</code>. See the method
  116.      * <code>ActivationGroup.createGroup</code> for details on how
  117.      * to create an <code>ActivationGroup</code> for the VM.
  118.      *
  119.      * @param className the object's fully package qualified class name
  120.      * @param source the object's code source (from where the class is loaded)
  121.      * @param data the object's initialization (activation) data contained
  122.      * in marshalled form.
  123.      * @param restart if true, the object is restarted when the activator
  124.      * is restarted; if false, the object is activated on demand.
  125.      * @exception ActivationException if the current group is inactive,
  126.      * a default group could not be created, or a security manager is not
  127.      * set.
  128.      */
  129.     public ActivationDesc(String className,
  130.               CodeSource source, 
  131.               MarshalledObject data,
  132.               boolean restart)
  133.     throws ActivationException
  134.     {
  135.     this(ActivationGroup.internalCurrentGroupID(),
  136.          className, source, data, restart);
  137.     }
  138.  
  139.     /**
  140.      * Constructs an object descriptor for an object whose class name
  141.      * is <code>className</code> that can be loaded from the
  142.      * CodeSource, <code>source</code>, and whose initialization
  143.      * information is <code>data</code>. All objects with the same
  144.      * <code>groupID</code> are activated in the same Java VM.
  145.      *
  146.      * @param groupID the group's identifier (obtained from registering
  147.      * <code>ActivationSystem.registerGroup</code> method). The group
  148.      * indicates the VM in which the object should be activated.
  149.      * @param className the object's fully package-qualified class name
  150.      * @param source the object's  code source (from where the class is loaded)
  151.      * @param data  the object's initialization (activation) data contained
  152.      * in marshalled form.
  153.      * @exception IllegalArgumentException if <code>groupID</code> is null
  154.      */
  155.    public ActivationDesc(ActivationGroupID groupID,
  156.              String className, 
  157.              CodeSource source, 
  158.              MarshalledObject data)
  159.     {
  160.     this(groupID, className, source, data, false);
  161.     }
  162.  
  163.     /**
  164.      * Constructs an object descriptor for an object whose class name
  165.      * is <code>className</code> that can be loaded from the
  166.      * CodeSource, <code>source</code>, and whose initialization
  167.      * information is <code>data</code>. All objects with the same
  168.      * <code>groupID</code> are activated in the same Java VM.
  169.      *
  170.      * @param groupID the group's identifier (obtained from registering
  171.      * <code>ActivationSystem.registerGroup</code> method). The group
  172.      * indicates the VM in which the object should be activated.
  173.      * @param className the object's fully package-qualified class name
  174.      * @param source the object's  code source (from where the class is loaded)
  175.      * @param data  the object's initialization (activation) data contained
  176.      * in marshalled form.
  177.      * @param restart if true, the object is restarted when the activator
  178.      * is restarted; if false, the object is activated on demand.
  179.      * @exception IllegalArgumentException if <code>groupID</code> is null
  180.      */
  181.    public ActivationDesc(ActivationGroupID groupID,
  182.              String className, 
  183.              CodeSource source, 
  184.              MarshalledObject data,
  185.              boolean restart)
  186.     {
  187.     if (groupID == null)
  188.         throw new IllegalArgumentException("groupID can't be null");
  189.     this.groupID = groupID;
  190.     this.className = className;
  191.     this.source = source;
  192.     this.data = data;
  193.     this.restart = restart;
  194.     }
  195.     
  196.     /**
  197.      * Returns the group identifier for the object specified by this
  198.      * descriptor. A group provides a way to aggregate objects into a
  199.      * single Java virtual machine. RMI creates/activates objects with
  200.      * the same <code>groupID</code> in the same virtual machine.
  201.      *
  202.      * @return the group identifier
  203.      */
  204.     public ActivationGroupID getGroupID() 
  205.     {
  206.     return groupID;
  207.     }
  208.     
  209.     /**
  210.      * Returns the class name for the object specified by this
  211.      * descriptor.
  212.      * @return the class name
  213.      */
  214.     public String getClassName() 
  215.     {
  216.     return className;
  217.     }
  218.     
  219.     /**
  220.      * Returns the code source for the object specified by
  221.      * this descriptor.
  222.      * @return the code source
  223.      */
  224.     public CodeSource getCodeSource() 
  225.     {
  226.     return source;
  227.     }
  228.     
  229.     /**
  230.      * Returns a "marshalled object" containing intialization/activation
  231.      * data for the object specified by this descriptor.
  232.      * @return the object specific "initialization" data
  233.      */
  234.     public MarshalledObject getData() 
  235.     {
  236.     return data;
  237.     }
  238.  
  239.     /**
  240.      * Returns the "restart" mode of the object associated with
  241.      * this activation descriptor.
  242.      *
  243.      * @return true if the activatable object associated with this
  244.      * activation descriptor should be restarted via the activation
  245.      * daemon when the daemon comes up; otherwise it returns false
  246.      * (meaning that the object is only activated on demand via a
  247.      * method call). 
  248.      */
  249.     public boolean getRestartMode()
  250.     {
  251.     return restart;
  252.     }
  253. }
  254.