org.softamis.cluster4spring.support
Class Endpoint<SI extends java.io.Serializable>

java.lang.Object
  extended by org.softamis.cluster4spring.support.Endpoint<SI>
Type Parameters:
SI - type of data used to invoke remote service (such as remote service URL)
Direct Known Subclasses:
RmiEndpoint

public abstract class Endpoint<SI extends java.io.Serializable>
extends java.lang.Object

Abstract class that encapsulates low-level logic of calling underlying remote service. Roughly speaking, it could be considered as client-side proxy for remote server-side service. An appropriate type of endpoints should be implemented for every corresponging cluster4spring protocol.

Instance of this class is created by appropriate ProxyFactoryBean which is used to create proxies to remote service.

Author:
Andrew Sazonov

Field Summary
protected  java.util.Map<java.lang.String,java.lang.Object> fAttributes
          Custom data which could be associated with endpoint.
protected  java.lang.String fEndpointKey
          Key used to identify endpoint
protected  long fLastAccessTime
          Time of last invocation of remote service via this endpoint
protected static org.apache.commons.logging.Log fLog
           
protected  org.springframework.remoting.support.RemoteInvocationFactory fRemoteInvocationFactory
          Factory used to create remote invocations
protected  SI fServiceInfo
          information about remote service (for example, URL of remote service)
 
Constructor Summary
protected Endpoint(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory)
          Creates endpoint.
protected Endpoint(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory, java.lang.String aEndpointKey, SI aServiceInfo)
          Creates endpoint.
 
Method Summary
protected  org.springframework.remoting.support.RemoteInvocation createRemoteInvocation(org.aopalliance.intercept.MethodInvocation aMethodInvocation)
          Create a new RemoteInvocation object for the given AOP method invocation.
protected abstract  java.lang.Object doInvoke(org.aopalliance.intercept.MethodInvocation aMethodInvocation)
          Perform invocation of given MethoInvocation taking into consideration details of concrete cluster4spring protocol.
 java.util.Map<java.lang.String,java.lang.Object> getAttributes()
          Returns custom attributes which could be associated with endpoint.
 java.lang.String getEndpointKey()
          Returns key for endpoint
 long getLastAccessTime()
          Returns time of last invocation of remote service via this endpoint.
 SI getServiceInfo()
          Returns information about remote service (for example, URL of remote service)
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation aMethodInvocation)
          Performs invocation of given MethodInvocation.
 void setAttributes(java.util.Map<java.lang.String,java.lang.Object> aAttributes)
          Sets custom attributes which could be associated with endpoint.
 void setEndpointKey(java.lang.String aEndpointKey)
          Sets key for endpoint
 void setLastAccessTime(long aLastAccessTime)
          Sets time of last invocation of remote service via this endpoint
 
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

fEndpointKey

protected java.lang.String fEndpointKey
Key used to identify endpoint


fServiceInfo

protected SI extends java.io.Serializable fServiceInfo
information about remote service (for example, URL of remote service)


fAttributes

protected java.util.Map<java.lang.String,java.lang.Object> fAttributes
Custom data which could be associated with endpoint. Such a custom data could be used, for example, by EndpointSelectionPolicy


fRemoteInvocationFactory

protected org.springframework.remoting.support.RemoteInvocationFactory fRemoteInvocationFactory
Factory used to create remote invocations


fLastAccessTime

protected long fLastAccessTime
Time of last invocation of remote service via this endpoint

Constructor Detail

Endpoint

protected Endpoint(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory)
Creates endpoint.

Parameters:
aRemoteInvocationFactory - factory used to create remote invocations

Endpoint

protected Endpoint(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory,
                   java.lang.String aEndpointKey,
                   SI aServiceInfo)
Creates endpoint.

Parameters:
aRemoteInvocationFactory - factory used to create remote invocations
aEndpointKey - key of endpoint
aServiceInfo - information about service that could be used to perform service invocation
Method Detail

invoke

public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation aMethodInvocation)
                        throws java.lang.Throwable
Performs invocation of given MethodInvocation. After invocation, updates
lastAccessTime of endpoint.

Parameters:
aMethodInvocation - method invocation to invoke
Returns:
object which represents result of method invocation
Throws:
java.lang.Throwable

doInvoke

protected abstract java.lang.Object doInvoke(org.aopalliance.intercept.MethodInvocation aMethodInvocation)
                                      throws java.lang.Throwable
Perform invocation of given MethoInvocation taking into consideration details of concrete cluster4spring protocol. This method should be implemented for particular remote protocol impl.

Parameters:
aMethodInvocation - method invocation to invoke
Returns:
result of invocation, if any
Throws:
java.lang.Throwable - exception that could occur during invocation

getAttributes

public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Returns custom attributes which could be associated with endpoint. Such a custom data could be used, for example, by EndpointSelectionPolicy to implement algorithm of endpoints selection

Returns:
custom data

setAttributes

public void setAttributes(java.util.Map<java.lang.String,java.lang.Object> aAttributes)
Sets custom attributes which could be associated with endpoint.

Parameters:
aAttributes - custom data

createRemoteInvocation

protected org.springframework.remoting.support.RemoteInvocation createRemoteInvocation(org.aopalliance.intercept.MethodInvocation aMethodInvocation)
Create a new RemoteInvocation object for the given AOP method invocation. The default implementation delegates to the RemoteInvocationFactory.

Can be overridden in subclasses to provide custom RemoteInvocation subclasses, containing additional invocation parameters like user credentials. Note that it is preferable to use a custom RemoteInvocationFactory which is a reusable strategy.

Parameters:
aMethodInvocation - the current AOP method invocation
Returns:
the RemoteInvocation object
See Also:
RemoteInvocationFactory.createRemoteInvocation(org.aopalliance.intercept.MethodInvocation)

getServiceInfo

public SI getServiceInfo()
Returns information about remote service (for example, URL of remote service)

Returns:
information about remote service

getLastAccessTime

public long getLastAccessTime()
Returns time of last invocation of remote service via this endpoint. This time could be used for statistical purposes and also for selection of particular endpoint if there are serveral ones exists for the same remote service.

Returns:
time of last invocation of remote service via this endpoint
See Also:
LastAccessTimeEndpointSelectionPolicy

setLastAccessTime

public void setLastAccessTime(long aLastAccessTime)
Sets time of last invocation of remote service via this endpoint

Parameters:
aLastAccessTime - time

getEndpointKey

public java.lang.String getEndpointKey()
Returns key for endpoint

Returns:
key for endpoint

setEndpointKey

public void setEndpointKey(java.lang.String aEndpointKey)
Sets key for endpoint

Parameters:
aEndpointKey - key for endpoint