org.softamis.cluster4spring.support.provider
Class SingleUrlEndpointProvider<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.SingleUrlEndpointProvider<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

public class SingleUrlEndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
extends BaseEndpointProvider<E,SI>
implements org.springframework.beans.factory.InitializingBean

Implementation of EndpointProvider that utilises single and explicitely specified "url" of the service to create service endpoint. Basically, any object may represent service "url" - it is responsibility of concrete implementation of EndpointFactory to interpret given object and create appropriate endpoint for remote service that could be located based on given "url".

In general, this is similar to traditional Spring cluster4spring.

Author:
Andrew Sazonov

Field Summary
protected  E fEndpoint
          Cached endpoint, if any.
protected static org.apache.commons.logging.Log fLog
           
protected  SI fServiceMoniker
          Information needed to discover remote service
 
Fields inherited from class org.softamis.cluster4spring.support.provider.BaseEndpointProvider
fCacheEndpoints
 
Constructor Summary
SingleUrlEndpointProvider()
           
 
Method Summary
 void afterPropertiesSet()
          Called by Spring as part of bean lifecycle.
 E getEndpoint(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory, EndpointFactory<E,SI> aEndpointFactory, java.lang.String aBeanName)
          Returns endpoint that will be used for remote service invocation.
 SI getServiceMoniker()
           
 java.lang.String getServiceUrl()
          Returns information needed to discover remote service
 void markInvalid(java.lang.String aBeanName, E aEndpoint)
          Marks given endpoint invalid.
 void refresh(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory, EndpointFactory<E,SI> aEndpointFactory, java.lang.String aBeanName)
          Refreshes internal state of provider.
 void setServiceMoniker(SI aServiceMoniker)
          Sets information needed to discover remote service
 void setServiceUrl(java.lang.String aServiceURL)
           
 
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

fEndpoint

protected E extends Endpoint<SI> fEndpoint
Cached endpoint, if any.


fServiceMoniker

protected SI extends ServiceMoniker fServiceMoniker
Information needed to discover remote service

Constructor Detail

SingleUrlEndpointProvider

public SingleUrlEndpointProvider()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Called by Spring as part of bean lifecycle. Checks whether serviceUrl property is specified.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception
See Also:
setServiceMoniker(ServiceMoniker), setServiceUrl(String)

getEndpoint

public E getEndpoint(org.springframework.remoting.support.RemoteInvocationFactory aRemoteInvocationFactory,
                     EndpointFactory<E,SI> aEndpointFactory,
                     java.lang.String aBeanName)
                                   throws org.springframework.remoting.RemoteAccessException
Returns endpoint that will be used for remote service invocation. If configured to cache discovered endpoints, simply returns cached endpoint.

Otherwise, tries to create endpoint using provided EndpointFactory

Specified by:
getEndpoint in interface EndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Parameters:
aRemoteInvocationFactory - factory used to create remote invocations
aEndpointFactory - factory used to create endpoints
aBeanName - name of bean that is used as proxy for remote service
Returns:
endpoint that should be used to remote invocation
Throws:
org.springframework.remoting.RemoteAccessException - thrown if endpoint could not be selected of if there are not currently available endpoints for remote service
See Also:
BaseEndpointProvider.setCacheEndpoints(boolean)

markInvalid

public void markInvalid(java.lang.String aBeanName,
                        E aEndpoint)
Marks given endpoint invalid. This endpoint will not be later used for methods invocation. This implementation simply assigns null to cached endpoint.

Specified by:
markInvalid in interface EndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
Parameters:
aBeanName - name of bean that is used as proxy for remote service
aEndpoint - endpoint to be marked invalid

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 convifugred to cache endpoints, tries to create endpoint using provided EndpointFactory and stored created endpoint for later use.

Otherwise, silently does nothing since endpoint will be obtained by request.

Specified by:
refresh in interface EndpointProvider<E extends Endpoint<SI>,SI extends ServiceMoniker>
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
See Also:
BaseEndpointProvider.setCacheEndpoints(boolean)

setServiceMoniker

public void setServiceMoniker(SI aServiceMoniker)
Sets information needed to discover remote service

Parameters:
aServiceMoniker - information needed to discover remote service

getServiceMoniker

public SI getServiceMoniker()

getServiceUrl

public java.lang.String getServiceUrl()
Returns information needed to discover remote service

Returns:
service info

setServiceUrl

public void setServiceUrl(java.lang.String aServiceURL)