author | henryjen |
Tue, 10 Jun 2014 16:18:54 -0700 | |
changeset 24865 | 09b1d992ca72 |
parent 21421 | aadfbd8b351b |
permissions | -rw-r--r-- |
2 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package java.rmi.server; |
|
26 |
||
27 |
import java.rmi.*; |
|
28 |
import sun.rmi.server.UnicastServerRef; |
|
29 |
import sun.rmi.server.UnicastServerRef2; |
|
30 |
||
31 |
/** |
|
32 |
* 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
|
33 |
* 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
|
34 |
* 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
|
35 |
* 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
|
36 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
37 |
* <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
|
38 |
* 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
|
39 |
* 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
|
40 |
* loading static stubs. Generating stubs dynamically is preferred, using one |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
41 |
* of the five non-deprecated ways of exporting objects as listed below. Do |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
42 |
* 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
|
43 |
* it is also deprecated.</em> |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
44 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
45 |
* <p>There are six ways to export remote objects: |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
46 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
47 |
* <ol> |
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 |
* <li>Subclassing {@code UnicastRemoteObject} and calling the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
50 |
* {@link #UnicastRemoteObject()} constructor. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
51 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
52 |
* <li>Subclassing {@code UnicastRemoteObject} and calling the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
53 |
* {@link #UnicastRemoteObject(int) UnicastRemoteObject(port)} constructor. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
54 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
55 |
* <li>Subclassing {@code UnicastRemoteObject} and calling the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
56 |
* {@link #UnicastRemoteObject(int, RMIClientSocketFactory, RMIServerSocketFactory) |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
57 |
* UnicastRemoteObject(port, csf, ssf)} constructor. |
2 | 58 |
* |
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
59 |
* <li>Calling the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
60 |
* {@link #exportObject(Remote) exportObject(Remote)} method. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
61 |
* <strong>Deprecated.</strong> |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
62 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
63 |
* <li>Calling the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
64 |
* {@link #exportObject(Remote, int) exportObject(Remote, port)} method. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
65 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
66 |
* <li>Calling the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
67 |
* {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory) |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
68 |
* exportObject(Remote, port, csf, ssf)} method. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
69 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
70 |
* </ol> |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
71 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
72 |
* <p>The fourth technique, {@link #exportObject(Remote)}, |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
73 |
* always uses statically generated stubs and is deprecated. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
74 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
75 |
* <p>The other five techniques all use the following approach: if the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
76 |
* {@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
|
77 |
* (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
|
78 |
* 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
|
79 |
* static stubs are used. |
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 default value of the |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
82 |
* {@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
|
83 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
84 |
* <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
|
85 |
* 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
|
86 |
* 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
|
87 |
* below. |
2 | 88 |
* |
21334 | 89 |
* <ul> |
2 | 90 |
* |
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
91 |
* <li>A "root class" is determined as follows: if the remote object's |
2 | 92 |
* class directly implements an interface that extends {@link Remote}, then |
93 |
* the remote object's class is the root class; otherwise, the root class is |
|
94 |
* 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
|
95 |
* implements an interface that extends {@code Remote}. |
2 | 96 |
* |
97 |
* <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
|
98 |
* the binary name of the root class with the suffix {@code _Stub}. |
2 | 99 |
* |
100 |
* <li>The stub class is loaded by name using the class loader of the root |
|
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
101 |
* class. The stub class must extend {@link RemoteStub} and must have a |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
102 |
* public constructor that has one parameter of type {@link RemoteRef}. |
2 | 103 |
* |
104 |
* <li>Finally, an instance of the stub class is constructed with a |
|
105 |
* {@link RemoteRef}. |
|
106 |
* |
|
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
107 |
* <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
|
108 |
* could not be loaded, or if a problem occurs creating the stub instance, a |
2 | 109 |
* {@link StubNotFoundException} is thrown. |
110 |
* |
|
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
111 |
* </ul> |
2 | 112 |
* |
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
113 |
* <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
|
114 |
* a {@link java.lang.reflect.Proxy Proxy} with the following characteristics: |
2 | 115 |
* |
116 |
* <ul> |
|
117 |
* |
|
118 |
* <li>The proxy's class is defined by the class loader of the remote |
|
119 |
* object's class. |
|
120 |
* |
|
121 |
* <li>The proxy implements all the remote interfaces implemented by the |
|
122 |
* remote object's class. |
|
123 |
* |
|
124 |
* <li>The proxy's invocation handler is a {@link |
|
125 |
* RemoteObjectInvocationHandler} instance constructed with a |
|
126 |
* {@link RemoteRef}. |
|
127 |
* |
|
128 |
* <li>If the proxy could not be created, a {@link StubNotFoundException} |
|
129 |
* will be thrown. |
|
130 |
* |
|
131 |
* </ul> |
|
132 |
* |
|
19201
80230405e311
8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents:
5506
diff
changeset
|
133 |
* @implNote |
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
134 |
* 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
|
135 |
* 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
|
136 |
* 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
|
137 |
* 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
|
138 |
* {@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
|
139 |
* <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
|
140 |
* in the |
80230405e311
8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents:
5506
diff
changeset
|
141 |
* <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
|
142 |
* |
2 | 143 |
* @author Ann Wollrath |
144 |
* @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
|
145 |
* @since 1.1 |
2 | 146 |
**/ |
147 |
public class UnicastRemoteObject extends RemoteServer { |
|
148 |
||
149 |
/** |
|
150 |
* @serial port number on which to export object |
|
151 |
*/ |
|
152 |
private int port = 0; |
|
153 |
||
154 |
/** |
|
155 |
* @serial client-side socket factory (if any) |
|
156 |
*/ |
|
157 |
private RMIClientSocketFactory csf = null; |
|
158 |
||
159 |
/** |
|
160 |
* @serial server-side socket factory (if any) to use when |
|
161 |
* exporting object |
|
162 |
*/ |
|
163 |
private RMIServerSocketFactory ssf = null; |
|
164 |
||
165 |
/* indicate compatibility with JDK 1.1.x version of class */ |
|
166 |
private static final long serialVersionUID = 4974527148936298033L; |
|
167 |
||
168 |
/** |
|
169 |
* Creates and exports a new UnicastRemoteObject object using an |
|
170 |
* anonymous port. |
|
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
171 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
172 |
* <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
|
173 |
* created using the {@link RMISocketFactory} class. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
174 |
* |
2 | 175 |
* @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
|
176 |
* @since 1.1 |
2 | 177 |
*/ |
178 |
protected UnicastRemoteObject() throws RemoteException |
|
179 |
{ |
|
180 |
this(0); |
|
181 |
} |
|
182 |
||
183 |
/** |
|
184 |
* Creates and exports a new UnicastRemoteObject object using the |
|
185 |
* particular supplied port. |
|
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
186 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
187 |
* <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
|
188 |
* created using the {@link RMISocketFactory} class. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
189 |
* |
2 | 190 |
* @param port the port number on which the remote object receives calls |
191 |
* (if <code>port</code> is zero, an anonymous port is chosen) |
|
192 |
* @throws RemoteException if failed to export object |
|
193 |
* @since 1.2 |
|
194 |
*/ |
|
195 |
protected UnicastRemoteObject(int port) throws RemoteException |
|
196 |
{ |
|
197 |
this.port = port; |
|
198 |
exportObject((Remote) this, port); |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* Creates and exports a new UnicastRemoteObject object using the |
|
203 |
* particular supplied port and socket factories. |
|
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
204 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
205 |
* <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
|
206 |
* 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
|
207 |
* {@link RMISocketFactory} is used instead. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
208 |
* |
2 | 209 |
* @param port the port number on which the remote object receives calls |
210 |
* (if <code>port</code> is zero, an anonymous port is chosen) |
|
211 |
* @param csf the client-side socket factory for making calls to the |
|
212 |
* remote object |
|
213 |
* @param ssf the server-side socket factory for receiving remote calls |
|
214 |
* @throws RemoteException if failed to export object |
|
215 |
* @since 1.2 |
|
216 |
*/ |
|
217 |
protected UnicastRemoteObject(int port, |
|
218 |
RMIClientSocketFactory csf, |
|
219 |
RMIServerSocketFactory ssf) |
|
220 |
throws RemoteException |
|
221 |
{ |
|
222 |
this.port = port; |
|
223 |
this.csf = csf; |
|
224 |
this.ssf = ssf; |
|
225 |
exportObject((Remote) this, port, csf, ssf); |
|
226 |
} |
|
227 |
||
228 |
/** |
|
229 |
* Re-export the remote object when it is deserialized. |
|
230 |
*/ |
|
231 |
private void readObject(java.io.ObjectInputStream in) |
|
232 |
throws java.io.IOException, java.lang.ClassNotFoundException |
|
233 |
{ |
|
234 |
in.defaultReadObject(); |
|
235 |
reexport(); |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Returns a clone of the remote object that is distinct from |
|
240 |
* the original. |
|
241 |
* |
|
242 |
* @exception CloneNotSupportedException if clone failed due to |
|
243 |
* a RemoteException. |
|
244 |
* @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
|
245 |
* @since 1.1 |
2 | 246 |
*/ |
247 |
public Object clone() throws CloneNotSupportedException |
|
248 |
{ |
|
249 |
try { |
|
250 |
UnicastRemoteObject cloned = (UnicastRemoteObject) super.clone(); |
|
251 |
cloned.reexport(); |
|
252 |
return cloned; |
|
253 |
} catch (RemoteException e) { |
|
254 |
throw new ServerCloneException("Clone failed", e); |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
/* |
|
259 |
* Exports this UnicastRemoteObject using its initialized fields because |
|
260 |
* its creation bypassed running its constructors (via deserialization |
|
261 |
* or cloning, for example). |
|
262 |
*/ |
|
263 |
private void reexport() throws RemoteException |
|
264 |
{ |
|
265 |
if (csf == null && ssf == null) { |
|
266 |
exportObject((Remote) this, port); |
|
267 |
} else { |
|
268 |
exportObject((Remote) this, port, csf, ssf); |
|
269 |
} |
|
270 |
} |
|
271 |
||
272 |
/** |
|
273 |
* 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
|
274 |
* 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
|
275 |
* statically generated stub. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
276 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
277 |
* <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
|
278 |
* created using the {@link RMISocketFactory} class. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
279 |
* |
2 | 280 |
* @param obj the remote object to be exported |
281 |
* @return remote object stub |
|
282 |
* @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
|
283 |
* @since 1.1 |
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
284 |
* @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
|
285 |
* 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
|
286 |
* {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory) |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
287 |
* exportObject(Remote, port, csf, ssf)} |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
288 |
* instead. |
2 | 289 |
*/ |
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
290 |
@Deprecated |
2 | 291 |
public static RemoteStub exportObject(Remote obj) |
292 |
throws RemoteException |
|
293 |
{ |
|
294 |
/* |
|
295 |
* Use UnicastServerRef constructor passing the boolean value true |
|
296 |
* to indicate that only a generated stub class should be used. A |
|
297 |
* generated stub class must be used instead of a dynamic proxy |
|
298 |
* because the return value of this method is RemoteStub which a |
|
299 |
* dynamic proxy class cannot extend. |
|
300 |
*/ |
|
301 |
return (RemoteStub) exportObject(obj, new UnicastServerRef(true)); |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* Exports the remote object to make it available to receive incoming |
|
306 |
* calls, using the particular supplied port. |
|
21421
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
307 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
308 |
* <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
|
309 |
* created using the {@link RMISocketFactory} class. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
310 |
* |
2 | 311 |
* @param obj the remote object to be exported |
312 |
* @param port the port to export the object on |
|
313 |
* @return remote object stub |
|
314 |
* @exception RemoteException if export fails |
|
315 |
* @since 1.2 |
|
316 |
*/ |
|
317 |
public static Remote exportObject(Remote obj, int port) |
|
318 |
throws RemoteException |
|
319 |
{ |
|
320 |
return exportObject(obj, new UnicastServerRef(port)); |
|
321 |
} |
|
322 |
||
323 |
/** |
|
324 |
* Exports the remote object to make it available to receive incoming |
|
325 |
* 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
|
326 |
* |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
327 |
* <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
|
328 |
* 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
|
329 |
* {@link RMISocketFactory} is used instead. |
aadfbd8b351b
8023863: deprecate support for statically-generated stubs from RMI (JRMP)
smarks
parents:
21334
diff
changeset
|
330 |
* |
2 | 331 |
* @param obj the remote object to be exported |
332 |
* @param port the port to export the object on |
|
333 |
* @param csf the client-side socket factory for making calls to the |
|
334 |
* remote object |
|
335 |
* @param ssf the server-side socket factory for receiving remote calls |
|
336 |
* @return remote object stub |
|
337 |
* @exception RemoteException if export fails |
|
338 |
* @since 1.2 |
|
339 |
*/ |
|
340 |
public static Remote exportObject(Remote obj, int port, |
|
341 |
RMIClientSocketFactory csf, |
|
342 |
RMIServerSocketFactory ssf) |
|
343 |
throws RemoteException |
|
344 |
{ |
|
345 |
||
346 |
return exportObject(obj, new UnicastServerRef2(port, csf, ssf)); |
|
347 |
} |
|
348 |
||
349 |
/** |
|
350 |
* Removes the remote object, obj, from the RMI runtime. If |
|
351 |
* successful, the object can no longer accept incoming RMI calls. |
|
352 |
* If the force parameter is true, the object is forcibly unexported |
|
353 |
* even if there are pending calls to the remote object or the |
|
354 |
* remote object still has calls in progress. If the force |
|
355 |
* parameter is false, the object is only unexported if there are |
|
356 |
* no pending or in progress calls to the object. |
|
357 |
* |
|
358 |
* @param obj the remote object to be unexported |
|
359 |
* @param force if true, unexports the object even if there are |
|
360 |
* pending or in-progress calls; if false, only unexports the object |
|
361 |
* if there are no pending or in-progress calls |
|
362 |
* @return true if operation is successful, false otherwise |
|
363 |
* @exception NoSuchObjectException if the remote object is not |
|
364 |
* currently exported |
|
365 |
* @since 1.2 |
|
366 |
*/ |
|
367 |
public static boolean unexportObject(Remote obj, boolean force) |
|
368 |
throws java.rmi.NoSuchObjectException |
|
369 |
{ |
|
370 |
return sun.rmi.transport.ObjectTable.unexportObject(obj, force); |
|
371 |
} |
|
372 |
||
373 |
/** |
|
374 |
* Exports the specified object using the specified server ref. |
|
375 |
*/ |
|
376 |
private static Remote exportObject(Remote obj, UnicastServerRef sref) |
|
377 |
throws RemoteException |
|
378 |
{ |
|
379 |
// if obj extends UnicastRemoteObject, set its ref. |
|
380 |
if (obj instanceof UnicastRemoteObject) { |
|
381 |
((UnicastRemoteObject) obj).ref = sref; |
|
382 |
} |
|
383 |
return sref.exportObject(obj, null, false); |
|
384 |
} |
|
385 |
} |