src/java.rmi/share/classes/java/rmi/activation/ActivationID.java
author darcy
Fri, 20 Jul 2018 14:46:43 -0700
changeset 51181 01b8120f867a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8208060: Additional corrections of serial-related declarations Reviewed-by: rriggs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45983
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
     2
 * Copyright (c) 1997, 2017, 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.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.InvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.MarshalledObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.UnmarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.server.RemoteObjectInvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.server.RemoteRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.rmi.server.UID;
45983
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    43
import java.security.AccessControlContext;
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    44
import java.security.AccessController;
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    45
import java.security.Permissions;
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    46
import java.security.PrivilegedActionException;
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    47
import java.security.PrivilegedExceptionAction;
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    48
import java.security.ProtectionDomain;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Activation makes use of special identifiers to denote remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * objects that can be activated over time. An activation identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * (an instance of the class <code>ActivationID</code>) contains several
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * pieces of information needed for activating an object:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <li> a remote reference to the object's activator (a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * java.rmi.server.RemoteRef RemoteRef}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * instance), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <li> a unique identifier (a {@link java.rmi.server.UID UID}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * instance) for the object. </ul> <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * An activation identifier for an object can be obtained by registering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * an object with the activation system. Registration is accomplished
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * in a few ways: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <li>via the <code>Activatable.register</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <li>via the first <code>Activatable</code> constructor (that takes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * three arguments and both registers and exports the object, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <li>via the first <code>Activatable.exportObject</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * that takes the activation descriptor, object and port as arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * this method both registers and exports the object. </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @author      Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see         Activatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public class ActivationID implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * the object's activator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private transient Activator activator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * the object's unique id
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private transient UID uid = new UID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** indicate compatibility with the Java 2 SDK v1.2 version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final long serialVersionUID = -4608673054848209235L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
45983
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    90
    /** an AccessControlContext with no permissions */
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    91
    private static final AccessControlContext NOPERMS_ACC;
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    92
    static {
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    93
        Permissions perms = new Permissions();
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    94
        ProtectionDomain[] pd = { new ProtectionDomain(null, perms) };
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    95
        NOPERMS_ACC = new AccessControlContext(pd);
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    96
    }
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
    97
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * The constructor for <code>ActivationID</code> takes a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * argument, activator, that specifies a remote reference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * activator responsible for activating the object associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * this identifier. An instance of <code>ActivationID</code> is globally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * unique.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param activator reference to the activator responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * activating the object
19829
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   107
     * @throws UnsupportedOperationException if and only if activation is
eb9dea4a724c 8023447: change specification to allow RMI activation to be optional
smarks
parents: 5506
diff changeset
   108
     *         not supported by this implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public ActivationID(Activator activator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.activator = activator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Activate the object for this id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param force if true, forces the activator to contact the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * when activating the object (instead of returning a cached reference);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * if false, returning a cached value is acceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return the reference to the active remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @exception ActivationException if activation fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @exception UnknownObjectException if the object is unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @exception RemoteException if remote call fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public Remote activate(boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        throws ActivationException, UnknownObjectException, RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            MarshalledObject<? extends Remote> mobj =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                activator.activate(this, force);
45983
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   133
            return AccessController.doPrivileged(
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   134
                new PrivilegedExceptionAction<Remote>() {
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   135
                    public Remote run() throws IOException, ClassNotFoundException {
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   136
                        return mobj.get();
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   137
                    }
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   138
                }, NOPERMS_ACC);
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   139
        } catch (PrivilegedActionException pae) {
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   140
            Exception ex = pae.getException();
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   141
            if (ex instanceof RemoteException) {
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   142
                throw (RemoteException) ex;
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   143
            } else {
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   144
                throw new UnmarshalException("activation failed", ex);
4bcee8b28e89 8173697: Less Active Activations
smarks
parents: 37782
diff changeset
   145
            }
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Returns a hashcode for the activation id.  Two identifiers that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * refer to the same remote object will have the same hash code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see java.util.Hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return uid.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Compares two activation ids for content equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Returns true if both of the following conditions are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * 1) the unique identifiers equivalent (by content), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * 2) the activator specified in each identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *    refers to the same remote object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param   obj     the Object to compare with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return  true if these Objects are equal; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see             java.util.Hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (obj instanceof ActivationID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            ActivationID id = (ActivationID) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return (uid.equals(id.uid) && activator.equals(id.activator));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <code>writeObject</code> for custom serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * <p>This method writes this object's serialized form for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * this class as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <p>The <code>writeObject</code> method is invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <code>out</code> passing this object's unique identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * (a {@link java.rmi.server.UID UID} instance) as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <p>Next, the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * getRefClass} method is invoked on the activator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <code>RemoteRef</code> instance to obtain its external ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * type name.  Next, the <code>writeUTF</code> method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * invoked on <code>out</code> with the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <code>getRefClass</code>, and then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <code>writeExternal</code> method is invoked on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <code>RemoteRef</code> instance passing <code>out</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @serialData The serialized data for this class comprises a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <code>java.rmi.server.UID</code> (written with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <code>ObjectOutput.writeObject</code>) followed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * external ref type name of the activator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <code>RemoteRef</code> instance (a string written with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * <code>ObjectOutput.writeUTF</code>), followed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * external form of the <code>RemoteRef</code> instance as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * written by its <code>writeExternal</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <p>The external ref type name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <code>RemoteRef</Code> instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * determined using the definitions of external ref type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * names specified in the {@link java.rmi.server.RemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * RemoteObject} <code>writeObject</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <b>serialData</b> specification.  Similarly, the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * written by the <code>writeExternal</code> method and read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * by the <code>readExternal</code> method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <code>RemoteRef</code> implementation classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * corresponding to each of the defined external ref type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * names is specified in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * java.rmi.server.RemoteObject RemoteObject}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>writeObject</code> method <b>serialData</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private void writeObject(ObjectOutputStream out)
51181
01b8120f867a 8208060: Additional corrections of serial-related declarations
darcy
parents: 47216
diff changeset
   228
        throws IOException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        out.writeObject(uid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        RemoteRef ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (activator instanceof RemoteObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            ref = ((RemoteObject) activator).getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } else if (Proxy.isProxyClass(activator.getClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            InvocationHandler handler = Proxy.getInvocationHandler(activator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            if (!(handler instanceof RemoteObjectInvocationHandler)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                throw new InvalidObjectException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    "unexpected invocation handler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ref = ((RemoteObjectInvocationHandler) handler).getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            throw new InvalidObjectException("unexpected activator type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        out.writeUTF(ref.getRefClass(out));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        ref.writeExternal(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>readObject</code> for custom serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p>This method reads this object's serialized form for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * class as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <p>The <code>readObject</code> method is invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <code>in</code> to read this object's unique identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * (a {@link java.rmi.server.UID UID} instance).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <p>Next, the <code>readUTF</code> method is invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <code>in</code> to read the external ref type name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <code>RemoteRef</code> instance for this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * activator.  Next, the <code>RemoteRef</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * instance is created of an implementation-specific class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * corresponding to the external ref type name (returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <code>readUTF</code>), and the <code>readExternal</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * method is invoked on that <code>RemoteRef</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * to read the external form corresponding to the external
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * ref type name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <p>Note: If the external ref type name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <code>"UnicastRef"</code>, <code>"UnicastServerRef"</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <code>"UnicastRef2"</code>, <code>"UnicastServerRef2"</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * or <code>"ActivatableRef"</code>, a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * implementation-specific class must be found, and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <code>readExternal</code> method must read the serial data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * for that external ref type name as specified to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * in the <b>serialData</b> documentation for this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * If the external ref type name is any other string (of non-zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * length), a <code>ClassNotFoundException</code> will be thrown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * unless the implementation provides an implementation-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * class corresponding to that external ref type name, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * case the <code>RemoteRef</code> will be an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * that implementation-specific class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        uid = (UID)in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            Class<? extends RemoteRef> refClass =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                Class.forName(RemoteRef.packagePrefix + "." + in.readUTF())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                .asSubclass(RemoteRef.class);
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 36511
diff changeset
   295
            @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            RemoteRef ref = refClass.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            ref.readExternal(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            activator = (Activator)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   299
                Proxy.newProxyInstance(Activator.class.getClassLoader(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                       new Class<?>[] { Activator.class },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                       new RemoteObjectInvocationHandler(ref));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            throw (IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                new InvalidObjectException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    "Unable to create remote reference").initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            throw (IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                new InvalidObjectException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    "Unable to create remote reference").initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}