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