org.softamis.cluster4spring.rmi.support
Class RmiClientInterceptor<SI extends ServiceMoniker>

java.lang.Object
  extended by org.springframework.remoting.support.RemoteAccessor
      extended by org.softamis.cluster4spring.support.RemoteInvocationBasedAccessor
          extended by org.softamis.cluster4spring.support.RemoteClientInterceptor<RmiEndpoint<SI>,SI>
              extended by org.softamis.cluster4spring.rmi.support.RmiClientInterceptor<SI>
Type Parameters:
SI - type of data used to invoke remote service (such as remote service URL)
All Implemented Interfaces:
java.util.EventListener, org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationListener
Direct Known Subclasses:
AbstractRmiProxyFactoryBean

public class RmiClientInterceptor<SI extends ServiceMoniker>
extends RemoteClientInterceptor<RmiEndpoint<SI>,SI>

Interceptor for accessing remote services via RMI. Adds processing or RMI specific exceptions in doInvoke method.

Author:
Andrew Sazonov

Field Summary
protected static org.apache.commons.logging.Log fLog
           
static java.lang.String PROTOCOL_RMI
           
 
Fields inherited from class org.softamis.cluster4spring.support.RemoteClientInterceptor
fBeanName, fEndpointFactory, fEndpointProvider, fRefreshEndpointsOnConnectFailure, fRefreshEndpointsOnStartup, fSwitchEndpointOnFailure
 
Fields inherited from class org.softamis.cluster4spring.support.RemoteInvocationBasedAccessor
fRemoteInvocationFactory
 
Fields inherited from class org.springframework.remoting.support.RemoteAccessor
logger
 
Constructor Summary
RmiClientInterceptor()
           
 
Method Summary
protected  java.lang.Exception convertRmiAccessException(java.lang.reflect.Method aMethod, java.rmi.RemoteException aRemoteException, boolean aConnectFailure, SI aServiceInfo)
          Utility method used to convert remote exception to corresponding RemoteAccessException
protected  EndpointFactory<RmiEndpoint<SI>,SI> createDefaultEndpointFactory()
          Creates default endpoint factory used to create RMI endpoints.
protected  java.lang.Object doInvoke(org.aopalliance.intercept.MethodInvocation aInvocation, RmiEndpoint<SI> aServiceEndpoint)
          Perform the given aInvocation on the given RMI aStub.
protected  java.lang.String getProtocol()
          Returns protocol which identifies interceptor.
protected  boolean isConnectFailure(org.springframework.remoting.RemoteAccessException aException)
          Determine whether the given RMI exception indicates a connect failure.
protected  boolean isConnectFailureOnRemoteException(java.rmi.RemoteException aRemoteException)
          Utility method to definie whether given remote excption indicates a connect failure.
protected  void throwRmiAccessException(org.aopalliance.intercept.MethodInvocation aInvocation, java.rmi.RemoteException aRemoteException, RmiEndpoint<SI> aServiceEndpoint)
          Utility method to throw RmiAccessException Utility method to throw RmiAccessException
 
Methods inherited from class org.softamis.cluster4spring.support.RemoteClientInterceptor
afterPropertiesSet, doInvoke, doPreprocessApplicationEvent, getBeanName, getEndpointFactory, handleRemoteConnectFailure, invoke, isRefreshEndpointsOnConnectFailure, isRefreshEndpointsOnStartup, isSwitchEndpointOnFailure, markServiceInvalid, obtainEndpointToExecute, onApplicationEvent, onContextClosed, onContextRefreshed, prepare, refreshAndRetry, refreshEndpointProvider, retry, setBeanName, setEndpointFactory, setEndpointProvider, setRefreshEndpointsOnConnectFailure, setRefreshEndpointsOnStartup, setSwitchEndpointOnFailure, throwRemoteLookupFailureException, throwServiceException
 
Methods inherited from class org.softamis.cluster4spring.support.RemoteInvocationBasedAccessor
getRemoteInvocationFactory, setRemoteInvocationFactory
 
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
 

Field Detail

fLog

protected static final org.apache.commons.logging.Log fLog

PROTOCOL_RMI

public static final java.lang.String PROTOCOL_RMI
See Also:
Constant Field Values
Constructor Detail

RmiClientInterceptor

public RmiClientInterceptor()
Method Detail

getProtocol

protected java.lang.String getProtocol()
Returns protocol which identifies interceptor. Used for logging.

Specified by:
getProtocol in class RemoteClientInterceptor<RmiEndpoint<SI extends ServiceMoniker>,SI extends ServiceMoniker>
Returns:
protocol name

createDefaultEndpointFactory

protected EndpointFactory<RmiEndpoint<SI>,SI> createDefaultEndpointFactory()
Creates default endpoint factory used to create RMI endpoints.

Specified by:
createDefaultEndpointFactory in class RemoteClientInterceptor<RmiEndpoint<SI extends ServiceMoniker>,SI extends ServiceMoniker>
Returns:
EndpointFactory that should be used if one is is not specified explicitely
See Also:
RmiEndpointFactory

isConnectFailure

protected boolean isConnectFailure(org.springframework.remoting.RemoteAccessException aException)
Determine whether the given RMI exception indicates a connect failure.

Specified by:
isConnectFailure in class RemoteClientInterceptor<RmiEndpoint<SI extends ServiceMoniker>,SI extends ServiceMoniker>
Parameters:
aException - the RMI exception to check
Returns:
whether the exception should be treated as connect failure
See Also:
RmiClientInterceptorUtils.isConnectFailure(java.rmi.RemoteException)

isConnectFailureOnRemoteException

protected boolean isConnectFailureOnRemoteException(java.rmi.RemoteException aRemoteException)
Utility method to definie whether given remote excption indicates a connect failure. Default implementation delegates to RmiClientInterceptorUtils.

Parameters:
aRemoteException - exception to inspect
Returns:
true if given exception indicates a connect failure

doInvoke

protected java.lang.Object doInvoke(org.aopalliance.intercept.MethodInvocation aInvocation,
                                    RmiEndpoint<SI> aServiceEndpoint)
                             throws java.lang.Throwable
Perform the given aInvocation on the given RMI aStub.

Specified by:
doInvoke in class RemoteClientInterceptor<RmiEndpoint<SI extends ServiceMoniker>,SI extends ServiceMoniker>
Parameters:
aInvocation - the AOP method aInvocation
aServiceEndpoint - the RMI aStub to invoke
Returns:
the aInvocation result, if any
Throws:
java.lang.Throwable - in case of aInvocation failure

throwRmiAccessException

protected void throwRmiAccessException(org.aopalliance.intercept.MethodInvocation aInvocation,
                                       java.rmi.RemoteException aRemoteException,
                                       RmiEndpoint<SI> aServiceEndpoint)
                                throws java.lang.Exception
Utility method to throw RmiAccessException Utility method to throw RmiAccessException

Parameters:
aInvocation -
aRemoteException -
aServiceEndpoint -
Throws:
java.lang.Exception

convertRmiAccessException

protected java.lang.Exception convertRmiAccessException(java.lang.reflect.Method aMethod,
                                                        java.rmi.RemoteException aRemoteException,
                                                        boolean aConnectFailure,
                                                        SI aServiceInfo)
Utility method used to convert remote exception to corresponding RemoteAccessException

Parameters:
aMethod - methods that threw exception
aRemoteException - remote exception
aConnectFailure - true if exception is connect failure
aServiceInfo - information about service url where remote exception occured
Returns:
appropriate conferted exception