src/java.rmi/share/classes/java/rmi/activation/ActivationGroup.java
author rriggs
Wed, 02 Oct 2019 13:57:03 -0400
changeset 58446 5c83830390ba
parent 47216 71c04702a3d5
child 58609 fbfc72ec8e6b
permissions -rw-r--r--
8231663: Incorrect GPL header in some RMI/SQL package-info.java files Reviewed-by: bpb, iris, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.rmi.activation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.rmi.MarshalledObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.rmi.Naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.activation.UnknownGroupException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.activation.UnknownObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.server.RMIClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.AccessController;
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21338
diff changeset
    39
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * An <code>ActivationGroup</code> is responsible for creating new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * instances of "activatable" objects in its group, informing its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>ActivationMonitor</code> when either: its object's become
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * active or inactive, or the group as a whole becomes inactive. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * An <code>ActivationGroup</code> is <i>initially</i> created in one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * of several ways: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <li>as a side-effect of creating an <code>ActivationDesc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     without an explicit <code>ActivationGroupID</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     first activatable object in the group, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <li>via the <code>ActivationGroup.createGroup</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <li>as a side-effect of activating the first object in a group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     whose <code>ActivationGroupDesc</code> was only registered.</ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Only the activator can <i>recreate</i> an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>ActivationGroup</code>.  The activator spawns, as needed, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * separate VM (as a child process, for example) for each registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * activation group and directs activation requests to the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * group. It is implementation specific how VMs are spawned. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * activation group is created via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <code>ActivationGroup.createGroup</code> static method. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>createGroup</code> method has two requirements on the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * to be created: 1) the group must be a concrete subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>ActivationGroup</code>, and 2) the group must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * constructor that takes two arguments:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <li> the group's <code>ActivationGroupID</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <li> the group's initialization data (in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *      <code>java.rmi.MarshalledObject</code>)</ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * When created, the default implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <code>ActivationGroup</code> will override the system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * with the properties requested when its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <code>ActivationGroupDesc</code> was created, and will set a
21338
ed59bead7654 8026427: deprecate obsolete APIs from java.rmi
smarks
parents: 21334
diff changeset
    77
 * {@link SecurityManager} as the default system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * security manager.  If your application requires specific properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * to be set when objects are activated in the group, the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * should create a special <code>Properties</code> object containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * these properties, then create an <code>ActivationGroupDesc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * with the <code>Properties</code> object, and use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <code>ActivationGroup.createGroup</code> before creating any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <code>ActivationDesc</code>s (before the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <code>ActivationGroupDesc</code> is created).  If your application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * requires the use of a security manager other than
21338
ed59bead7654 8026427: deprecate obsolete APIs from java.rmi
smarks
parents: 21334
diff changeset
    87
 * {@link SecurityManager}, in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * ActivativationGroupDescriptor properties list you can set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <code>java.security.manager</code> property to the name of the security
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * manager you would like to install.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @author      Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @see         ActivationInstantiator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @see         ActivationGroupDesc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @see         ActivationGroupID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
public abstract class ActivationGroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        implements ActivationInstantiator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @serial the group's identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private ActivationGroupID groupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @serial the group's monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private ActivationMonitor monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @serial the group's incarnation number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private long incarnation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /** the current activation group for this VM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static ActivationGroup currGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /** the current group's identifier */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static ActivationGroupID currGroupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /** the current group's activation system */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static ActivationSystem currSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /** used to control a group being created only once */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static boolean canCreate = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /** indicate compatibility with the Java 2 SDK v1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static final long serialVersionUID = -7696947875314805420L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Constructs an activation group with the given activation group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * identifier.  The group is exported as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <code>java.rmi.server.UnicastRemoteObject</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param   groupID the group's identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @throws  RemoteException if this group could not be exported
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   136
     * @throws  UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   137
     *          not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected ActivationGroup(ActivationGroupID groupID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // call super constructor to export the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this.groupID = groupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * The group's <code>inactiveObject</code> method is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * indirectly via a call to the <code>Activatable.inactive</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * method. A remote object implementation must call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <code>Activatable</code>'s <code>inactive</code> method when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * that object deactivates (the object deems that it is no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * active). If the object does not call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * <code>Activatable.inactive</code> when it deactivates, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * object will never be garbage collected since the group keeps
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 19829
diff changeset
   157
     * strong references to the objects it creates.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <p>The group's <code>inactiveObject</code> method unexports the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * remote object from the RMI runtime so that the object can no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * longer receive incoming RMI calls. An object will only be unexported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * if the object has no pending or executing calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * The subclass of <code>ActivationGroup</code> must override this
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 19829
diff changeset
   164
     * method and unexport the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p>After removing the object from the RMI runtime, the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * must inform its <code>ActivationMonitor</code> (via the monitor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <code>inactiveObject</code> method) that the remote object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * not currently active so that the remote object will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * re-activated by the activator upon a subsequent activation
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 19829
diff changeset
   171
     * request.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <p>This method simply informs the group's monitor that the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * is inactive.  It is up to the concrete subclass of ActivationGroup
23720
7d5147c21927 8039172: Tidy warnings cleanup for java.net, java.math, java.time, java.rmi
yan
parents: 23333
diff changeset
   175
     * to fulfill the additional requirement of unexporting the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param id the object's activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return true if the object was successfully deactivated; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *         returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @exception UnknownObjectException if object is unknown (may already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * be inactive)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception RemoteException if call informing monitor fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @exception ActivationException if group is inactive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public boolean inactiveObject(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        getMonitor().inactiveObject(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * The group's <code>activeObject</code> method is called when an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * object is exported (either by <code>Activatable</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * construction or an explicit call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <code>Activatable.exportObject</code>. The group must inform its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <code>ActivationMonitor</code> that the object is active (via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * the monitor's <code>activeObject</code> method) if the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * hasn't already done so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param id the object's identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param obj the remote object implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @exception UnknownObjectException if object is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @exception RemoteException if call informing monitor fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @exception ActivationException if group is inactive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public abstract void activeObject(ActivationID id, Remote obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        throws ActivationException, UnknownObjectException, RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Create and set the activation group for the current VM.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * activation group can only be set if it is not currently set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * An activation group is set using the <code>createGroup</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * method when the <code>Activator</code> initiates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * re-creation of an activation group in order to carry out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * incoming <code>activate</code> requests. A group must first be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * registered with the <code>ActivationSystem</code> before it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * be created via this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <p>The group class specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <code>ActivationGroupDesc</code> must be a concrete subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>ActivationGroup</code> and have a public constructor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * takes two arguments: the <code>ActivationGroupID</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * group and the <code>MarshalledObject</code> containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * group's initialization data (obtained from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <code>ActivationGroupDesc</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <p>If the group class name specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <code>ActivationGroupDesc</code> is <code>null</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * this method will behave as if the group descriptor contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * the name of the default activation group implementation class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <p>Note that if your application creates its own custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * activation group, a security manager must be set for that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * group.  Otherwise objects cannot be activated in the group.
21338
ed59bead7654 8026427: deprecate obsolete APIs from java.rmi
smarks
parents: 21334
diff changeset
   238
     * {@link SecurityManager} is set by default.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <p>If a security manager is already set in the group VM, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * method first calls the security manager's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <code>checkSetFactory</code> method.  This could result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <code>SecurityException</code>. If your application needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * set a different security manager, you must ensure that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * policy file specified by the group's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <code>ActivationGroupDesc</code> grants the group the necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * permissions to set a new security manager.  (Note: This will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * necessary if your group downloads and sets a security manager).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <p>After the group is created, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>ActivationSystem</code> is informed that the group is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * active by calling the <code>activeGroup</code> method which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * returns the <code>ActivationMonitor</code> for the group. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * application need not call <code>activeGroup</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * independently since it is taken care of by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p>Once a group is created, subsequent calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <code>currentGroupID</code> method will return the identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * for this group until the group becomes inactive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param id the activation group's identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param desc the activation group's descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param incarnation the group's incarnation number (zero on group's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * initial creation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return the activation group for the VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @exception ActivationException if group already exists or if error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * occurs during group creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @exception SecurityException if permission to create group is denied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * (Note: The default implementation of the security manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <code>checkSetFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * method requires the RuntimePermission "setFactory")
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   272
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   273
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @see SecurityManager#checkSetFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public static synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        ActivationGroup createGroup(ActivationGroupID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                    final ActivationGroupDesc desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                    long incarnation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        throws ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (security != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            security.checkSetFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (currGroup != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new ActivationException("group already exists");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (canCreate == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            throw new ActivationException("group deactivated and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                          "cannot be recreated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            // load group's class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            String groupClassName = desc.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            Class<? extends ActivationGroup> cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            Class<? extends ActivationGroup> defaultGroupClass =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                sun.rmi.server.ActivationGroupImpl.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (groupClassName == null ||       // see 4252236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                groupClassName.equals(defaultGroupClass.getName()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                cl = defaultGroupClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                Class<?> cl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    cl0 = RMIClassLoader.loadClass(desc.getLocation(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                                   groupClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        "Could not load group implementation class", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if (ActivationGroup.class.isAssignableFrom(cl0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    cl = cl0.asSubclass(ActivationGroup.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    throw new ActivationException("group not correct class: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                                  cl0.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            // create group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            Constructor<? extends ActivationGroup> constructor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                cl.getConstructor(ActivationGroupID.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                  MarshalledObject.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            ActivationGroup newGroup =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                constructor.newInstance(id, desc.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            currSystem = id.getSystem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            newGroup.incarnation = incarnation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            newGroup.monitor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                currSystem.activeGroup(id, newGroup, incarnation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            currGroup = newGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            currGroupID = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            canCreate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                e.getTargetException().printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                throw new ActivationException("exception in group constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                              e.getTargetException());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } catch (ActivationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            throw new ActivationException("exception creating group", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return currGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Returns the current activation group's identifier.  Returns null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * if no group is currently active for this VM.
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   352
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   353
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return the activation group's identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public static synchronized ActivationGroupID currentGroupID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return currGroupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Returns the activation group identifier for the VM.  If an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * activation group does not exist for this VM, a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * activation group is created. A group can be created only once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * so if a group has already become active and deactivated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @return the activation group identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @exception ActivationException if error occurs during group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * creation, if security manager is not set, or if the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * has already been created and deactivated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    static synchronized ActivationGroupID internalCurrentGroupID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        throws ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (currGroupID == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            throw new ActivationException("nonexistent group");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return currGroupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Set the activation system for the VM.  The activation system can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * only be set it if no group is currently active. If the activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * system is not set via this call, then the <code>getSystem</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * method attempts to obtain a reference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * <code>ActivationSystem</code> by looking up the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * "java.rmi.activation.ActivationSystem" in the Activator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * registry. By default, the port number used to look up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * activation system is defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be overridden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * by setting the property <code>java.rmi.activation.port</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * <p>If there is a security manager, this method first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * calls the security manager's <code>checkSetFactory</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * This could result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @param system remote reference to the <code>ActivationSystem</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @exception ActivationException if activation system is already set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @exception SecurityException if permission to set the activation system is denied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * (Note: The default implementation of the security manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <code>checkSetFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * method requires the RuntimePermission "setFactory")
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   403
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   404
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see #getSystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @see SecurityManager#checkSetFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public static synchronized void setSystem(ActivationSystem system)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        throws ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (security != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            security.checkSetFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (currSystem != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            throw new ActivationException("activation system already set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        currSystem = system;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Returns the activation system for the VM. The activation system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * may be set by the <code>setSystem</code> method. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * activation system is not set via the <code>setSystem</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * method, then the <code>getSystem</code> method attempts to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * obtain a reference to the <code>ActivationSystem</code> by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * looking up the name "java.rmi.activation.ActivationSystem" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * the Activator's registry. By default, the port number used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * look up the activation system is defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * overridden by setting the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <code>java.rmi.activation.port</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @return the activation system for the VM/group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @exception ActivationException if activation system cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *  obtained or is not bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * (means that it is not running)
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   439
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   440
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see #setSystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public static synchronized ActivationSystem getSystem()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        throws ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (currSystem == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            try {
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21338
diff changeset
   449
                int port = AccessController.doPrivileged((PrivilegedAction<Integer>) () ->
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21338
diff changeset
   450
                    Integer.getInteger("java.rmi.activation.port", ActivationSystem.SYSTEM_PORT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                currSystem = (ActivationSystem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    Naming.lookup("//:" + port +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                  "/java.rmi.activation.ActivationSystem");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                throw new ActivationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    "unable to obtain ActivationSystem", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return currSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * This protected method is necessary for subclasses to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * make the <code>activeObject</code> callback to the group's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * monitor. The call is simply forwarded to the group's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * <code>ActivationMonitor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @param id the object's identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @param mobj a marshalled object containing the remote object's stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @exception UnknownObjectException if object is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @exception RemoteException if call informing monitor fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @exception ActivationException if an activation error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    protected void activeObject(ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                MarshalledObject<? extends Remote> mobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        getMonitor().activeObject(id, mobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * This protected method is necessary for subclasses to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * make the <code>inactiveGroup</code> callback to the group's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * monitor. The call is simply forwarded to the group's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <code>ActivationMonitor</code>. Also, the current group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * for the VM is set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @exception UnknownGroupException if group is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @exception RemoteException if call informing monitor fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    protected void inactiveGroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        throws UnknownGroupException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            getMonitor().inactiveGroup(groupID, incarnation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            destroyGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Returns the monitor for the activation group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    private ActivationMonitor getMonitor() throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        synchronized (ActivationGroup.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            if (monitor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                return monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        throw new RemoteException("monitor not received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Destroys the current group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    private static synchronized void destroyGroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        currGroup = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        currGroupID = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        // NOTE: don't set currSystem to null since it may be needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * Returns the current group for the VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @exception ActivationException if current group is null (not active)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    static synchronized ActivationGroup currentGroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        throws ActivationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (currGroup == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            throw new ActivationException("group is not active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return currGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
}