src/java.rmi/share/classes/java/rmi/server/UnicastRemoteObject.java
author serb
Thu, 12 Sep 2019 22:20:35 -0700
changeset 58323 7b3101216e61
parent 50774 662f66f9c9e2
child 58609 fbfc72ec8e6b
permissions -rw-r--r--
8225101: Crash at sun.awt.X11.XlibWrapper.XkbGetUpdatedMap when change keybord map Reviewed-by: prr, pbansal
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45029
8a8e17cde86f 8179692: Move RMI spec to specs directory
ihse
parents: 44545
diff changeset
     2
 * Copyright (c) 1996, 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
package java.rmi.server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    27
import java.io.ObjectInputFilter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.rmi.server.UnicastServerRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.rmi.server.UnicastServerRef2;
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    31
import sun.rmi.transport.LiveRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Used for exporting a remote object with JRMP and obtaining a stub
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    35
 * that communicates to the remote object. Stubs are either generated
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    36
 * at runtime using dynamic proxy objects, or they are generated statically
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    37
 * at build time, typically using the {@code rmic} tool.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    38
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    39
 * <p><strong>Deprecated: Static Stubs.</strong> <em>Support for statically
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    40
 * generated stubs is deprecated. This includes the API in this class that
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    41
 * requires the use of static stubs, as well as the runtime support for
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    42
 * loading static stubs.  Generating stubs dynamically is preferred, using one
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    43
 * of the non-deprecated ways of exporting objects as listed below. Do
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    44
 * not run {@code rmic} to generate static stub classes. It is unnecessary, and
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    45
 * it is also deprecated.</em>
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    46
 *
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    47
 * <p>There are eight ways to export remote objects:
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    48
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    49
 * <ol>
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    50
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    51
 * <li>Subclassing {@code UnicastRemoteObject} and calling the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    52
 * {@link #UnicastRemoteObject()} constructor.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    53
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    54
 * <li>Subclassing {@code UnicastRemoteObject} and calling the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    55
 * {@link #UnicastRemoteObject(int) UnicastRemoteObject(port)} constructor.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    56
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    57
 * <li>Subclassing {@code UnicastRemoteObject} and calling the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    58
 * {@link #UnicastRemoteObject(int, RMIClientSocketFactory, RMIServerSocketFactory)
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    59
 * UnicastRemoteObject(port, csf, ssf)} constructor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    61
 * <li>Calling the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    62
 * {@link #exportObject(Remote) exportObject(Remote)} method.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    63
 * <strong>Deprecated.</strong>
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    64
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    65
 * <li>Calling the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    66
 * {@link #exportObject(Remote, int) exportObject(Remote, port)} method.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    67
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    68
 * <li>Calling the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    69
 * {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory)
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    70
 * exportObject(Remote, port, csf, ssf)} method.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    71
 *
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    72
 * <li>Calling the
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    73
 * {@link #exportObject(Remote, int, ObjectInputFilter) exportObject(Remote, port, filter)} method.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    74
 *
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    75
 * <li>Calling the
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    76
 * {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory, ObjectInputFilter)
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    77
 * exportObject(Remote, port, csf, ssf, filter)} method.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    78
 *
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    79
 * </ol>
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    80
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    81
 * <p>The fourth technique, {@link #exportObject(Remote)},
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    82
 * always uses statically generated stubs and is deprecated.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    83
 *
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
    84
 * <p>The other techniques all use the following approach: if the
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    85
 * {@code java.rmi.server.ignoreStubClasses} property is {@code true}
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    86
 * (case insensitive) or if a static stub cannot be found, stubs are generated
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    87
 * dynamically using {@link java.lang.reflect.Proxy Proxy} objects. Otherwise,
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    88
 * static stubs are used.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    89
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    90
 * <p>The default value of the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    91
 * {@code java.rmi.server.ignoreStubClasses} property is {@code false}.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    92
 *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    93
 * <p>Statically generated stubs are typically pregenerated from the
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    94
 * remote object's class using the {@code rmic} tool. A static stub is
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    95
 * loaded and an instance of that stub class is constructed as described
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
    96
 * below.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 19201
diff changeset
    98
 * <ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   100
 * <li>A "root class" is determined as follows: if the remote object's
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * class directly implements an interface that extends {@link Remote}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * the remote object's class is the root class; otherwise, the root class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * the most derived superclass of the remote object's class that directly
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   104
 * implements an interface that extends {@code Remote}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <li>The name of the stub class to load is determined by concatenating
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   107
 * the binary name of the root class with the suffix {@code _Stub}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <li>The stub class is loaded by name using the class loader of the root
43690
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   110
 * class. The stub class must be public, it must extend {@link RemoteStub}, it must
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   111
 * reside in a package that is exported to at least the {@code java.rmi} module, and it
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   112
 * must have a public constructor that has one parameter of type {@link RemoteRef}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <li>Finally, an instance of the stub class is constructed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * {@link RemoteRef}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   117
 * <li>If the appropriate stub class could not be found, or if the stub class
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   118
 * could not be loaded, or if a problem occurs creating the stub instance, a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * {@link StubNotFoundException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   121
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   123
 * <p>Stubs are dynamically generated by constructing an instance of
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   124
 * a {@link java.lang.reflect.Proxy Proxy} with the following characteristics:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
43690
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   128
 * <li>The proxy's class is defined according to the specifications for the
50774
662f66f9c9e2 8201610: Broken link on the page api/java.rmi/java/rmi/server/UnicastRemoteObject.html
smarks
parents: 47216
diff changeset
   129
 * <a href="{@docRoot}/java.base/java/lang/reflect/Proxy.html#membership">
43690
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   130
 * {@code Proxy}
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   131
 * </a>
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   132
 * class, using the class loader of the remote object's class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <li>The proxy implements all the remote interfaces implemented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * remote object's class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *
43690
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   137
 * <li>Each remote interface must either be public and reside in a package that is
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43690
diff changeset
   138
 * {@linkplain Module#isExported(String,Module) exported}
43690
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   139
 * to at least the {@code java.rmi} module, or it must reside in a package that is
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43690
diff changeset
   140
 * {@linkplain Module#isOpen(String,Module) open}
43690
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   141
 * to at least the {@code java.rmi} module.
e8cdf30d90c4 8044626: Update RMI specifications to reflect modularization changes
smarks
parents: 41232
diff changeset
   142
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <li>The proxy's invocation handler is a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * RemoteObjectInvocationHandler} instance constructed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * {@link RemoteRef}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <li>If the proxy could not be created, a {@link StubNotFoundException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   152
 * <p>
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   153
 * Exported remote objects receive method invocations from the stubs
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   154
 * as described in the RMI specification. Each invocation's operation and
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   155
 * parameters are unmarshaled using a custom {@link java.io.ObjectInputStream}.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   156
 * If an {@link ObjectInputFilter} is provided and is not {@code null} when the object
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   157
 * is exported, it is used to filter the parameters as they are unmarshaled from the stream.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   158
 * The filter is used for all invocations and all parameters regardless of
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   159
 * the method being invoked or the parameter values.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   160
 * If no filter is provided or is {@code null} for the exported object then the
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   161
 * {@code ObjectInputStream} default filter, if any, is used. The default filter is
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   162
 * configured with {@link ObjectInputFilter.Config#setSerialFilter(ObjectInputFilter)
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   163
 * ObjectInputFilter.Config.setSerialFilter}.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   164
 * If the filter rejects any of the parameters, the {@code InvalidClassException}
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   165
 * thrown by {@code ObjectInputStream} is reported as the cause of an
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   166
 * {@link UnmarshalException}.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   167
 *
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   168
 * @implNote
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   169
 * Depending upon which constructor or static method is used for exporting an
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   170
 * object, {@link RMISocketFactory} may be used for creating sockets.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   171
 * By default, server sockets created by {@link RMISocketFactory}
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   172
 * 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
   173
 * {@link RMISocketFactory} class and the section
45029
8a8e17cde86f 8179692: Move RMI spec to specs directory
ihse
parents: 44545
diff changeset
   174
 * <a href="{@docRoot}/../specs/rmi/server.html#rmi-socket-factories">RMI Socket Factories</a>
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   175
 * in the
45029
8a8e17cde86f 8179692: Move RMI spec to specs directory
ihse
parents: 44545
diff changeset
   176
 * <a href="{@docRoot}/../specs/rmi/index.html">Java RMI Specification</a>.
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
   177
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * @author  Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * @author  Peter Jones
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21421
diff changeset
   180
 * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
public class UnicastRemoteObject extends RemoteServer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @serial port number on which to export object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private int port = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @serial client-side socket factory (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private RMIClientSocketFactory csf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @serial server-side socket factory (if any) to use when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * exporting object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private RMIServerSocketFactory ssf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /* indicate compatibility with JDK 1.1.x version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static final long serialVersionUID = 4974527148936298033L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Creates and exports a new UnicastRemoteObject object using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * anonymous port.
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   206
     *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   207
     * <p>The object is exported with a server socket
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   208
     * created using the {@link RMISocketFactory} class.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   209
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @throws RemoteException if failed to export object
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21421
diff changeset
   211
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    protected UnicastRemoteObject() throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        this(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Creates and exports a new UnicastRemoteObject object using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * particular supplied port.
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   221
     *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   222
     * <p>The object is exported with a server socket
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   223
     * created using the {@link RMISocketFactory} class.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   224
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param port the port number on which the remote object receives calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * (if <code>port</code> is zero, an anonymous port is chosen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @throws RemoteException if failed to export object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    protected UnicastRemoteObject(int port) throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        exportObject((Remote) this, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Creates and exports a new UnicastRemoteObject object using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * particular supplied port and socket factories.
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   239
     *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   240
     * <p>Either socket factory may be {@code null}, in which case
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   241
     * the corresponding client or server socket creation method of
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   242
     * {@link RMISocketFactory} is used instead.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   243
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param port the port number on which the remote object receives calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * (if <code>port</code> is zero, an anonymous port is chosen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws RemoteException if failed to export object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected UnicastRemoteObject(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                  RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                  RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        this.csf = csf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        this.ssf = ssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        exportObject((Remote) this, port, csf, ssf);
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
     * Re-export the remote object when it is deserialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private void readObject(java.io.ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        throws java.io.IOException, java.lang.ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        reexport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Returns a clone of the remote object that is distinct from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @exception CloneNotSupportedException if clone failed due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * a RemoteException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return the new remote object
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21421
diff changeset
   280
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public Object clone() throws CloneNotSupportedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            UnicastRemoteObject cloned = (UnicastRemoteObject) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            cloned.reexport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return cloned;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throw new ServerCloneException("Clone failed", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Exports this UnicastRemoteObject using its initialized fields because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * its creation bypassed running its constructors (via deserialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * or cloning, for example).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private void reexport() throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (csf == null && ssf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            exportObject((Remote) this, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            exportObject((Remote) this, port, csf, ssf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Exports the remote object to make it available to receive incoming
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   309
     * calls using an anonymous port. This method will always return a
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   310
     * statically generated stub.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   311
     *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   312
     * <p>The object is exported with a server socket
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   313
     * created using the {@link RMISocketFactory} class.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   314
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param obj the remote object to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @return remote object stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @exception RemoteException if export fails
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21421
diff changeset
   318
     * @since 1.1
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   319
     * @deprecated This method is deprecated because it supports only static stubs.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   320
     * Use {@link #exportObject(Remote, int) exportObject(Remote, port)} or
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   321
     * {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory)
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   322
     * exportObject(Remote, port, csf, ssf)}
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   323
     * instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   325
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public static RemoteStub exportObject(Remote obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         * Use UnicastServerRef constructor passing the boolean value true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         * to indicate that only a generated stub class should be used.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
         * generated stub class must be used instead of a dynamic proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
         * because the return value of this method is RemoteStub which a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
         * dynamic proxy class cannot extend.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return (RemoteStub) exportObject(obj, new UnicastServerRef(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Exports the remote object to make it available to receive incoming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * calls, using the particular supplied port.
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   342
     *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   343
     * <p>The object is exported with a server socket
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   344
     * created using the {@link RMISocketFactory} class.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   345
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param obj the remote object to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @param port the port to export the object on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @return remote object stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @exception RemoteException if export fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public static Remote exportObject(Remote obj, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return exportObject(obj, new UnicastServerRef(port));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Exports the remote object to make it available to receive incoming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * calls, using a transport specified by the given socket factory.
21421
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   361
     *
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   362
     * <p>Either socket factory may be {@code null}, in which case
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   363
     * the corresponding client or server socket creation method of
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   364
     * {@link RMISocketFactory} is used instead.
aadfbd8b351b 8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents: 21334
diff changeset
   365
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @param obj the remote object to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param port the port to export the object on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param csf the client-side socket factory for making calls to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param ssf the server-side socket factory for receiving remote calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @return remote object stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @exception RemoteException if export fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public static Remote exportObject(Remote obj, int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                      RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                      RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        return exportObject(obj, new UnicastServerRef2(port, csf, ssf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
41232
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   385
     * Exports the remote object to make it available to receive incoming
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   386
     * calls, using the particular supplied port
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   387
     * and {@linkplain ObjectInputFilter filter}.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   388
     *
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   389
     * <p>The object is exported with a server socket
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   390
     * created using the {@link RMISocketFactory} class.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   391
     *
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   392
     * @param obj the remote object to be exported
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   393
     * @param port the port to export the object on
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   394
     * @param filter an ObjectInputFilter applied when deserializing invocation arguments;
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   395
     *               may be {@code null}
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   396
     * @return remote object stub
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   397
     * @exception RemoteException if export fails
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   398
     * @since 9
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   399
     */
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   400
    public static Remote exportObject(Remote obj, int port,
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   401
                                      ObjectInputFilter filter)
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   402
            throws RemoteException
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   403
    {
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   404
        return exportObject(obj, new UnicastServerRef(new LiveRef(port), filter));
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   405
    }
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   406
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   407
    /**
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   408
     * Exports the remote object to make it available to receive incoming
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   409
     * calls, using a transport specified by the given socket factory
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   410
     * and {@linkplain ObjectInputFilter filter}.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   411
     *
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   412
     * <p>Either socket factory may be {@code null}, in which case
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   413
     * the corresponding client or server socket creation method of
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   414
     * {@link RMISocketFactory} is used instead.
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   415
     *
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   416
     * @param obj the remote object to be exported
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   417
     * @param port the port to export the object on
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   418
     * @param csf the client-side socket factory for making calls to the
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   419
     * remote object
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   420
     * @param ssf the server-side socket factory for receiving remote calls
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   421
     * @param filter an ObjectInputFilter applied when deserializing invocation arguments;
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   422
     *               may be {@code null}
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   423
     * @return remote object stub
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   424
     * @exception RemoteException if export fails
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   425
     * @since 9
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   426
     */
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   427
    public static Remote exportObject(Remote obj, int port,
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   428
                                      RMIClientSocketFactory csf,
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   429
                                      RMIServerSocketFactory ssf,
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   430
                                      ObjectInputFilter filter)
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   431
        throws RemoteException
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   432
    {
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   433
        return exportObject(obj, new UnicastServerRef2(port, csf, ssf, filter));
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   434
    }
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   435
5da543633b3b 8165261: RMI API to export an object with a serialization filter
rriggs
parents: 25859
diff changeset
   436
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Removes the remote object, obj, from the RMI runtime. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * successful, the object can no longer accept incoming RMI calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * If the force parameter is true, the object is forcibly unexported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * even if there are pending calls to the remote object or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * remote object still has calls in progress.  If the force
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * parameter is false, the object is only unexported if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * no pending or in progress calls to the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @param obj the remote object to be unexported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param force if true, unexports the object even if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * pending or in-progress calls; if false, only unexports the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * if there are no pending or in-progress calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @return true if operation is successful, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @exception NoSuchObjectException if the remote object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * currently exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public static boolean unexportObject(Remote obj, boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        throws java.rmi.NoSuchObjectException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return sun.rmi.transport.ObjectTable.unexportObject(obj, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Exports the specified object using the specified server ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    private static Remote exportObject(Remote obj, UnicastServerRef sref)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        // if obj extends UnicastRemoteObject, set its ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (obj instanceof UnicastRemoteObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            ((UnicastRemoteObject) obj).ref = sref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        return sref.exportObject(obj, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
}