jdk/src/share/classes/java/rmi/server/UnicastRemoteObject.java
author smarks
Mon, 05 Aug 2013 19:12:33 -0700
changeset 19201 80230405e311
parent 5506 202f599c92aa
child 21334 c60dfce46a77
permissions -rw-r--r--
8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address Reviewed-by: rgallard, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.rmi.server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.rmi.server.UnicastServerRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.rmi.server.UnicastServerRef2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Used for exporting a remote object with JRMP and obtaining a stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * that communicates to the remote object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>For the constructors and static <code>exportObject</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * below, the stub for a remote object being exported is obtained as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <li>If the remote object is exported using the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * #exportObject(Remote) UnicastRemoteObject.exportObject(Remote)} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * a stub class (typically pregenerated from the remote object's class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * using the <code>rmic</code> tool) is loaded and an instance of that stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * class is constructed as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <li>A "root class" is determined as follows:  if the remote object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * class directly implements an interface that extends {@link Remote}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * the remote object's class is the root class; otherwise, the root class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the most derived superclass of the remote object's class that directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * implements an interface that extends <code>Remote</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <li>The name of the stub class to load is determined by concatenating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the binary name of the root class with the suffix <code>"_Stub"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <li>The stub class is loaded by name using the class loader of the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * class.  The stub class must extend {@link RemoteStub} and must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * public constructor that has one parameter, of type {@link RemoteRef}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <li>Finally, an instance of the stub class is constructed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * {@link RemoteRef}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <li>If the appropriate stub class could not be found, or the stub class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * could not be loaded, or a problem occurs creating the stub instance, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * {@link StubNotFoundException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <li>For all other means of exporting:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <li>If the remote object's stub class (as defined above) could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * loaded or the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <code>java.rmi.server.ignoreStubClasses</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <code>"true"</code> (case insensitive), a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * java.lang.reflect.Proxy} instance is constructed with the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <li>The proxy's class is defined by the class loader of the remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * object's class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <li>The proxy implements all the remote interfaces implemented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * remote object's class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <li>The proxy's invocation handler is a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * RemoteObjectInvocationHandler} instance constructed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * {@link RemoteRef}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <li>If the proxy could not be created, a {@link StubNotFoundException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <li>Otherwise, an instance of the remote object's stub class (as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * described above) is used as the stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   103
 * <p>If an object is exported with the
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   104
 * {@link #exportObject(Remote) exportObject(Remote)}
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   105
 * or
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   106
 * {@link #exportObject(Remote, int) exportObject(Remote, port)}
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   107
 * methods, or if a subclass constructor invokes one of the
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   108
 * {@link #UnicastRemoteObject()}
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   109
 * or
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   110
 * {@link #UnicastRemoteObject(int) UnicastRemoteObject(port)}
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   111
 * constructors, the object is exported with a server socket created using the
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   112
 * {@link RMISocketFactory}
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   113
 * class.
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   114
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   115
 * @implNote
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   116
 * <p>By default, server sockets created by the {@link RMISocketFactory} class
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   117
 * listen on all network interfaces. See the
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   118
 * {@link RMISocketFactory} class and the section
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   119
 * <a href="{@docRoot}/../platform/rmi/spec/rmi-server29.html">RMI Socket Factories</a>
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   120
 * in the
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   121
 * <a href="{@docRoot}/../platform/rmi/spec/rmiTOC.html">Java RMI Specification</a>.
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   122
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @author  Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @author  Peter Jones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
public class UnicastRemoteObject extends RemoteServer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @serial port number on which to export object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private int port = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @serial client-side socket factory (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private RMIClientSocketFactory csf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @serial server-side socket factory (if any) to use when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * exporting object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private RMIServerSocketFactory ssf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /* indicate compatibility with JDK 1.1.x version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private static final long serialVersionUID = 4974527148936298033L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Creates and exports a new UnicastRemoteObject object using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * anonymous port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @throws RemoteException if failed to export object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected UnicastRemoteObject() throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Creates and exports a new UnicastRemoteObject object using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * particular supplied port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param port the port number on which the remote object receives calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * (if <code>port</code> is zero, an anonymous port is chosen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @throws RemoteException if failed to export object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected UnicastRemoteObject(int port) throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        exportObject((Remote) this, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Creates and exports a new UnicastRemoteObject object using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * particular supplied port and socket factories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param port the port number on which the remote object receives calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * (if <code>port</code> is zero, an anonymous port is chosen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @throws RemoteException if failed to export object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected UnicastRemoteObject(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                  RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                  RMIServerSocketFactory ssf)
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
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.csf = csf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        this.ssf = ssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        exportObject((Remote) this, port, csf, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Re-export the remote object when it is deserialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private void readObject(java.io.ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        throws java.io.IOException, java.lang.ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        reexport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns a clone of the remote object that is distinct from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @exception CloneNotSupportedException if clone failed due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * a RemoteException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the new remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public Object clone() throws CloneNotSupportedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            UnicastRemoteObject cloned = (UnicastRemoteObject) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            cloned.reexport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return cloned;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw new ServerCloneException("Clone failed", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Exports this UnicastRemoteObject using its initialized fields because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * its creation bypassed running its constructors (via deserialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * or cloning, for example).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    private void reexport() throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (csf == null && ssf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            exportObject((Remote) this, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            exportObject((Remote) this, port, csf, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Exports the remote object to make it available to receive incoming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * calls using an anonymous port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param obj the remote object to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return remote object stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @exception RemoteException if export fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public static RemoteStub exportObject(Remote obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         * Use UnicastServerRef constructor passing the boolean value true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * to indicate that only a generated stub class should be used.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         * generated stub class must be used instead of a dynamic proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         * because the return value of this method is RemoteStub which a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         * dynamic proxy class cannot extend.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return (RemoteStub) exportObject(obj, new UnicastServerRef(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Exports the remote object to make it available to receive incoming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * calls, using the particular supplied port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param obj the remote object to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param port the port to export the object on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return remote object stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @exception RemoteException if export fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public static Remote exportObject(Remote obj, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return exportObject(obj, new UnicastServerRef(port));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Exports the remote object to make it available to receive incoming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * calls, using a transport specified by the given socket factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param obj the remote object to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param port the port to export the object on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return remote object stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @exception RemoteException if export fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public static Remote exportObject(Remote obj, int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                      RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                      RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return exportObject(obj, new UnicastServerRef2(port, csf, ssf));
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
     * Removes the remote object, obj, from the RMI runtime. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * successful, the object can no longer accept incoming RMI calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * If the force parameter is true, the object is forcibly unexported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * even if there are pending calls to the remote object or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * remote object still has calls in progress.  If the force
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * parameter is false, the object is only unexported if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * no pending or in progress calls to the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param obj the remote object to be unexported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param force if true, unexports the object even if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * pending or in-progress calls; if false, only unexports the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * if there are no pending or in-progress calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return true if operation is successful, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @exception NoSuchObjectException if the remote object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * currently exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public static boolean unexportObject(Remote obj, boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        throws java.rmi.NoSuchObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return sun.rmi.transport.ObjectTable.unexportObject(obj, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Exports the specified object using the specified server ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    private static Remote exportObject(Remote obj, UnicastServerRef sref)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // if obj extends UnicastRemoteObject, set its ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (obj instanceof UnicastRemoteObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            ((UnicastRemoteObject) obj).ref = sref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return sref.exportObject(obj, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}