APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.rmi.server

public Class RemoteObjectInvocationHandler

extends RemoteObject
implements InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler
Imports
java.io.InvalidObjectException, java.lang.reflect.InvocationHandler, .Method, .Proxy, java.rmi.Remote, .RemoteException, .UnexpectedException, java.util.Map, .WeakHashMap, sun.rmi.server.Util, .WeakClassHashMap

An implementation of the InvocationHandler interface for use with Java Remote Method Invocation (Java RMI). This invocation handler can be used in conjunction with a dynamic proxy instance as a replacement for a pregenerated stub class.

Applications are not expected to use this class directly. A remote object exported to use a dynamic proxy with UnicastRemoteObject has an instance of this class as that proxy's invocation handler.

Author
Ann Wollrath
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
RemoteObjectInvocationHandler.MethodToHash_Maps

A weak hash map, mapping classes to weak hash maps that map method objects to method hashes.

Field Summary

Modifier and TypeField and Description
private static final RemoteObjectInvocationHandler.MethodToHash_Maps
methodToHash_Maps

A weak hash map, mapping classes to weak hash maps that map method objects to method hashes.

private static final long
Inherited from java.rmi.server.RemoteObject:
ref

Constructor Summary

AccessConstructor and Description
public
RemoteObjectInvocationHandler(RemoteRef
the remote ref
ref
)

Creates a new RemoteObjectInvocationHandler constructed with the specified RemoteRef.

Method Summary

Modifier and TypeMethod and Description
private static long

Returns:

the method hash for the specified method
getMethodHash
(Method
the remote method
method
)

Returns the method hash for the specified method.

public Object

Returns:

the value to return from the method invocation on the proxy instance
invoke
(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if the method takes no arguments
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation made on the encapsulating proxy instance, proxy, and returns the result.

private Object
invokeObjectMethod(Object proxy, Method method, Object[] args)

Handles java.lang.Object methods.

private Object
invokeRemoteMethod(Object proxy, Method method, Object[] args)

Handles remote methods.

private String
proxyToString(Object proxy)

Returns a string representation for a proxy that uses this invocation handler.

private void
Inherited from java.rmi.server.RemoteObject:
equalsgetRefhashCodetoStringtoStub

Field Detail

methodToHash_Mapsback to summary
private static final RemoteObjectInvocationHandler.MethodToHash_Maps methodToHash_Maps

A weak hash map, mapping classes to weak hash maps that map method objects to method hashes.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.rmi.server.RemoteObject.serialVersionUID.

Constructor Detail

RemoteObjectInvocationHandlerback to summary
public RemoteObjectInvocationHandler(RemoteRef ref)

Creates a new RemoteObjectInvocationHandler constructed with the specified RemoteRef.

Parameters
ref:RemoteRef

the remote ref

Exceptions
NullPointerException:
if ref is null

Method Detail

getMethodHashback to summary
private static long getMethodHash(Method method)

Returns the method hash for the specified method. Subsequent calls to "getMethodHash" passing the same method argument should be faster since this method caches internally the result of the method to method hash mapping. The method hash is calculated using the "computeMethodHash" method.

Parameters
method:Method

the remote method

Returns:long

the method hash for the specified method

invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation made on the encapsulating proxy instance, proxy, and returns the result.

RemoteObjectInvocationHandler implements this method as follows:

If method is one of the following methods, it is processed as described below:

  • Object.hashCode: Returns the hash code value for the proxy.
  • Object.equals: Returns true if the argument (args[0]) is an instance of a dynamic proxy class and this invocation handler is equal to the invocation handler of that argument, and returns false otherwise.
  • Object.toString: Returns a string representation of the proxy.

If method overrides Object.finalize, it is ignored.

Otherwise, a remote call is made as follows:

  • If proxy is not an instance of the interface Remote, then an IllegalArgumentException is thrown.
  • Otherwise, the invoke method is invoked on this invocation handler's RemoteRef, passing proxy, method, args, and the method hash (defined in section 8.3 of the "Java Remote Method Invocation (RMI) Specification") for method, and the result is returned.
  • If an exception is thrown by RemoteRef.invoke and that exception is a checked exception that is not assignable to any exception in the throws clause of the method implemented by the proxy's class, then that exception is wrapped in an UnexpectedException and the wrapped exception is thrown. Otherwise, the exception thrown by invoke is thrown by this method.

The semantics of this method are unspecified if the arguments could not have been produced by an instance of some valid dynamic proxy class containing this invocation handler.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if the method takes no arguments

Returns:Object

the value to return from the method invocation on the proxy instance

Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance
invokeObjectMethodback to summary
private Object invokeObjectMethod(Object proxy, Method method, Object[] args)

Handles java.lang.Object methods.

invokeRemoteMethodback to summary
private Object invokeRemoteMethod(Object proxy, Method method, Object[] args) throws Exception

Handles remote methods.

proxyToStringback to summary
private String proxyToString(Object proxy)

Returns a string representation for a proxy that uses this invocation handler.

readObjectNoDataback to summary
private void readObjectNoData() throws InvalidObjectException
Exceptions
InvalidObjectException:
unconditionally
java.rmi.server back to summary

private Class RemoteObjectInvocationHandler.MethodToHash_Maps

extends WeakClassHashMap<Map<Method, Long>>
Class Inheritance

A weak hash map, mapping classes to weak hash maps that map method objects to method hashes.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected Map<Method, Long>
Inherited from sun.rmi.server.WeakClassHashMap:
get

Constructor Detail

MethodToHash_Mapsback to summary
pack-priv MethodToHash_Maps()

Method Detail

computeValueback to summary
protected Map<Method, Long> computeValue(Class<?> remoteClass)

Implements abstract sun.rmi.server.WeakClassHashMap.computeValue.