org.softamis.cluster4spring.support.provider
Class AbstractUrlListEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>

java.lang.Object
  extended by org.softamis.cluster4spring.support.provider.BaseEndpointProvider<E,SI>
      extended by org.softamis.cluster4spring.support.provider.MultiURLEndpointProvider<E,SI>
          extended by org.softamis.cluster4spring.support.provider.AbstractUrlListEndpointProvider<E,SI>
Type Parameters:
SI - type of data used to invoke remote service (such as remote service URL)
E - type of endpoints that could be created by this factory
All Implemented Interfaces:
EndpointProvider<E,SI>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
AbstractDiscoveringEndpointProvider, UrlListEndpointProvider

public abstract class AbstractUrlListEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
extends MultiURLEndpointProvider<E,SI>

Base abstract class to implement endpoint providers which provide endpoints based on list of endpoints available for service and which maintains internal cache of discovered endpoints.

Author:
Andrew Sazonov

Field Summary
protected  java.lang.Object fCacheLock
          Object used as lock to access cache of endpoints
protected  java.util.List<E> fEndpointsCache
          List which contains discovered endpoints
protected static org.apache.commons.logging.Log fLog
           
 
Fields inherited from class org.softamis.cluster4spring.support.provider.MultiURLEndpointProvider
fEndpointSelectionPolicy
 
Fields inherited from class org.softamis.cluster4spring.support.provider.BaseEndpointProvider
fCacheEndpoints
 
Constructor Summary
protected AbstractUrlListEndpointProvider()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by Spring as part of bean lifecycle.
protected  java.util.List<E> doGetCachedEndpoints()
          Utility method to obtain list of enpoints from cache.
protected abstract  java.util.List<E> doRefreshServiceEndpointsList(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory, EndpointFactory<E,SI> aEndpointFactory, java.lang.String aBeanName)
          Creates list of endpoints available for service.
protected  java.util.List<E> getCachedEndpoints(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory, EndpointFactory<E,SI> aEndpointFactory, java.lang.String aBeanName)
          Obtains endpoints from endpoints cache.
protected  java.util.List<E> getServiceEndpointsList(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory, EndpointFactory<E,SI> aEndpointFactory, java.lang.String aBeanName)
          Performs actual obtaining of list of available endpoints.
 void refresh(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory, EndpointFactory<E,SI> aEndpointFactory, java.lang.String aBeanName)
          Refreshes internal state of provider.
protected  void saveFreshEndpointsToCache(java.util.List<E> aEndpoints)
          Save obtained endpoints to endpoints cache.
 
Methods inherited from class org.softamis.cluster4spring.support.provider.MultiURLEndpointProvider
createDefaultEndpointSelectionPolicy, getEndpoint, setEndpointSelectionPolicy
 
Methods inherited from class org.softamis.cluster4spring.support.provider.BaseEndpointProvider
doCreateServiceEndpoint, isCacheEndpoints, setCacheEndpoints
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.softamis.cluster4spring.support.EndpointProvider
markInvalid
 

Field Detail

fLog

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

fEndpointsCache

protected java.util.List<E extends Endpoint<SI>> fEndpointsCache
List which contains discovered endpoints


fCacheLock

protected final java.lang.Object fCacheLock
Object used as lock to access cache of endpoints

Constructor Detail

AbstractUrlListEndpointProvider

protected AbstractUrlListEndpointProvider()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Description copied from class: MultiURLEndpointProvider
Invoked by Spring as part of bean lifecycle. Used to check whether endpoints selection policy is specified during bean configuration. If one is not specified, default endpoints selection policy is created.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Overrides:
afterPropertiesSet in class MultiURLEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Throws:
java.lang.Exception
See Also:
MultiURLEndpointProvider.createDefaultEndpointSelectionPolicy()

refresh

public void refresh(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory,
                    EndpointFactory<E,SI> aEndpointFactory,
                    java.lang.String aBeanName)
             throws org.springframework.remoting.RemoteAccessException
Refreshes internal state of provider. If configured to cache endpoints, tries to obtain list of endpoints available and saves it to cache. Otherwise, silently does nothing since endpoint list will be obtained by request.

Parameters:
aRemoteInvocationFactory - factory used to create remote invocation
aEndpointFactory - factory used to create endpoints
aBeanName - name of bean that is used as proxy for remote service
Throws:
org.springframework.remoting.RemoteAccessException - throw if exception occured during refreshing

getServiceEndpointsList

protected java.util.List<E> getServiceEndpointsList(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory,
                                                    EndpointFactory<E,SI> aEndpointFactory,
                                                    java.lang.String aBeanName)
                                                                  throws org.springframework.remoting.RemoteAccessException
Performs actual obtaining of list of available endpoints. If configured to cache endpoints, tries to provide endpoints from the endpoints cache. Otherwise, tries to create available endpoints.

Specified by:
getServiceEndpointsList in class MultiURLEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Parameters:
aRemoteInvocationFactory - factory used for remote invocation
aEndpointFactory - factory used for endpoints creation
aBeanName -
Returns:
list of endpoints available for service
Throws:
org.springframework.remoting.RemoteAccessException
See Also:
BaseEndpointProvider.setCacheEndpoints(boolean)

getCachedEndpoints

protected java.util.List<E> getCachedEndpoints(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory,
                                               EndpointFactory<E,SI> aEndpointFactory,
                                               java.lang.String aBeanName)
Obtains endpoints from endpoints cache. If endpoints cache is null (i.e there were no endpoints stored there), tries to perform refresh.

Parameters:
aRemoteInvocationFactory - factory to create remote invocations
aEndpointFactory - factory used to create endpoints
aBeanName -
Returns:
list of endpoints

doGetCachedEndpoints

protected java.util.List<E> doGetCachedEndpoints()
Utility method to obtain list of enpoints from cache. Includes synchronization related code.

Returns:
list of cached endpoints

saveFreshEndpointsToCache

protected void saveFreshEndpointsToCache(java.util.List<E> aEndpoints)
Save obtained endpoints to endpoints cache.

Parameters:
aEndpoints - list of endpoints to store in cache

doRefreshServiceEndpointsList

protected abstract java.util.List<E> doRefreshServiceEndpointsList(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory,
                                                                   EndpointFactory<E,SI> aEndpointFactory,
                                                                   java.lang.String aBeanName)
                                                                                 throws org.springframework.remoting.RemoteAccessException
Creates list of endpoints available for service. Inherited classes will override it to provide specific implementation.

Parameters:
aRemoteInvocationFactory - factory used to create remote invocation
aEndpointFactory - factory used to create endpoints
aBeanName -
Returns:
list of created endpoints
Throws:
org.springframework.remoting.RemoteAccessException - throws if list of endpoints could not be created