RemoteObjectInvocationHandler (Java Platform SE 8 ) (original) (raw)
- java.rmi.server.RemoteObject
- java.rmi.server.RemoteObjectInvocationHandler
All Implemented Interfaces:
Serializable, InvocationHandler, Remote
public class RemoteObjectInvocationHandler
extends RemoteObject
implements InvocationHandler
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 or Activatable has an instance of this class as that proxy's invocation handler.
Since:
1.5
See Also:
Serialized Form
Field Summary
* ### Fields inherited from class java.rmi.server.[RemoteObject](../../../java/rmi/server/RemoteObject.html "class in java.rmi.server") `[ref](../../../java/rmi/server/RemoteObject.html#ref)`
Constructor Summary
Constructors
Constructor Description RemoteObjectInvocationHandler(RemoteRef ref) Creates a new RemoteObjectInvocationHandler constructed with the specified RemoteRef. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description Object invoke(Object proxy,Method method,Object[] args) Processes a method invocation made on the encapsulating proxy instance, proxy, and returns the result. * ### Methods inherited from class java.rmi.server.[RemoteObject](../../../java/rmi/server/RemoteObject.html "class in java.rmi.server") `[equals](../../../java/rmi/server/RemoteObject.html#equals-java.lang.Object-), [getRef](../../../java/rmi/server/RemoteObject.html#getRef--), [hashCode](../../../java/rmi/server/RemoteObject.html#hashCode--), [toString](../../../java/rmi/server/RemoteObject.html#toString--), [toStub](../../../java/rmi/server/RemoteObject.html#toStub-java.rmi.Remote-)` * ### Methods inherited from class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone--), [finalize](../../../java/lang/Object.html#finalize--), [getClass](../../../java/lang/Object.html#getClass--), [notify](../../../java/lang/Object.html#notify--), [notifyAll](../../../java/lang/Object.html#notifyAll--), [wait](../../../java/lang/Object.html#wait--), [wait](../../../java/lang/Object.html#wait-long-), [wait](../../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### RemoteObjectInvocationHandler public RemoteObjectInvocationHandler([RemoteRef](../../../java/rmi/server/RemoteRef.html "interface in java.rmi.server") ref) Creates a new `RemoteObjectInvocationHandler` constructed with the specified `RemoteRef`. Parameters: `ref` \- the remote ref Throws: `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if `ref` is `null`
Method Detail
* #### invoke public [Object](../../../java/lang/Object.html "class in java.lang") invoke([Object](../../../java/lang/Object.html "class in java.lang") proxy, [Method](../../../java/lang/reflect/Method.html "class in java.lang.reflect") method, [Object](../../../java/lang/Object.html "class in java.lang")[] args) throws [Throwable](../../../java/lang/Throwable.html "class in java.lang") 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](../../../java/lang/Object.html#hashCode--): Returns the hash code value for the proxy. * [Object.equals](../../../java/lang/Object.html#equals-java.lang.Object-): 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](../../../java/lang/Object.html#toString--): Returns a string representation of the proxy. Otherwise, a remote call is made as follows: * If `proxy` is not an instance of the interface[Remote](../../../java/rmi/Remote.html "interface in java.rmi"), then an [IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang") is thrown. * Otherwise, the [invoke](../../../java/rmi/server/RemoteRef.html#invoke-java.rmi.Remote-java.lang.reflect.Method-java.lang.Object:A-long-) 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](../../../java/rmi/UnexpectedException.html "class in java.rmi") 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. Specified by: `[invoke](../../../java/lang/reflect/InvocationHandler.html#invoke-java.lang.Object-java.lang.reflect.Method-java.lang.Object:A-)` in interface `[InvocationHandler](../../../java/lang/reflect/InvocationHandler.html "interface in java.lang.reflect")` Parameters: `proxy` \- the proxy instance that the method was invoked on `method` \- the `Method` instance corresponding to the interface method invoked on the proxy instance `args` \- 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: the value to return from the method invocation on the proxy instance Throws: `[Throwable](../../../java/lang/Throwable.html "class in java.lang")` \- the exception to throw from the method invocation on the proxy instance See Also: [UndeclaredThrowableException](../../../java/lang/reflect/UndeclaredThrowableException.html "class in java.lang.reflect")
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.