org.softamis.cluster4spring.support.provider
Class DiscoveringEndpointProviderEx<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>
                      extended by org.softamis.cluster4spring.support.provider.DiscoveringEndpointProviderEx<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.softamis.net.exchange.spi.RegistryEventProcessor<java.lang.String,SI>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationListener

public class DiscoveringEndpointProviderEx<E extends Endpoint<SI>,SI extends ServiceMoniker>
extends DiscoveringEndpointProvider<E,SI>
implements org.softamis.net.exchange.spi.RegistryEventProcessor<java.lang.String,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.

While DiscoveringEndpointProvider determines when refresh of endpoints should be performed (if configured to cache endpoints) based on state of networking registry, this class (if configured to cache endpoints) acts as listener of ConsumingRegistry and is able to create/remove service endpoints as soon as appropriate service url is registered/unregistered in distributed registry.

If configured not to cache endpoints, it behaves exatly as DiscoveringEndpointProvider

Author:
Andrew Sazonov
See Also:
ConsumingRegistry, BaseEndpointProvider.setCacheEndpoints(boolean)

Field Summary
protected  boolean fCheckRegistryDirty
           
protected  EndpointFactory<E,SI> fEndpointFactory
          Factory used to create endpoints
protected  boolean fListenRegistry
          Option that specifies whether provider should register itself as listener for ConsumingRegistry
protected  org.springframework.remoting.support.RemoteInvocationFactory fRemoteInvocationFactory
          Factory used to create remote invocations
 
Fields inherited from class org.softamis.cluster4spring.support.provider.DiscoveringEndpointProvider
fClientServicesRegistry, 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
DiscoveringEndpointProviderEx()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by Spring as part of bean lifecycle.
protected  void checkRemoteInvocationFactory()
           
protected  void checkServiceName()
           
 void close()
          If provider added itself as listener to the registry, removes listener.
protected  void createAndAddEndpointToCache(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
          Creates endpoint and adds it to endpoints cache based on service key and service url.
protected  boolean equals(java.lang.String aFirst, java.lang.String aSecond)
           
 EndpointFactory<E,SI> getEndpointFactory()
          Returns factory used to create endpoints.
 org.springframework.remoting.support.RemoteInvocationFactory getRemoteInvocationFactory()
          Returns factory used to create remote invocations
 void init()
          Method used for initialization of provider.
protected  boolean isApplicableEntry(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
          Utility method used to determine whether url obtained as part of ConsumingRegistry notification is related to service which is processed by current provider.
 boolean isListenRegistry()
          Returns option that specifies whether provider should register itself as listener for ConsumingRegistry
protected  boolean isRefreshRequiredForCachedEndpoints(java.lang.String aServiceKey)
          Determines whether refresh for cached endpoints is required.
protected  void onContextClosed()
          Handles ContextClosed application event.
protected  void onContextRefreshed()
          Handles ContextRefreshed application event.
 void processItemInvalid(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_INVALID notification If url is registered for service that is processed by given provider, removes endpoint from endpoints cache.
 void processItemRegistered(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_REGISTERED notification.
 void processItemsRequest(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_REQUEST notification - typically will be processed by ProvidingRegistry.
 void processItemUnregistered(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_UNREGISTERED notification.
protected  void removeEndpointFromCache(SI aServiceInfo)
          Removes endpoint that corresponds to given service url from endpoints cache.
 void setEndpointFactory(EndpointFactory<E,SI> aEndpointFactory)
          Sets factory used to create endpoints.- should be specified only provider is configured to be listener for registry.
 void setListenRegistry(boolean aListenRegistry)
          Sets option that specifies whether provider should register itself as listener for ConsumingRegistry
 void setRemoteInvocationFactory(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory)
          Sets factory used to create remote invocations - should be specified only provider is configured to be listener for registry.
 
Methods inherited from class org.softamis.cluster4spring.support.provider.DiscoveringEndpointProvider
getClientServicesRegistry, invalidateServiceInRegistry, obtainServiceUrlsFromRegistry, saveFreshEndpointsToCache, setClientServicesRegistry
 
Methods inherited from class org.softamis.cluster4spring.support.provider.AbstractDiscoveringEndpointProvider
createServiceKey, doRefreshServiceEndpointsList, getCachedEndpoints, getProtocolName, getServiceGroup, getServiceName, markInvalid, markServiceInvalidInternal, obtainServiceKey, onApplicationEvent, 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

fListenRegistry

protected boolean fListenRegistry
Option that specifies whether provider should register itself as listener for ConsumingRegistry


fRemoteInvocationFactory

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


fEndpointFactory

protected EndpointFactory<E extends Endpoint<SI>,SI extends ServiceMoniker> fEndpointFactory
Factory used to create endpoints


fCheckRegistryDirty

protected boolean fCheckRegistryDirty
Constructor Detail

DiscoveringEndpointProviderEx

public DiscoveringEndpointProviderEx()
Method Detail

processItemUnregistered

public void processItemUnregistered(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
Callback for processing CommunicationHelper.COMMAND_ITEM_UNREGISTERED notification. If url is registered for service that is processed by given provider, removes endpoint from endpoints cache.

Specified by:
processItemUnregistered in interface org.softamis.net.exchange.spi.RegistryEventProcessor<java.lang.String,SI extends ServiceMoniker>
Parameters:
aEntry - recevied item entry

processItemRegistered

public void processItemRegistered(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
Callback for processing CommunicationHelper.COMMAND_ITEM_REGISTERED notification. If url is registered for service that is processed by given provider, creates endpoint for obtained url and adds it to endpoints cache.

Specified by:
processItemRegistered in interface org.softamis.net.exchange.spi.RegistryEventProcessor<java.lang.String,SI extends ServiceMoniker>
Parameters:
aEntry - recevied item entry

createAndAddEndpointToCache

protected void createAndAddEndpointToCache(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
Creates endpoint and adds it to endpoints cache based on service key and service url. Endpoint is added to cache only if there is no endpoint for given url. If endpoint cannot be created for obtained service, error is silently ignored.

Parameters:
aEntry - entry that contains information about service key and service url.

processItemsRequest

public void processItemsRequest(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
Callback for processing CommunicationHelper.COMMAND_ITEM_REQUEST notification - typically will be processed by ProvidingRegistry. In this implementation intentionally does nothing.

Specified by:
processItemsRequest in interface org.softamis.net.exchange.spi.RegistryEventProcessor<java.lang.String,SI extends ServiceMoniker>
Parameters:
aEntry - recevied item entry

processItemInvalid

public void processItemInvalid(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
Callback for processing CommunicationHelper.COMMAND_ITEM_INVALID notification If url is registered for service that is processed by given provider, removes endpoint from endpoints cache.

Specified by:
processItemInvalid in interface org.softamis.net.exchange.spi.RegistryEventProcessor<java.lang.String,SI extends ServiceMoniker>
Parameters:
aEntry - recevied item entry

removeEndpointFromCache

protected void removeEndpointFromCache(SI aServiceInfo)
Removes endpoint that corresponds to given service url from endpoints cache.

Parameters:
aServiceInfo - service url

isRefreshRequiredForCachedEndpoints

protected boolean isRefreshRequiredForCachedEndpoints(java.lang.String aServiceKey)
Determines whether refresh for cached endpoints is required. If configured to be listener of ConsumingRegistry, determines whether endpoints case is empty and if so, returns true. If is not configured to listen registry, simple checks registry state.

Overrides:
isRefreshRequiredForCachedEndpoints in class DiscoveringEndpointProvider<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(java.io.Serializable), setListenRegistry(boolean)

isApplicableEntry

protected boolean isApplicableEntry(org.softamis.net.exchange.spi.ItemEntry<java.lang.String,SI> aEntry)
Utility method used to determine whether url obtained as part of ConsumingRegistry notification is related to service which is processed by current provider.

Parameters:
aEntry - entry that contains information about service key and service url
Returns:
true if obtained entry corresponds service processed by provider

equals

protected boolean equals(java.lang.String aFirst,
                         java.lang.String aSecond)

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Description copied from class: DiscoveringEndpointProvider
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 DiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Throws:
java.lang.Exception
See Also:
MultiURLEndpointProvider.createDefaultEndpointSelectionPolicy()

checkRemoteInvocationFactory

protected void checkRemoteInvocationFactory()

checkServiceName

protected void checkServiceName()
Overrides:
checkServiceName in class AbstractDiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>

onContextRefreshed

protected void onContextRefreshed()
Description copied from class: AbstractDiscoveringEndpointProvider
Handles ContextRefreshed application event.

Overrides:
onContextRefreshed in class AbstractDiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
See Also:
AbstractDiscoveringEndpointProvider.onApplicationEvent(ApplicationEvent)

onContextClosed

protected void onContextClosed()
Description copied from class: AbstractDiscoveringEndpointProvider
Handles ContextClosed application event. On closing context clears endpoints cache

Overrides:
onContextClosed in class AbstractDiscoveringEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
See Also:
AbstractDiscoveringEndpointProvider.onApplicationEvent(ApplicationEvent)

init

public void init()
Method used for initialization of provider. If provider is configured to listen registry and to cache endpoints, it add itself as listener to registry. Otherwise, does nothing. Due to this, this method SHOULD BE DECLARED as init-method of Spring bean.


close

public void close()
If provider added itself as listener to the registry, removes listener. This method SHOULD BE DELARED as destroy-method in Spring definition of bean.


isListenRegistry

public boolean isListenRegistry()
Returns option that specifies whether provider should register itself as listener for ConsumingRegistry

Returns:
true if provider listens registry

setListenRegistry

public void setListenRegistry(boolean aListenRegistry)
Sets option that specifies whether provider should register itself as listener for ConsumingRegistry

Parameters:
aListenRegistry - option that specifies that provider should listen registry

getRemoteInvocationFactory

public org.springframework.remoting.support.RemoteInvocationFactory getRemoteInvocationFactory()
Returns factory used to create remote invocations

Returns:
factory used to create remote invocations

setRemoteInvocationFactory

public void setRemoteInvocationFactory(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory)
Sets factory used to create remote invocations - should be specified only provider is configured to be listener for registry.

Parameters:
aRemoteInvocationFactory - factory used to create remote invocations
See Also:
setListenRegistry(boolean)

getEndpointFactory

public EndpointFactory<E,SI> getEndpointFactory()
Returns factory used to create endpoints.

Returns:
factory used to create endpoints

setEndpointFactory

public void setEndpointFactory(EndpointFactory<E,SI> aEndpointFactory)
Sets factory used to create endpoints.- should be specified only provider is configured to be listener for registry.

Parameters:
aEndpointFactory - factory used to create endpoints
See Also:
setListenRegistry(boolean)