public abstract class SafeRemoteProxy extends Object implements InvocationHandler
One use of Proxies is to implement remote method calls. You can use Vm.getRemoteProxyMaker() to get an IRemoteProxyMaker object which will create a proxy object that implements methods by making calls across a specified communication line. However if there is a problem with the communication channel, the proxy returned by IRemoteProxyMaker will fail by throwing a RemoteMethodException and thereafter it may not be possible to do further calls using the proxy.
This class provides a way of recovering from such an error. This class is used to wrap a proxy such that a RemoteMethodException triggers a call to the abstract method handleRemoteMethodException(). That method should attempt to re-establish a connection and then create a new proxy to be used instead of the original. The method call is then attempted again on that new proxy and normal operation continues.
Each instance of RemoteProxy can only handle a single proxy, so you should create a new one for each proxy created.
Modifier and Type | Field and Description |
---|---|
protected Class[] |
interfaces
The classes implemented by the proxy.
|
protected Object |
originalProxy
The original or current external proxy being used.
|
protected ClassLoader |
proxyClassLoader
If you are using the createProxy() method, this is the ClassLoader
that is used to create the proxy.
|
Modifier | Constructor and Description |
---|---|
protected |
SafeRemoteProxy(Object createdProxy,
Class implementedInterface)
A simpler way to crete a RemoteProxy.
|
protected |
SafeRemoteProxy(Object createdProxy,
Class[] interfaces,
ClassLoader proxyClassLoader)
Create a RemoteProxy.
|
Modifier and Type | Method and Description |
---|---|
Object |
createProxy()
Create and return the proxy that implements the same intefaces as the original
proxy.
|
protected abstract Object |
handleRemoteMethodException(Method method,
RemoteMethodException thrown,
int numberOfFailures)
If the remote proxy that was provided should throw a RemoteMethodException
when a method is called then this method is called.
|
Object |
invoke(Object proxy,
Method method,
Object[] args) |
protected Object originalProxy
protected Class[] interfaces
protected ClassLoader proxyClassLoader
protected SafeRemoteProxy(Object createdProxy, Class[] interfaces, ClassLoader proxyClassLoader)
createdProxy
- a proxy object that has already been created.interfaces
- the list of interfaces implemented by the proxy.proxyClassLoader
- an optional ClassLoader to be used with proxy creation.public Object createProxy()
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke
in interface InvocationHandler
Throwable
protected abstract Object handleRemoteMethodException(Method method, RemoteMethodException thrown, int numberOfFailures)
method
- the method that was being invoked when the RemoteMethodException
occured.thrown
- the RemoteMethodException that was thrown when the method
was called.numberOfFailures
- the number of times the method call has failed
consecutively.