org.kuali.rice.ksb.impl.bus
Class ServiceBusImpl

java.lang.Object
  extended by org.kuali.rice.core.api.lifecycle.BaseLifecycle
      extended by org.kuali.rice.ksb.impl.bus.ServiceBusImpl
All Implemented Interfaces:
Lifecycle, ServiceBus, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean

public class ServiceBusImpl
extends BaseLifecycle
implements ServiceBus, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean


Constructor Summary
ServiceBusImpl()
           
 
Method Summary
 void afterPropertiesSet()
           
 void destroy()
           
protected  Set<RemoteService> filterByApplicationId(String applicationId, Set<RemoteService> remoteServices)
           
 List<Endpoint> getAllEndpoints()
          Returns an unmodifiable list of all available and online endpoints of which the service bus is aware, including both local and remote endpoints.
 Endpoint getConfiguredEndpoint(ServiceConfiguration serviceConfiguration)
          Returns the endpoint matching the given service configuration, if one exists.
 Endpoint getEndpoint(QName serviceName)
          Returns an available endpoint for the service with the given name.
 Endpoint getEndpoint(QName serviceName, String applicationId)
          Returns an available endpoint for the service with the given name which is hosted by the application with the given application id.
 List<Endpoint> getEndpoints(QName serviceName)
          Returns an unmodifiable list of accessible endpoints that are available to the service bus with the given service name.
 String getInstanceId()
          Returns the instance ID which identifies this client application to the service bus.
 Endpoint getLocalEndpoint(QName serviceName)
          Returns the endpoint for the service with the given name that was published by this service bus client.
 Map<QName,Endpoint> getLocalEndpoints()
          Returns an unmodifiable list of all services that have been published by this service bus client.
 List<Endpoint> getRemoteEndpoints(QName serviceName)
          Returns an unmodifiable list of remotely accessible endpoints that are available in the service registry with the given service name.
 Object getService(QName serviceName)
          Returns a proxy to the service with the given name.
 Object getService(QName serviceName, String applicationId)
          Returns a proxy to the service with the given name which is hosted by the application with the given application id.
protected  boolean isDevMode()
           
protected  void processLocalServiceDiff(LocalServicesDiff localServicesDiff)
           
protected  void processRemoteServiceDiff(RemoteServicesDiff remoteServicesDiff)
           
 ServiceConfiguration publishService(ServiceDefinition serviceDefinition, boolean synchronize)
          Publish a service with the given ServiceDefinition to the service bus.
 List<ServiceConfiguration> publishServices(List<ServiceDefinition> serviceDefinitions, boolean synchronize)
          Functions as per ServiceBus.publishService(ServiceDefinition, boolean) but allows for multiple services to be published to the bus in a single operation.
protected  void rebuildLocalServiceEndpointAfterPublishing(ServiceEndpoint publishedService)
           
protected  ServiceEndpoint rebuildServiceEndpointForUpdate(ServiceEndpoint originalEndpoint, ServiceInfo registryServiceInfo)
           
 boolean removeService(QName serviceName, boolean synchronize)
          Removes the service from the service bus and the service registry with the given service name.
 List<Boolean> removeServices(List<QName> serviceNames, boolean synchronize)
          Functions as per ServiceBus.removeService(QName, boolean) but allows for multiple services to be removed from the bus in a single operation.
 void setDiffCalculator(ServiceRegistryDiffCalculator diffCalculator)
           
 void setInstanceId(String instanceId)
           
 void setScheduledPool(KSBScheduledPool scheduledPool)
           
 void setServiceExportManager(ServiceExportManager serviceExportManager)
           
 void setServiceRegistry(ServiceRegistry serviceRegistry)
           
 void start()
           
protected  void startSynchronizationThread()
           
protected  void stopSynchronizationThread()
           
 void synchronize()
          Synchronizes the current client's service bus with the central service registry.
 
Methods inherited from class org.kuali.rice.core.api.lifecycle.BaseLifecycle
isStarted, setStarted, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceBusImpl

public ServiceBusImpl()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

start

public void start()
           throws Exception
Specified by:
start in interface Lifecycle
Overrides:
start in class BaseLifecycle
Throws:
Exception

isDevMode

protected boolean isDevMode()

startSynchronizationThread

protected void startSynchronizationThread()

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
Exception

stopSynchronizationThread

protected void stopSynchronizationThread()

getInstanceId

public String getInstanceId()
Description copied from interface: ServiceBus
Returns the instance ID which identifies this client application to the service bus. The instance ID should be unique for each client of the service bus and will never be blank or null.

Specified by:
getInstanceId in interface ServiceBus
Returns:
the instance ID for the application in which this service bus client is resident

setInstanceId

public void setInstanceId(String instanceId)

getEndpoints

public List<Endpoint> getEndpoints(QName serviceName)
Description copied from interface: ServiceBus
Returns an unmodifiable list of accessible endpoints that are available to the service bus with the given service name. This method will only return endpoints that the service bus believes are online, endpoints which are offline will not be included. In certain cases a specific service endpoint will be available both as a local and remote service. In these cases, the list returned from this method will preferentially include the local service. It will *not* include both the local and remote endpoint to the same service. This is important as this method may be used to get endpoints for broadcasting service calls to all endpoints with a given name. In these cases, it is not desirable to invoke the same endpoint twice.

Specified by:
getEndpoints in interface ServiceBus
Returns:
a list of the remote endpoints that are available for the given service name, this list will never be null but may be empty if there are no remote endpoints for the given service name

getRemoteEndpoints

public List<Endpoint> getRemoteEndpoints(QName serviceName)
Description copied from interface: ServiceBus
Returns an unmodifiable list of remotely accessible endpoints that are available in the service registry with the given service name. This method will only return endpoints that the service bus believes are online, endpoints which are offline will not be included.

If the service bus client has also deployed a service with this name, a remoted endpoint to this service will likely also be included in this list assuming that endpoint has already been synchronized with the registry.

In most cases, it is preferable to use ServiceBus.getEndpoints(QName) instead of this method. Because it will preferably return a local endpoint reference for a given service endpoint if one is available.

Specified by:
getRemoteEndpoints in interface ServiceBus
Returns:
a list of all endpoints that are available for the given service name, this list will never be null but may be empty if there are no endpoints for the given service name

getLocalEndpoint

public Endpoint getLocalEndpoint(QName serviceName)
Description copied from interface: ServiceBus
Returns the endpoint for the service with the given name that was published by this service bus client. If this client has not published any such service, then this method will return null.

Specified by:
getLocalEndpoint in interface ServiceBus
Parameters:
serviceName - the name of the service represented by the local endpoint
Returns:
the local endpoint for the given service name which was deployed by this client, or null if no such service has been published

getLocalEndpoints

public Map<QName,Endpoint> getLocalEndpoints()
Description copied from interface: ServiceBus
Returns an unmodifiable list of all services that have been published by this service bus client.

Specified by:
getLocalEndpoints in interface ServiceBus
Returns:
a map with the local service name as the key and the local endpoint as the value which contains all local services published by this service bus client. This map may be empty if this client has published no services, but it should never be null.

getAllEndpoints

public List<Endpoint> getAllEndpoints()
Description copied from interface: ServiceBus
Returns an unmodifiable list of all available and online endpoints of which the service bus is aware, including both local and remote endpoints.

Specified by:
getAllEndpoints in interface ServiceBus
Returns:
all available endpoints, this list may be empty if no endpoints exist but will never be null

getEndpoint

public Endpoint getEndpoint(QName serviceName)
Description copied from interface: ServiceBus
Returns an available endpoint for the service with the given name. If the service with the given name is published locally, preference will be given to the locally deployed version of the service.

Based on the nature of this method, if there is more than one endpoint available for the given name, multiple invocations of this method with the same service name may return different Endpoint instances each time.

Specified by:
getEndpoint in interface ServiceBus
Parameters:
serviceName - the name of the service for which to locate an available endpoint
Returns:
an available endpoint for the service with the given name, or null if none is available

getEndpoint

public Endpoint getEndpoint(QName serviceName,
                            String applicationId)
Description copied from interface: ServiceBus
Returns an available endpoint for the service with the given name which is hosted by the application with the given application id. This operation functions the same as ServiceBus.getEndpoint(QName) with the exception that it will only consider endpoints with the given application id.

Invoking this method with a null or blank value for applicationId is equivalent to invoking ServiceBus.getEndpoint(QName).

Specified by:
getEndpoint in interface ServiceBus
Parameters:
serviceName - the name of the service for which to locate an available endpoint
applicationId - the id of the application for which to locate an available endpoint for the given service name
Returns:
an available endpoint for the service with the given name and application id, or null if none is available

filterByApplicationId

protected Set<RemoteService> filterByApplicationId(String applicationId,
                                                   Set<RemoteService> remoteServices)

getConfiguredEndpoint

public Endpoint getConfiguredEndpoint(ServiceConfiguration serviceConfiguration)
Description copied from interface: ServiceBus
Returns the endpoint matching the given service configuration, if one exists. In the case of services published by this service bus client, this method will preferably return the local endpoints in place of a remote endpoint to the same service.

Specified by:
getConfiguredEndpoint in interface ServiceBus
Parameters:
serviceConfiguration - the service configuration by which to lookup up the endpoint
Returns:
the endpoint who's service configuration matches the given configuration, or null if no such match could be determined

getService

public Object getService(QName serviceName)
Description copied from interface: ServiceBus
Returns a proxy to the service with the given name. This proxy should have built-in support for fail-over and load balancing capabilities. This means it is safe for client applications to cache a reference to this service proxy.

This proxy should additionally be thread-safe.

This method is equivalent to invoking #getEndpoint(QName).getService().

Specified by:
getService in interface ServiceBus
Parameters:
serviceName - the name of the service for which to locate an available proxy
Returns:
an available proxy for the service with the given name, or null if none is available

getService

public Object getService(QName serviceName,
                         String applicationId)
Description copied from interface: ServiceBus
Returns a proxy to the service with the given name which is hosted by the application with the given application id. This operation functions the same as ServiceBus.getService(QName) with the exception that it will only consider endpoints with the given application id.

Invoking this method with a null or blank value for applicationId is equivalent to invoking ServiceBus.getService(QName). This method is also equivalent to invoking #getEndpoint(QName, String).getService().

Specified by:
getService in interface ServiceBus
Parameters:
serviceName - the name of the service for which to locate an available proxy
applicationId - the id of the application for which to locate an available proxy for the given service name
Returns:
an available proxy for the service with the given name, or null if none is available

publishService

public ServiceConfiguration publishService(ServiceDefinition serviceDefinition,
                                           boolean synchronize)
Description copied from interface: ServiceBus
Publish a service with the given ServiceDefinition to the service bus. This effectively updates the service registry and provides an endpoint for other applications to invoke. If this application has already published a service under this name, it will be updated instead to reflect the new ServiceDefinition.

The method also provides the ability for the service bus to immediately synchronize with the service registry after registering the service if synchronize is set to true.

Specified by:
publishService in interface ServiceBus
Parameters:
serviceDefinition - the definition of the service to publish, must not be null
synchronize - indicates whether or not this service bus client should immediately synchronize it's changes with the registry after registering the service.
Returns:
the service configuration for the published service
See Also:
ServiceBus.synchronize()

publishServices

public List<ServiceConfiguration> publishServices(List<ServiceDefinition> serviceDefinitions,
                                                  boolean synchronize)
Description copied from interface: ServiceBus
Functions as per ServiceBus.publishService(ServiceDefinition, boolean) but allows for multiple services to be published to the bus in a single operation. If the given list of service definitions is empty then this method will do nothing (including skipping synchronization with the registry if that was requested).

Specified by:
publishServices in interface ServiceBus
Parameters:
serviceDefinitions - the list of definition for the services to publish, must not be null
synchronize - indicates whether or not this service bus client should immediately synchronize it's changes with the registry after registering the services.
Returns:
the list of service configurations for the published services in the same order as the list of service definitions
See Also:
ServiceBus.publishService(ServiceDefinition, boolean), ServiceBus.synchronize()

removeService

public boolean removeService(QName serviceName,
                             boolean synchronize)
Description copied from interface: ServiceBus
Removes the service from the service bus and the service registry with the given service name. Client applications should only be able to remove services that they themselves have published.

This method also provides the ability for the service bus to immediately synchronize with the service registry after removing the service if synchronize is set to true. If the service is not located and successfully removed, however, the sychronization will not run.

Specified by:
removeService in interface ServiceBus
Parameters:
serviceName - the name of the service to remove
synchronize - indicates whether or not this service bus client should immediately synchronize after removing the service
Returns:
true if the service was removed, false otherwise
See Also:
ServiceBus.synchronize()

removeServices

public List<Boolean> removeServices(List<QName> serviceNames,
                                    boolean synchronize)
Description copied from interface: ServiceBus
Functions as per ServiceBus.removeService(QName, boolean) but allows for multiple services to be removed from the bus in a single operation. If the given list of service names is empty then this method will do nothing (including skipping synchronization with the registry if that was requested).

If the list returned from the method contains only false responses (meaning that no services were removed) this method will skip synchronization even if it is requested.

Specified by:
removeServices in interface ServiceBus
Parameters:
serviceNames - the list of names for the services to remove, must not be null
synchronize - indicates whether or not this service bus client should immediately synchronize it's changes with the registry after removing the services.
Returns:
a list of Booleans indicating which of the service removals were successful. This list will be in the same order as the list of service configurations that were passed in.
See Also:
ServiceBus.removeService(QName, boolean), ServiceBus.synchronize()

synchronize

public void synchronize()
Description copied from interface: ServiceBus
Synchronizes the current client's service bus with the central service registry. This is done automatically on a periodic basic, but can be invoked manually through this method. This method should both register any outstanding service publications to the registry, as well as detect any changes in remote services that have been published/removed by other applications in the registry and update local service bus state accordingly.

Specified by:
synchronize in interface ServiceBus

processRemoteServiceDiff

protected void processRemoteServiceDiff(RemoteServicesDiff remoteServicesDiff)

processLocalServiceDiff

protected void processLocalServiceDiff(LocalServicesDiff localServicesDiff)

rebuildServiceEndpointForUpdate

protected ServiceEndpoint rebuildServiceEndpointForUpdate(ServiceEndpoint originalEndpoint,
                                                          ServiceInfo registryServiceInfo)

rebuildLocalServiceEndpointAfterPublishing

protected void rebuildLocalServiceEndpointAfterPublishing(ServiceEndpoint publishedService)

setServiceRegistry

public void setServiceRegistry(ServiceRegistry serviceRegistry)

setDiffCalculator

public void setDiffCalculator(ServiceRegistryDiffCalculator diffCalculator)

setServiceExportManager

public void setServiceExportManager(ServiceExportManager serviceExportManager)

setScheduledPool

public void setScheduledPool(KSBScheduledPool scheduledPool)


Copyright © 2005-2011 The Kuali Foundation. All Rights Reserved.