author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 23333 | jdk/src/share/classes/sun/rmi/server/UnicastServerRef.java@b0af2c7c8c91 |
child 37584 | 0cc00d7a0755 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
19211 | 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 |
||
26 |
package sun.rmi.server; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.io.ObjectInput; |
|
30 |
import java.io.ObjectOutput; |
|
31 |
import java.io.PrintStream; |
|
32 |
import java.lang.reflect.InvocationTargetException; |
|
33 |
import java.lang.reflect.Method; |
|
34 |
import java.rmi.MarshalException; |
|
35 |
import java.rmi.Remote; |
|
36 |
import java.rmi.RemoteException; |
|
37 |
import java.rmi.ServerError; |
|
38 |
import java.rmi.ServerException; |
|
39 |
import java.rmi.UnmarshalException; |
|
40 |
import java.rmi.server.ExportException; |
|
41 |
import java.rmi.server.RemoteCall; |
|
42 |
import java.rmi.server.RemoteRef; |
|
43 |
import java.rmi.server.RemoteStub; |
|
44 |
import java.rmi.server.ServerNotActiveException; |
|
45 |
import java.rmi.server.ServerRef; |
|
46 |
import java.rmi.server.Skeleton; |
|
47 |
import java.rmi.server.SkeletonNotFoundException; |
|
48 |
import java.security.AccessController; |
|
49 |
import java.security.PrivilegedAction; |
|
50 |
import java.util.Collections; |
|
51 |
import java.util.Date; |
|
52 |
import java.util.HashMap; |
|
53 |
import java.util.Map; |
|
54 |
import java.util.WeakHashMap; |
|
55 |
import sun.rmi.runtime.Log; |
|
56 |
import sun.rmi.transport.LiveRef; |
|
57 |
import sun.rmi.transport.Target; |
|
58 |
import sun.rmi.transport.tcp.TCPTransport; |
|
59 |
||
60 |
/** |
|
61 |
* UnicastServerRef implements the remote reference layer server-side |
|
62 |
* behavior for remote objects exported with the "UnicastRef" reference |
|
63 |
* type. |
|
64 |
* |
|
65 |
* @author Ann Wollrath |
|
66 |
* @author Roger Riggs |
|
67 |
* @author Peter Jones |
|
68 |
*/ |
|
19211 | 69 |
@SuppressWarnings("deprecation") |
2 | 70 |
public class UnicastServerRef extends UnicastRef |
71 |
implements ServerRef, Dispatcher |
|
72 |
{ |
|
73 |
/** value of server call log property */ |
|
74 |
public static final boolean logCalls = AccessController.doPrivileged( |
|
23333
b0af2c7c8c91
8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents:
21655
diff
changeset
|
75 |
(PrivilegedAction<Boolean>) () -> Boolean.getBoolean("java.rmi.server.logCalls")); |
2 | 76 |
|
77 |
/** server call log */ |
|
78 |
public static final Log callLog = |
|
79 |
Log.getLog("sun.rmi.server.call", "RMI", logCalls); |
|
80 |
||
81 |
// use serialVersionUID from JDK 1.2.2 for interoperability |
|
82 |
private static final long serialVersionUID = -7384275867073752268L; |
|
83 |
||
84 |
/** flag to enable writing exceptions to System.err */ |
|
85 |
private static final boolean wantExceptionLog = |
|
23333
b0af2c7c8c91
8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents:
21655
diff
changeset
|
86 |
AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> |
b0af2c7c8c91
8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents:
21655
diff
changeset
|
87 |
Boolean.getBoolean("sun.rmi.server.exceptionTrace")); |
2 | 88 |
|
89 |
private boolean forceStubUse = false; |
|
90 |
||
91 |
/** |
|
92 |
* flag to remove server-side stack traces before marshalling |
|
93 |
* exceptions thrown by remote invocations to this VM |
|
94 |
*/ |
|
95 |
private static final boolean suppressStackTraces = |
|
23333
b0af2c7c8c91
8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents:
21655
diff
changeset
|
96 |
AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> |
b0af2c7c8c91
8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents:
21655
diff
changeset
|
97 |
Boolean.getBoolean("sun.rmi.server.suppressStackTraces")); |
2 | 98 |
|
99 |
/** |
|
100 |
* skeleton to dispatch remote calls through, for 1.1 stub protocol |
|
101 |
* (may be null if stub class only uses 1.2 stub protocol) |
|
102 |
*/ |
|
103 |
private transient Skeleton skel; |
|
104 |
||
105 |
/** maps method hash to Method object for each remote method */ |
|
106 |
private transient Map<Long,Method> hashToMethod_Map = null; |
|
107 |
||
108 |
/** |
|
109 |
* A weak hash map, mapping classes to hash maps that map method |
|
110 |
* hashes to method objects. |
|
111 |
**/ |
|
112 |
private static final WeakClassHashMap<Map<Long,Method>> hashToMethod_Maps = |
|
113 |
new HashToMethod_Maps(); |
|
114 |
||
115 |
/** cache of impl classes that have no corresponding skeleton class */ |
|
116 |
private static final Map<Class<?>,?> withoutSkeletons = |
|
117 |
Collections.synchronizedMap(new WeakHashMap<Class<?>,Void>()); |
|
118 |
||
119 |
/** |
|
120 |
* Create a new (empty) Unicast server remote reference. |
|
121 |
*/ |
|
122 |
public UnicastServerRef() { |
|
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* Construct a Unicast server remote reference for a specified |
|
127 |
* liveRef. |
|
128 |
*/ |
|
129 |
public UnicastServerRef(LiveRef ref) { |
|
130 |
super(ref); |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Construct a Unicast server remote reference to be exported |
|
135 |
* on the specified port. |
|
136 |
*/ |
|
137 |
public UnicastServerRef(int port) { |
|
138 |
super(new LiveRef(port)); |
|
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
* Constructs a UnicastServerRef to be exported on an |
|
143 |
* anonymous port (i.e., 0) and that uses a pregenerated stub class |
|
144 |
* (NOT a dynamic proxy instance) if 'forceStubUse' is 'true'. |
|
145 |
* |
|
146 |
* This constructor is only called by the method |
|
147 |
* UnicastRemoteObject.exportObject(Remote) passing 'true' for |
|
148 |
* 'forceStubUse'. The UnicastRemoteObject.exportObject(Remote) method |
|
149 |
* returns RemoteStub, so it must ensure that the stub for the |
|
150 |
* exported object is an instance of a pregenerated stub class that |
|
151 |
* extends RemoteStub (instead of an instance of a dynamic proxy class |
|
152 |
* which is not an instance of RemoteStub). |
|
153 |
**/ |
|
154 |
public UnicastServerRef(boolean forceStubUse) { |
|
155 |
this(0); |
|
156 |
this.forceStubUse = forceStubUse; |
|
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
* With the addition of support for dynamic proxies as stubs, this |
|
161 |
* method is obsolete because it returns RemoteStub instead of the more |
|
162 |
* general Remote. It should not be called. It sets the |
|
163 |
* 'forceStubUse' flag to true so that the stub for the exported object |
|
164 |
* is forced to be an instance of the pregenerated stub class, which |
|
165 |
* extends RemoteStub. |
|
166 |
* |
|
167 |
* Export this object, create the skeleton and stubs for this |
|
168 |
* dispatcher. Create a stub based on the type of the impl, |
|
169 |
* initialize it with the appropriate remote reference. Create the |
|
170 |
* target defined by the impl, dispatcher (this) and stub. |
|
171 |
* Export that target via the Ref. |
|
172 |
**/ |
|
173 |
public RemoteStub exportObject(Remote impl, Object data) |
|
174 |
throws RemoteException |
|
175 |
{ |
|
176 |
forceStubUse = true; |
|
177 |
return (RemoteStub) exportObject(impl, data, false); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Export this object, create the skeleton and stubs for this |
|
182 |
* dispatcher. Create a stub based on the type of the impl, |
|
183 |
* initialize it with the appropriate remote reference. Create the |
|
184 |
* target defined by the impl, dispatcher (this) and stub. |
|
185 |
* Export that target via the Ref. |
|
186 |
*/ |
|
187 |
public Remote exportObject(Remote impl, Object data, |
|
188 |
boolean permanent) |
|
189 |
throws RemoteException |
|
190 |
{ |
|
12040
558b0e0d5910
7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents:
10912
diff
changeset
|
191 |
Class<?> implClass = impl.getClass(); |
2 | 192 |
Remote stub; |
193 |
||
194 |
try { |
|
195 |
stub = Util.createProxy(implClass, getClientRef(), forceStubUse); |
|
196 |
} catch (IllegalArgumentException e) { |
|
197 |
throw new ExportException( |
|
198 |
"remote object implements illegal remote interface", e); |
|
199 |
} |
|
200 |
if (stub instanceof RemoteStub) { |
|
201 |
setSkeleton(impl); |
|
202 |
} |
|
203 |
||
204 |
Target target = |
|
205 |
new Target(impl, this, stub, ref.getObjID(), permanent); |
|
206 |
ref.exportObject(target); |
|
207 |
hashToMethod_Map = hashToMethod_Maps.get(implClass); |
|
208 |
return stub; |
|
209 |
} |
|
210 |
||
211 |
/** |
|
212 |
* Return the hostname of the current client. When called from a |
|
213 |
* thread actively handling a remote method invocation the |
|
214 |
* hostname of the client is returned. |
|
215 |
* @exception ServerNotActiveException If called outside of servicing |
|
216 |
* a remote method invocation. |
|
217 |
*/ |
|
218 |
public String getClientHost() throws ServerNotActiveException { |
|
219 |
return TCPTransport.getClientHost(); |
|
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* Discovers and sets the appropriate skeleton for the impl. |
|
224 |
*/ |
|
225 |
public void setSkeleton(Remote impl) throws RemoteException { |
|
226 |
if (!withoutSkeletons.containsKey(impl.getClass())) { |
|
227 |
try { |
|
228 |
skel = Util.createSkeleton(impl); |
|
229 |
} catch (SkeletonNotFoundException e) { |
|
230 |
/* |
|
231 |
* Ignore exception for skeleton class not found, because a |
|
232 |
* skeleton class is not necessary with the 1.2 stub protocol. |
|
233 |
* Remember that this impl's class does not have a skeleton |
|
234 |
* class so we don't waste time searching for it again. |
|
235 |
*/ |
|
236 |
withoutSkeletons.put(impl.getClass(), null); |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
/** |
|
242 |
* Call to dispatch to the remote object (on the server side). |
|
243 |
* The up-call to the server and the marshalling of return result |
|
244 |
* (or exception) should be handled before returning from this |
|
245 |
* method. |
|
246 |
* @param obj the target remote object for the call |
|
247 |
* @param call the "remote call" from which operation and |
|
248 |
* method arguments can be obtained. |
|
249 |
* @exception IOException If unable to marshal return result or |
|
250 |
* release input or output streams |
|
251 |
*/ |
|
252 |
public void dispatch(Remote obj, RemoteCall call) throws IOException { |
|
253 |
// positive operation number in 1.1 stubs; |
|
254 |
// negative version number in 1.2 stubs and beyond... |
|
255 |
int num; |
|
256 |
long op; |
|
257 |
||
258 |
try { |
|
259 |
// read remote call header |
|
260 |
ObjectInput in; |
|
261 |
try { |
|
262 |
in = call.getInputStream(); |
|
263 |
num = in.readInt(); |
|
264 |
if (num >= 0) { |
|
265 |
if (skel != null) { |
|
266 |
oldDispatch(obj, call, num); |
|
267 |
return; |
|
268 |
} else { |
|
269 |
throw new UnmarshalException( |
|
270 |
"skeleton class not found but required " + |
|
271 |
"for client version"); |
|
272 |
} |
|
273 |
} |
|
274 |
op = in.readLong(); |
|
275 |
} catch (Exception readEx) { |
|
276 |
throw new UnmarshalException("error unmarshalling call header", |
|
277 |
readEx); |
|
278 |
} |
|
279 |
||
280 |
/* |
|
281 |
* Since only system classes (with null class loaders) will be on |
|
282 |
* the execution stack during parameter unmarshalling for the 1.2 |
|
283 |
* stub protocol, tell the MarshalInputStream not to bother trying |
|
284 |
* to resolve classes using its superclasses's default method of |
|
285 |
* consulting the first non-null class loader on the stack. |
|
286 |
*/ |
|
287 |
MarshalInputStream marshalStream = (MarshalInputStream) in; |
|
288 |
marshalStream.skipDefaultResolveClass(); |
|
289 |
||
290 |
Method method = hashToMethod_Map.get(op); |
|
291 |
if (method == null) { |
|
292 |
throw new UnmarshalException("unrecognized method hash: " + |
|
293 |
"method not supported by remote object"); |
|
294 |
} |
|
295 |
||
296 |
// if calls are being logged, write out object id and operation |
|
297 |
logCall(obj, method); |
|
298 |
||
299 |
// unmarshal parameters |
|
21655
55f32ae4f920
8028229: Fix more raw types lint warning in core libraries
darcy
parents:
19211
diff
changeset
|
300 |
Class<?>[] types = method.getParameterTypes(); |
2 | 301 |
Object[] params = new Object[types.length]; |
302 |
||
303 |
try { |
|
304 |
unmarshalCustomCallData(in); |
|
305 |
for (int i = 0; i < types.length; i++) { |
|
306 |
params[i] = unmarshalValue(types[i], in); |
|
307 |
} |
|
308 |
} catch (java.io.IOException e) { |
|
309 |
throw new UnmarshalException( |
|
310 |
"error unmarshalling arguments", e); |
|
311 |
} catch (ClassNotFoundException e) { |
|
312 |
throw new UnmarshalException( |
|
313 |
"error unmarshalling arguments", e); |
|
314 |
} finally { |
|
315 |
call.releaseInputStream(); |
|
316 |
} |
|
317 |
||
318 |
// make upcall on remote object |
|
319 |
Object result; |
|
320 |
try { |
|
321 |
result = method.invoke(obj, params); |
|
322 |
} catch (InvocationTargetException e) { |
|
323 |
throw e.getTargetException(); |
|
324 |
} |
|
325 |
||
326 |
// marshal return value |
|
327 |
try { |
|
328 |
ObjectOutput out = call.getResultStream(true); |
|
12040
558b0e0d5910
7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents:
10912
diff
changeset
|
329 |
Class<?> rtype = method.getReturnType(); |
2 | 330 |
if (rtype != void.class) { |
331 |
marshalValue(rtype, result, out); |
|
332 |
} |
|
333 |
} catch (IOException ex) { |
|
334 |
throw new MarshalException("error marshalling return", ex); |
|
335 |
/* |
|
336 |
* This throw is problematic because when it is caught below, |
|
337 |
* we attempt to marshal it back to the client, but at this |
|
338 |
* point, a "normal return" has already been indicated, |
|
339 |
* so marshalling an exception will corrupt the stream. |
|
340 |
* This was the case with skeletons as well; there is no |
|
341 |
* immediately obvious solution without a protocol change. |
|
342 |
*/ |
|
343 |
} |
|
344 |
} catch (Throwable e) { |
|
345 |
logCallException(e); |
|
346 |
||
347 |
ObjectOutput out = call.getResultStream(false); |
|
348 |
if (e instanceof Error) { |
|
349 |
e = new ServerError( |
|
350 |
"Error occurred in server thread", (Error) e); |
|
351 |
} else if (e instanceof RemoteException) { |
|
352 |
e = new ServerException( |
|
353 |
"RemoteException occurred in server thread", |
|
354 |
(Exception) e); |
|
355 |
} |
|
356 |
if (suppressStackTraces) { |
|
357 |
clearStackTraces(e); |
|
358 |
} |
|
359 |
out.writeObject(e); |
|
360 |
} finally { |
|
361 |
call.releaseInputStream(); // in case skeleton doesn't |
|
362 |
call.releaseOutputStream(); |
|
363 |
} |
|
364 |
} |
|
365 |
||
366 |
protected void unmarshalCustomCallData(ObjectInput in) |
|
367 |
throws IOException, ClassNotFoundException |
|
368 |
{} |
|
369 |
||
370 |
/** |
|
371 |
* Handle server-side dispatch using the RMI 1.1 stub/skeleton |
|
372 |
* protocol, given a non-negative operation number that has |
|
373 |
* already been read from the call stream. |
|
374 |
* |
|
375 |
* @param obj the target remote object for the call |
|
376 |
* @param call the "remote call" from which operation and |
|
377 |
* method arguments can be obtained. |
|
378 |
* @param op the operation number |
|
379 |
* @exception IOException if unable to marshal return result or |
|
380 |
* release input or output streams |
|
381 |
*/ |
|
382 |
public void oldDispatch(Remote obj, RemoteCall call, int op) |
|
383 |
throws IOException |
|
384 |
{ |
|
385 |
long hash; // hash for matching stub with skeleton |
|
386 |
||
387 |
try { |
|
388 |
// read remote call header |
|
389 |
ObjectInput in; |
|
390 |
try { |
|
391 |
in = call.getInputStream(); |
|
10912 | 392 |
try { |
393 |
Class<?> clazz = Class.forName("sun.rmi.transport.DGCImpl_Skel"); |
|
394 |
if (clazz.isAssignableFrom(skel.getClass())) { |
|
395 |
((MarshalInputStream)in).useCodebaseOnly(); |
|
396 |
} |
|
397 |
} catch (ClassNotFoundException ignore) { } |
|
2 | 398 |
hash = in.readLong(); |
399 |
} catch (Exception readEx) { |
|
400 |
throw new UnmarshalException("error unmarshalling call header", |
|
401 |
readEx); |
|
402 |
} |
|
403 |
||
404 |
// if calls are being logged, write out object id and operation |
|
405 |
logCall(obj, skel.getOperations()[op]); |
|
406 |
unmarshalCustomCallData(in); |
|
407 |
// dispatch to skeleton for remote object |
|
408 |
skel.dispatch(obj, call, op, hash); |
|
409 |
||
410 |
} catch (Throwable e) { |
|
411 |
logCallException(e); |
|
412 |
||
413 |
ObjectOutput out = call.getResultStream(false); |
|
414 |
if (e instanceof Error) { |
|
415 |
e = new ServerError( |
|
416 |
"Error occurred in server thread", (Error) e); |
|
417 |
} else if (e instanceof RemoteException) { |
|
418 |
e = new ServerException( |
|
419 |
"RemoteException occurred in server thread", |
|
420 |
(Exception) e); |
|
421 |
} |
|
422 |
if (suppressStackTraces) { |
|
423 |
clearStackTraces(e); |
|
424 |
} |
|
425 |
out.writeObject(e); |
|
426 |
} finally { |
|
427 |
call.releaseInputStream(); // in case skeleton doesn't |
|
428 |
call.releaseOutputStream(); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
/** |
|
433 |
* Clear the stack trace of the given Throwable by replacing it with |
|
434 |
* an empty StackTraceElement array, and do the same for all of its |
|
435 |
* chained causative exceptions. |
|
436 |
*/ |
|
437 |
public static void clearStackTraces(Throwable t) { |
|
438 |
StackTraceElement[] empty = new StackTraceElement[0]; |
|
439 |
while (t != null) { |
|
440 |
t.setStackTrace(empty); |
|
441 |
t = t.getCause(); |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
/** |
|
446 |
* Log the details of an incoming call. The method parameter is either of |
|
447 |
* type java.lang.reflect.Method or java.rmi.server.Operation. |
|
448 |
*/ |
|
449 |
private void logCall(Remote obj, Object method) { |
|
450 |
if (callLog.isLoggable(Log.VERBOSE)) { |
|
451 |
String clientHost; |
|
452 |
try { |
|
453 |
clientHost = getClientHost(); |
|
454 |
} catch (ServerNotActiveException snae) { |
|
455 |
clientHost = "(local)"; // shouldn't happen |
|
456 |
} |
|
457 |
callLog.log(Log.VERBOSE, "[" + clientHost + ": " + |
|
458 |
obj.getClass().getName() + |
|
459 |
ref.getObjID().toString() + ": " + |
|
460 |
method + "]"); |
|
461 |
} |
|
462 |
} |
|
463 |
||
464 |
/** |
|
465 |
* Log the exception detail of an incoming call. |
|
466 |
*/ |
|
467 |
private void logCallException(Throwable e) { |
|
468 |
// if calls are being logged, log them |
|
469 |
if (callLog.isLoggable(Log.BRIEF)) { |
|
470 |
String clientHost = ""; |
|
471 |
try { |
|
472 |
clientHost = "[" + getClientHost() + "] "; |
|
473 |
} catch (ServerNotActiveException snae) { |
|
474 |
} |
|
475 |
callLog.log(Log.BRIEF, clientHost + "exception: ", e); |
|
476 |
} |
|
477 |
||
478 |
// write exceptions (only) to System.err if desired |
|
479 |
if (wantExceptionLog) { |
|
480 |
java.io.PrintStream log = System.err; |
|
481 |
synchronized (log) { |
|
482 |
log.println(); |
|
483 |
log.println("Exception dispatching call to " + |
|
484 |
ref.getObjID() + " in thread \"" + |
|
485 |
Thread.currentThread().getName() + |
|
486 |
"\" at " + (new Date()) + ":"); |
|
487 |
e.printStackTrace(log); |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
491 |
||
492 |
/** |
|
493 |
* Returns the class of the ref type to be serialized. |
|
494 |
*/ |
|
495 |
public String getRefClass(ObjectOutput out) { |
|
496 |
return "UnicastServerRef"; |
|
497 |
} |
|
498 |
||
499 |
/** |
|
500 |
* Return the client remote reference for this remoteRef. |
|
501 |
* In the case of a client RemoteRef "this" is the answer. |
|
502 |
* For a server remote reference, a client side one will have to |
|
503 |
* found or created. |
|
504 |
*/ |
|
505 |
protected RemoteRef getClientRef() { |
|
506 |
return new UnicastRef(ref); |
|
507 |
} |
|
508 |
||
509 |
/** |
|
510 |
* Write out external representation for remote ref. |
|
511 |
*/ |
|
512 |
public void writeExternal(ObjectOutput out) throws IOException { |
|
513 |
} |
|
514 |
||
515 |
/** |
|
516 |
* Read in external representation for remote ref. |
|
517 |
* @exception ClassNotFoundException If the class for an object |
|
518 |
* being restored cannot be found. |
|
519 |
*/ |
|
520 |
public void readExternal(ObjectInput in) |
|
521 |
throws IOException, ClassNotFoundException |
|
522 |
{ |
|
523 |
// object is re-exported elsewhere (e.g., by UnicastRemoteObject) |
|
524 |
ref = null; |
|
525 |
skel = null; |
|
526 |
} |
|
527 |
||
528 |
||
529 |
/** |
|
530 |
* A weak hash map, mapping classes to hash maps that map method |
|
531 |
* hashes to method objects. |
|
532 |
**/ |
|
533 |
private static class HashToMethod_Maps |
|
534 |
extends WeakClassHashMap<Map<Long,Method>> |
|
535 |
{ |
|
536 |
HashToMethod_Maps() {} |
|
537 |
||
538 |
protected Map<Long,Method> computeValue(Class<?> remoteClass) { |
|
12040
558b0e0d5910
7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents:
10912
diff
changeset
|
539 |
Map<Long,Method> map = new HashMap<>(); |
2 | 540 |
for (Class<?> cl = remoteClass; |
541 |
cl != null; |
|
542 |
cl = cl.getSuperclass()) |
|
543 |
{ |
|
544 |
for (Class<?> intf : cl.getInterfaces()) { |
|
545 |
if (Remote.class.isAssignableFrom(intf)) { |
|
546 |
for (Method method : intf.getMethods()) { |
|
547 |
final Method m = method; |
|
548 |
/* |
|
549 |
* Set this Method object to override language |
|
550 |
* access checks so that the dispatcher can invoke |
|
551 |
* methods from non-public remote interfaces. |
|
552 |
*/ |
|
553 |
AccessController.doPrivileged( |
|
554 |
new PrivilegedAction<Void>() { |
|
555 |
public Void run() { |
|
556 |
m.setAccessible(true); |
|
557 |
return null; |
|
558 |
} |
|
559 |
}); |
|
560 |
map.put(Util.computeMethodHash(m), m); |
|
561 |
} |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
565 |
return map; |
|
566 |
} |
|
567 |
} |
|
568 |
} |