org.softamis.cluster4spring.support.provider
Class DiscoveringEndpointProvider<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>
              extended by org.softamis.cluster4spring.support.provider.AbstractDiscoveringEndpointProvider<E,SI>
                  extended by org.softamis.cluster4spring.support.provider.DiscoveringEndpointProvider<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:
java.util.EventListener, EndpointProvider<E,SI>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationListener
Direct Known Subclasses:
DiscoveringEndpointProviderEx, RmiDiscoveringEndpointProvider

public class DiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
extends AbstractDiscoveringEndpointProvider<E,SI>

Implementation of EndpointProvider that automatically discovers services based on service name and service group. Such auto-discoverable services are published via appropriate ServicePublisher. To discover urls for service, class relies on ConsumingRegistry that handles details of networking communications.

Author:
Andrew Sazonov
See Also:
ConsumingRegistry

Field Summary
protected  org.softamis.net.registry.ConsumingRegistry<java.lang.String,SI> fClientServicesRegistry
          Registry of "urls" for service
protected static org.apache.commons.logging.Log fLog
           
 
Fields inherited from class org.softamis.cluster4spring.support.provider.AbstractDiscoveringEndpointProvider
fProtocolName, fServiceGroup, fServiceKey, fServiceName
 
Fields inherited from class org.softamis.cluster4spring.support.provider.AbstractUrlListEndpointProvider
fCacheLock, fEndpointsCache
 
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 DiscoveringEndpointProvider()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by Spring as part of bean lifecycle.
 org.softamis.net.registry.ConsumingRegistry<java.lang.String,SI> getClientServicesRegistry()
          Returns registry of "urls" for service
protected  void invalidateServiceInRegistry(java.lang.String aServiceKey, SI aServiceInfo)
          Methods used to notify underlying services registry that particular service location should be invalidated.
protected  boolean isRefreshRequiredForCachedEndpoints(java.lang.String aServiceKey)
          Determines whether refresh for cached endpoints is required.
protected  java.util.Set<SI> obtainServiceUrlsFromRegistry(java.lang.String aServiceKey)
          Returns set of service url's from consuming registry
protected  void saveFreshEndpointsToCache(java.util.List<E> aEndpoints)
          Save obtained endpoints to endpoints cache.
 void setClientServicesRegistry(org.softamis.net.registry.ConsumingRegistry<java.lang.String,SI> aClientServicesRegistry)
          Sets registry used to obtain information about of "urls" for service
 
Methods inherited from class org.softamis.cluster4spring.support.provider.AbstractDiscoveringEndpointProvider
checkServiceName, createServiceKey, doRefreshServiceEndpointsList, getCachedEndpoints, getProtocolName, getServiceGroup, getServiceName, markInvalid, markServiceInvalidInternal, obtainServiceKey, onApplicationEvent, onContextClosed, onContextRefreshed, setProtocolName, setServiceGroup, setServiceName
 
Methods inherited from class org.softamis.cluster4spring.support.provider.AbstractUrlListEndpointProvider
doGetCachedEndpoints, getServiceEndpointsList, refresh
 
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
 

Field Detail

fLog

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

fClientServicesRegistry

protected org.softamis.net.registry.ConsumingRegistry<java.lang.String,SI extends ServiceMoniker> fClientServicesRegistry
Registry of "urls" for service

Constructor Detail

DiscoveringEndpointProvider

protected DiscoveringEndpointProvider()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Invoked by Spring as part of bean lifecycle. Adds checking for protocol name, consuming registry, etc.

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

isRefreshRequiredForCachedEndpoints

protected boolean isRefreshRequiredForCachedEndpoints(java.lang.String aServiceKey)
Determines whether refresh for cached endpoints is required. Current implementation simply checks whether ConsumingRegistry is dirty.

Specified by:
isRefreshRequiredForCachedEndpoints in class AbstractDiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Parameters:
aServiceKey - key used to check whether cahe should be refreshed
Returns:
true if endpoints cache should be refreshed.
See Also:
ConsumingRegistry.isDirty(Serializable)

saveFreshEndpointsToCache

protected void saveFreshEndpointsToCache(java.util.List<E> aEndpoints)
Description copied from class: AbstractUrlListEndpointProvider
Save obtained endpoints to endpoints cache.

Overrides:
saveFreshEndpointsToCache in class AbstractUrlListEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Parameters:
aEndpoints - list of endpoints to store in cache

invalidateServiceInRegistry

protected void invalidateServiceInRegistry(java.lang.String aServiceKey,
                                           SI aServiceInfo)
Description copied from class: AbstractDiscoveringEndpointProvider
Methods used to notify underlying services registry that particular service location should be invalidated.

Specified by:
invalidateServiceInRegistry in class AbstractDiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Parameters:
aServiceKey - key used to obtain service urls
aServiceInfo - information about particular service location

obtainServiceUrlsFromRegistry

protected java.util.Set<SI> obtainServiceUrlsFromRegistry(java.lang.String aServiceKey)
                                                                          throws java.lang.Exception
Returns set of service url's from consuming registry

Specified by:
obtainServiceUrlsFromRegistry in class AbstractDiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Parameters:
aServiceKey - key used to obtain service urls
Returns:
found service urls
Throws:
java.lang.Exception

getClientServicesRegistry

public org.softamis.net.registry.ConsumingRegistry<java.lang.String,SI> getClientServicesRegistry()
Returns registry of "urls" for service

Returns:
registry of "urls" for service

setClientServicesRegistry

public void setClientServicesRegistry(org.softamis.net.registry.ConsumingRegistry<java.lang.String,SI> aClientServicesRegistry)
Sets registry used to obtain information about of "urls" for service

Parameters:
aClientServicesRegistry - registry of "urls" for service