|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.remoting.support.RemoteAccessor org.springframework.remoting.support.UrlBasedRemoteAccessor org.springframework.remoting.support.RemoteInvocationBasedAccessor org.springframework.remoting.rmi.RmiClientInterceptor
Interceptor for accessing conventional RMI services or RMI invokers. The service URL must be a valid RMI URL like "rmi://localhost:1099/myservice".
RMI invokers work at the RmiInvocationHandler level, needing only one stub for any service. Service interfaces do not have to extend java.rmi.Remote or throw RemoteException; Spring's unchecked RemoteAccessException will be thrown on remote invocation failure. Of course, in and out parameters have to be serializable.
With conventional RMI services, this invoker is typically used with the RMI service interface. Alternatively, this invoker can also proxy a remote RMI service with a matching non-RMI business interface, i.e. an interface that mirrors the RMI service methods but does not declare RemoteExceptions. In the latter case, RemoteExceptions thrown by the RMI stub will automatically get converted to Spring's unchecked RemoteAccessException.
RmiServiceExporter
,
RmiProxyFactoryBean
,
RmiInvocationHandler
,
RemoteAccessException
,
RemoteException
,
Remote
Field Summary |
Fields inherited from class org.springframework.remoting.support.RemoteAccessor |
logger |
Constructor Summary | |
RmiClientInterceptor()
|
Method Summary | |
void |
afterPropertiesSet()
Fetches RMI stub on startup, if necessary. |
protected java.lang.Object |
doInvoke(org.aopalliance.intercept.MethodInvocation invocation,
java.rmi.Remote stub)
Perform the given invocation on the given RMI stub. |
protected java.lang.Object |
doInvoke(org.aopalliance.intercept.MethodInvocation methodInvocation,
RmiInvocationHandler invocationHandler)
Apply the given AOP method invocation to the given RmiInvocationHandler. |
protected java.rmi.Remote |
getStub()
Return the RMI stub to use. |
java.lang.Object |
invoke(org.aopalliance.intercept.MethodInvocation invocation)
Fetches an RMI stub and delegates to doInvoke. |
protected java.rmi.Remote |
lookupStub()
Create the RMI stub, typically by looking it up. |
protected java.lang.Object |
refreshAndRetry(org.aopalliance.intercept.MethodInvocation invocation)
Refresh the RMI stub and retry the given invocation. |
void |
setCacheStub(boolean cacheStub)
Set whether to cache the RMI stub once it has been located. |
void |
setLookupStubOnStartup(boolean lookupStubOnStartup)
Set whether to look up the RMI stub on startup. |
void |
setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)
Set whether to refresh the RMI stub on connect failure. |
Methods inherited from class org.springframework.remoting.support.RemoteInvocationBasedAccessor |
createRemoteInvocation, getRemoteInvocationFactory, setRemoteInvocationFactory |
Methods inherited from class org.springframework.remoting.support.UrlBasedRemoteAccessor |
getServiceUrl, setServiceUrl |
Methods inherited from class org.springframework.remoting.support.RemoteAccessor |
getServiceInterface, setServiceInterface |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RmiClientInterceptor()
Method Detail |
public void setLookupStubOnStartup(boolean lookupStubOnStartup)
Can be turned off to allow for late start of the RMI server. In this case, the RMI stub will be fetched on first access.
setCacheStub(boolean)
public void setCacheStub(boolean cacheStub)
Can be turned off to allow for hot restart of the RMI server. In this case, the RMI stub will be fetched for each invocation.
setLookupStubOnStartup(boolean)
public void setRefreshStubOnConnectFailure(boolean refreshStubOnConnectFailure)
Can be turned on to allow for hot restart of the RMI server. If a cached RMI stub throws a ConnectException, a fresh proxy will be fetched and the invocation will be retried.
ConnectException
public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface InitializingBean
java.lang.Exception
- in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.setLookupStubOnStartup(boolean)
,
lookupStub()
protected java.rmi.Remote lookupStub() throws java.lang.Exception
Default implementation looks up the service URL via java.rmi.Naming. Can be overridden in subclasses.
java.lang.Exception
- if proxy creation failedsetCacheStub(boolean)
,
getStub()
,
Naming.lookup(java.lang.String)
protected java.rmi.Remote getStub() throws java.lang.Exception
Default implementation returns the proxy created on initialization, if any; else, it invokes lookupStub to get a new proxy for each invocation.
Can be overridden in subclasses, for example to cache a proxy for a given amount of time before recreating it, or to test the proxy whether it is still alive.
java.lang.Exception
- if proxy creation failedlookupStub()
public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation) throws java.lang.Throwable
invoke
in interface org.aopalliance.intercept.MethodInterceptor
java.lang.Throwable
getStub()
,
doInvoke(MethodInvocation, Remote)
,
refreshAndRetry(org.aopalliance.intercept.MethodInvocation)
,
ConnectException
protected java.lang.Object refreshAndRetry(org.aopalliance.intercept.MethodInvocation invocation) throws java.lang.Throwable
invocation
- the AOP method invocation
java.lang.Throwable
- in case of invocation failureinvoke(org.aopalliance.intercept.MethodInvocation)
protected java.lang.Object doInvoke(org.aopalliance.intercept.MethodInvocation invocation, java.rmi.Remote stub) throws java.lang.Throwable
invocation
- the AOP method invocationstub
- the RMI stub to invoke
java.lang.Throwable
- in case of invocation failureprotected java.lang.Object doInvoke(org.aopalliance.intercept.MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler) throws java.rmi.RemoteException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Can be overridden in subclasses to provide custom RemoteInvocation subclasses, containing additional invocation parameters like user credentials. Can also process the returned result object.
methodInvocation
- the current AOP method invocationinvocationHandler
- the RmiInvocationHandler to apply the invocation to
java.lang.NoSuchMethodException
- if the method name could not be resolved
java.lang.IllegalAccessException
- if the method could not be accessed
java.lang.reflect.InvocationTargetException
- if the method invocation resulted in an exception
java.rmi.RemoteException
RemoteInvocation
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |