src/java.rmi/share/classes/java/rmi/activation/Activatable.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.rmi/share/classes/java/rmi/activation/Activatable.java@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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: 4512
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: 4512
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: 4512
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4512
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4512
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.rmi.MarshalledObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.rmi.NoSuchObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.rmi.activation.UnknownGroupException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.rmi.activation.UnknownObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.server.RMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.server.RMIServerSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.server.RemoteServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.rmi.server.ActivatableServerRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The <code>Activatable</code> class provides support for remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * objects that require persistent access over time and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * can be activated by the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>For the constructors and static <code>exportObject</code> methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the stub for a remote object being exported is obtained as described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * {@link java.rmi.server.UnicastRemoteObject}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>An attempt to serialize explicitly an instance of this class will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author      Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @serial      exclude
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public abstract class Activatable extends RemoteServer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private ActivationID id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /** indicate compatibility with the Java 2 SDK v1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final long serialVersionUID = -3120617863591563455L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Constructs an activatable remote object by registering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * an activation descriptor (with the specified location, data, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * restart mode) for this object, and exporting the object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * <p><strong>Note:</strong> Using the <code>Activatable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * constructors that both register and export an activatable remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * object is strongly discouraged because the actions of registering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * and exporting the remote object are <i>not</i> guaranteed to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * atomic.  Instead, an application should register an activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * descriptor and export a remote object separately, so that exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * can be handled properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p>This method invokes the {@link
4512
b3ed7ecf8f55 6909563: Javadoc build warnings in rmi, security, management
darcy
parents: 2
diff changeset
    76
     * #exportObject(Remote,String,MarshalledObject,boolean,int)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * exportObject} method with this object, and the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * data, restart mode, and port.  Subsequent calls to {@link #getID}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * will return the activation identifier returned from the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <code>exportObject</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param location the location for classes for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param data the object's initialization data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param port the port on which the object is exported (an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * port is used if port=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param restart if true, the object is restarted (reactivated) when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * either the activator is restarted or the object's activation group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * is restarted after an unexpected crash; if false, the object is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * activated on demand.  Specifying <code>restart</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * <code>true</code> does not force an initial immediate activation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * a newly registered object;  initial activation is lazy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @exception ActivationException if object registration fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @exception RemoteException if either of the following fails:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * a) registering the object with the activation system or b) exporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * the object to the RMI runtime.
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
    96
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
    97
     * not supported by this implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected Activatable(String location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                          MarshalledObject<?> data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                          boolean restart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                          int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        throws ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        id = exportObject(this, location, data, restart, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Constructs an activatable remote object by registering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * an activation descriptor (with the specified location, data, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * restart mode) for this object, and exporting the object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * specified port, and specified client and server socket factories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <p><strong>Note:</strong> Using the <code>Activatable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * constructors that both register and export an activatable remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * object is strongly discouraged because the actions of registering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * and exporting the remote object are <i>not</i> guaranteed to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * atomic.  Instead, an application should register an activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * descriptor and export a remote object separately, so that exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * can be handled properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p>This method invokes the {@link
4512
b3ed7ecf8f55 6909563: Javadoc build warnings in rmi, security, management
darcy
parents: 2
diff changeset
   125
     * #exportObject(Remote,String,MarshalledObject,boolean,int,RMIClientSocketFactory,RMIServerSocketFactory)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * exportObject} method with this object, and the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * data, restart mode, port, and client and server socket factories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Subsequent calls to {@link #getID} will return the activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * identifier returned from the call to <code>exportObject</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param location the location for classes for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param data the object's initialization data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param restart if true, the object is restarted (reactivated) when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * either the activator is restarted or the object's activation group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * is restarted after an unexpected crash; if false, the object is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * activated on demand.  Specifying <code>restart</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <code>true</code> does not force an initial immediate activation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * a newly registered object;  initial activation is lazy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param port the port on which the object is exported (an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * port is used if port=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception ActivationException if object registration fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @exception RemoteException if either of the following fails:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * a) registering the object with the activation system or b) exporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * the object to the RMI runtime.
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   148
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   149
     * not supported by this implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    protected Activatable(String location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                          MarshalledObject<?> data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                          boolean restart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                          int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                          RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                          RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        throws ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        id = exportObject(this, location, data, restart, port, csf, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Constructor used to activate/export the object on a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * port. An "activatable" remote object must have a constructor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * takes two arguments: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <li>the object's activation identifier (<code>ActivationID</code>), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <li>the object's initialization data (a <code>MarshalledObject</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * </ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * A concrete subclass of this class must call this constructor when it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <i>activated</i> via the two parameter constructor described above. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * a side-effect of construction, the remote object is "exported"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * to the RMI runtime (on the specified <code>port</code>) and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * available to accept incoming calls from clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param id activation identifier for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param port the port number on which the object is exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @exception RemoteException if exporting the object to the RMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * runtime fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   182
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   183
     * not supported by this implementation
2
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
    protected Activatable(ActivationID id, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        exportObject(this, id, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Constructor used to activate/export the object on a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * port. An "activatable" remote object must have a constructor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * takes two arguments: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <li>the object's activation identifier (<code>ActivationID</code>), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <li>the object's initialization data (a <code>MarshalledObject</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * </ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * A concrete subclass of this class must call this constructor when it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <i>activated</i> via the two parameter constructor described above. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * a side-effect of construction, the remote object is "exported"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * to the RMI runtime (on the specified <code>port</code>) and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * available to accept incoming calls from clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param id activation identifier for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param port the port number on which the object is exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @exception RemoteException if exporting the object to the RMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * runtime fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   215
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   216
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected Activatable(ActivationID id, int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                          RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                          RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        exportObject(this, id, port, csf, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Returns the object's activation identifier.  The method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * protected so that only subclasses can obtain an object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return the object's activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    protected ActivationID getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Register an object descriptor for an activatable remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * object so that is can be activated on demand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param desc  the object's descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @return the stub for the activatable remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @exception UnknownGroupException if group id in <code>desc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * is not registered with the activation system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @exception ActivationException if activation system is not running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @exception RemoteException if remote call fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   250
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   251
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public static Remote register(ActivationDesc desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        throws UnknownGroupException, ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        // register object with activator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        ActivationID id =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            ActivationGroup.getSystem().registerObject(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return sun.rmi.server.ActivatableRef.getStub(desc, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Informs the system that the object with the corresponding activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * <code>id</code> is currently inactive. If the object is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * active, the object is "unexported" from the RMI runtime (only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * there are no pending or in-progress calls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * so the that it can no longer receive incoming calls. This call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * informs this VM's ActivationGroup that the object is inactive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * that, in turn, informs its ActivationMonitor. If this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * completes successfully, a subsequent activate request to the activator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * will cause the object to reactivate. The operation may still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * succeed if the object is considered active but has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * unexported itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param id the object's activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return true if the operation succeeds (the operation will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * succeed if the object in currently known to be active and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * either already unexported or is currently exported and has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * pending/executing calls); false is returned if the object has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * pending/executing calls in which case it cannot be deactivated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @exception UnknownObjectException if object is not known (it may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * already be inactive)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @exception ActivationException if group is not active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @exception RemoteException if call informing monitor fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   286
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   287
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public static boolean inactive(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        throws UnknownObjectException, ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return ActivationGroup.currentGroup().inactiveObject(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Revokes previous registration for the activation descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * associated with <code>id</code>. An object can no longer be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * activated via that <code>id</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param id the object's activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @exception UnknownObjectException if object (<code>id</code>) is unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @exception ActivationException if activation system is not running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @exception RemoteException if remote call to activation system fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   305
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   306
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public static void unregister(ActivationID id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        throws UnknownObjectException, ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        ActivationGroup.getSystem().unregisterObject(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Registers an activation descriptor (with the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * data, and restart mode) for the specified object, and exports that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * object with the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <p><strong>Note:</strong> Using this method (as well as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <code>Activatable</code> constructors that both register and export
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * an activatable remote object) is strongly discouraged because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * actions of registering and exporting the remote object are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <i>not</i> guaranteed to be atomic.  Instead, an application should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * register an activation descriptor and export a remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * separately, so that exceptions can be handled properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <p>This method invokes the {@link
4512
b3ed7ecf8f55 6909563: Javadoc build warnings in rmi, security, management
darcy
parents: 2
diff changeset
   329
     * #exportObject(Remote,String,MarshalledObject,boolean,int,RMIClientSocketFactory,RMIServerSocketFactory)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * exportObject} method with the specified object, location, data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * restart mode, and port, and <code>null</code> for both client and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * server socket factories, and then returns the resulting activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @param obj the object being exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param location the object's code location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @param data the object's bootstrapping data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @param restart if true, the object is restarted (reactivated) when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * either the activator is restarted or the object's activation group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * is restarted after an unexpected crash; if false, the object is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * activated on demand.  Specifying <code>restart</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <code>true</code> does not force an initial immediate activation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * a newly registered object;  initial activation is lazy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @param port the port on which the object is exported (an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * port is used if port=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @return the activation identifier obtained from registering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * descriptor, <code>desc</code>, with the activation system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * the wrong group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @exception ActivationException if activation group is not active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @exception RemoteException if object registration or export fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   351
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   352
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public static ActivationID exportObject(Remote obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                            String location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                            MarshalledObject<?> data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                            boolean restart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                            int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        throws ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return exportObject(obj, location, data, restart, port, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Registers an activation descriptor (with the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * data, and restart mode) for the specified object, and exports that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * object with the specified port, and the specified client and server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * socket factories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * <p><strong>Note:</strong> Using this method (as well as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <code>Activatable</code> constructors that both register and export
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * an activatable remote object) is strongly discouraged because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * actions of registering and exporting the remote object are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * <i>not</i> guaranteed to be atomic.  Instead, an application should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * register an activation descriptor and export a remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * separately, so that exceptions can be handled properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * <p>This method first registers an activation descriptor for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * specified object as follows. It obtains the activation system by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * invoking the method {@link ActivationGroup#getSystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * ActivationGroup.getSystem}.  This method then obtains an {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * ActivationID} for the object by invoking the activation system's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * {@link ActivationSystem#registerObject registerObject} method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * an {@link ActivationDesc} constructed with the specified object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * class name, and the specified location, data, and restart mode.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * an exception occurs obtaining the activation system or registering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * the activation descriptor, that exception is thrown to the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * <p>Next, this method exports the object by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * #exportObject(Remote,ActivationID,int,RMIClientSocketFactory,RMIServerSocketFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * exportObject} method with the specified remote object, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * activation identifier obtained from registration, the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * port, and the specified client and server socket factories.  If an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * exception occurs exporting the object, this method attempts to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * unregister the activation identifier (obtained from registration) by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * invoking the activation system's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * ActivationSystem#unregisterObject unregisterObject} method with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * activation identifier.  If an exception occurs unregistering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * identifier, that exception is ignored, and the original exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * that occurred exporting the object is thrown to the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <p>Finally, this method invokes the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * ActivationGroup#activeObject activeObject} method on the activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * group in this VM with the activation identifier and the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * remote object, and returns the activation identifier to the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @param obj the object being exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param location the object's code location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @param data the object's bootstrapping data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param restart if true, the object is restarted (reactivated) when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * either the activator is restarted or the object's activation group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * is restarted after an unexpected crash; if false, the object is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * activated on demand.  Specifying <code>restart</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * <code>true</code> does not force an initial immediate activation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * a newly registered object;  initial activation is lazy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @param port the port on which the object is exported (an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * port is used if port=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @return the activation identifier obtained from registering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * descriptor with the activation system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @exception ActivationException if activation group is not active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @exception RemoteException if object registration or export fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   426
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   427
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public static ActivationID exportObject(Remote obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                            String location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                            MarshalledObject<?> data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                            boolean restart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                            int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                            RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                            RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        throws ActivationException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        ActivationDesc desc = new ActivationDesc(obj.getClass().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                                 location, data, restart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
         * Register descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        ActivationSystem system =  ActivationGroup.getSystem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        ActivationID id = system.registerObject(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         * Export object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            exportObject(obj, id, port, csf, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
             * Attempt to unregister activation descriptor because export
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
             * failed and register/export should be atomic (see 4323621).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                system.unregisterObject(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
             * Report original exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
         * This call can't fail (it is a local call, and the only possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         * exception, thrown if the group is inactive, will not be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
         * because the group is not inactive).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        ActivationGroup.currentGroup().activeObject(id, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Export the activatable remote object to the RMI runtime to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * the object available to receive incoming calls. The object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * exported on an anonymous port, if <code>port</code> is zero. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * During activation, this <code>exportObject</code> method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * be invoked explicitly by an "activatable" object, that does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * extend the <code>Activatable</code> class. There is no need for objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * that do extend the <code>Activatable</code> class to invoke this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * method directly because the object is exported during construction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @return the stub for the activatable remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @param obj the remote object implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param id the object's  activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @param port the port on which the object is exported (an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * port is used if port=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @exception RemoteException if object export fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   494
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   495
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public static Remote exportObject(Remote obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                      ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                      int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return exportObject(obj, new ActivatableServerRef(id, port));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Export the activatable remote object to the RMI runtime to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * the object available to receive incoming calls. The object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * exported on an anonymous port, if <code>port</code> is zero. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * During activation, this <code>exportObject</code> method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * be invoked explicitly by an "activatable" object, that does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * extend the <code>Activatable</code> class. There is no need for objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * that do extend the <code>Activatable</code> class to invoke this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * method directly because the object is exported during construction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @return the stub for the activatable remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @param obj the remote object implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @param id the object's  activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @param port the port on which the object is exported (an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * port is used if port=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @exception RemoteException if object export fails
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   526
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   527
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public static Remote exportObject(Remote obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                      ActivationID id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                      int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                                      RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                      RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        return exportObject(obj, new ActivatableServerRef(id, port, csf, ssf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * Remove the remote object, obj, from the RMI runtime. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * successful, the object can no longer accept incoming RMI calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * If the force parameter is true, the object is forcibly unexported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * even if there are pending calls to the remote object or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * remote object still has calls in progress.  If the force
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * parameter is false, the object is only unexported if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * no pending or in progress calls to the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @param obj the remote object to be unexported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @param force if true, unexports the object even if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * pending or in-progress calls; if false, only unexports the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * if there are no pending or in-progress calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @return true if operation is successful, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @exception NoSuchObjectException if the remote object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * currently exported
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   556
     * @exception UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   557
     * not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public static boolean unexportObject(Remote obj, boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        throws NoSuchObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return sun.rmi.transport.ObjectTable.unexportObject(obj, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Exports the specified object using the specified server ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    private static Remote exportObject(Remote obj, ActivatableServerRef sref)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // if obj extends Activatable, set its ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (obj instanceof Activatable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            ((Activatable) obj).ref = sref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return sref.exportObject(obj, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
}