com.codemonster.surinam.core.framework.impl
Class ServiceDirectoryImpl

java.lang.Object
  extended by com.codemonster.surinam.core.framework.impl.ServiceDirectoryImpl
All Implemented Interfaces:
ServiceDirectory, ServiceDirectoryAdmin

public class ServiceDirectoryImpl
extends Object
implements ServiceDirectory, ServiceDirectoryAdmin

This is the default service directory implementation for the Surinam project. This is one of the more important pieces of the whole framework from a runtime perspective since this is the central directory for all registered Entry Points, Service Contracts and Implementations.


Constructor Summary
ServiceDirectoryImpl()
           
 
Method Summary
 void activateService(Class serviceName)
          This is just an idea for lifecycle support that we might ask a organization implementation to mark itself as unavailable.
 boolean bindImplementation(Class serviceName, ManagedService managedService)
          Here, we store the given impl for this service interface.
 void deactivateService(Class serviceName)
          This is just an idea for lifecycle support that we might ask a organization implementation to mark itself as unavailable.
 Set<Class> getAllServices()
          This is an easy way to acquire the list of known services, including both Entry Points and Service Points.
 Object getProviderImplementation(VersionedProviderImplementationName versionedProviderImplementationName)
          This method will allow external threads to build their own compound versionedProviderImplementationName that identifies a versioned implementation class and get a reference to that impl class.
 ManagedService getService(Class serviceClass)
          We take the class of the service interface we want to use and we return an implementation of that service interface.
 ManagedService getUnvalidatedService(Class serviceClass)
          This method returns a managed service but does not consider the reference valid for making an invocation on.
 boolean isBoundImplementation(ManagedService impl)
          This method will scan the collection of held implementations to see if there's a match.
 boolean isBoundImplementation(VersionedProviderImplementationName key)
          Simple query to see if a particular implementation is known to the directory.
 boolean isRegisteredContract(Class serviceClass)
          Simple query to see if a contract is registered or not.
 void registerContractWithDefaultBinding(Class serviceClass)
          The given service Class will be registered with default binding.
 void reset()
          This method will cause the Service Directory to flush all its internal mappings and reset its state to what it was when it was first created.
 void retireContract(Class serviceClass)
          Takes the given Contract (or EntryPoint) and removes it from the directory and frees the Contract and any implementation bound to it.
 void retireEntryPoint(Class entryPointClass)
          A little syntactic sugar since retiring an Entry Point is the same as for a Contract.
 String toHTML()
          This method will render the service directory structure as an HTML string.
 String toXML()
          This method will render the service directory structure as an xml string.
 void unbindImplementation(ManagedService managedService)
           
 void unbindImplementation(VersionedProviderImplementationName versionedImplName)
           
 void unbindServiceImplementation(Class serviceName)
          Unbinding an implementation will set the given service to the default placeholder.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceDirectoryImpl

public ServiceDirectoryImpl()
Method Detail

getService

public ManagedService getService(Class serviceClass)
                          throws UnknownServiceException,
                                 UnavailableServiceException
Description copied from interface: ServiceDirectory
We take the class of the service interface we want to use and we return an implementation of that service interface.

Specified by:
getService in interface ServiceDirectory
Parameters:
serviceClass - This should be the class of an interface.
Returns:
Returns an object that implements the given interface, normally a proxy.
Throws:
UnknownServiceException - This exception can be thrown if the service that the proxy tries to acquire has been removed from the directory.
UnavailableServiceException - This exception gets thrown if the service is known but has removed itself from an active state possibly due to some runtime failure.j

getUnvalidatedService

public ManagedService getUnvalidatedService(Class serviceClass)
                                     throws UnknownServiceException,
                                            UnavailableServiceException
This method returns a managed service but does not consider the reference valid for making an invocation on. This is here only to break chicken-and-egg Catch-22 situations.

Specified by:
getUnvalidatedService in interface ServiceDirectoryAdmin
Parameters:
serviceClass - This is the key by which, we will acquire a reference to the service.
Returns:
Returns a reference to the service that the contract maps to.
Throws:
UnknownServiceException
UnavailableServiceException

getAllServices

public Set<Class> getAllServices()
Description copied from interface: ServiceDirectoryAdmin
This is an easy way to acquire the list of known services, including both Entry Points and Service Points.

Specified by:
getAllServices in interface ServiceDirectoryAdmin
Returns:
Returns a list of known services contracts.

getProviderImplementation

public Object getProviderImplementation(VersionedProviderImplementationName versionedProviderImplementationName)
Description copied from interface: ServiceDirectoryAdmin
This method will allow external threads to build their own compound versionedProviderImplementationName that identifies a versioned implementation class and get a reference to that impl class. This is useful if you want to register an existing instance to service an additional contract. This would happen in cases where an implementation supports multiple contracts and may already be in service for one or more of them. The implication in this is that there may be additional code paths that are not being used in the instance until invocations on another contract start coming in.

Specified by:
getProviderImplementation in interface ServiceDirectoryAdmin
Parameters:
versionedProviderImplementationName - This is the key that will be used to indentify and acquire the impl object.
Returns:
Returns the object of the given class, of the given version if it exists.

isRegisteredContract

public boolean isRegisteredContract(Class serviceClass)
Description copied from interface: ServiceDirectory
Simple query to see if a contract is registered or not.

Specified by:
isRegisteredContract in interface ServiceDirectory
Parameters:
serviceClass - This is the class object for the Service Contract interface.
Returns:
Returns a boolean indicating whether this is a known Service Contract.

isBoundImplementation

public boolean isBoundImplementation(VersionedProviderImplementationName key)
Description copied from interface: ServiceDirectory
Simple query to see if a particular implementation is known to the directory.

Specified by:
isBoundImplementation in interface ServiceDirectory
Parameters:
key - This is the key that will be used to indentify and acquire the impl object.
Returns:
Returns a boolean indicating whether this is a known implementation.

isBoundImplementation

public boolean isBoundImplementation(ManagedService impl)
Description copied from interface: ServiceDirectoryAdmin
This method will scan the collection of held implementations to see if there's a match.

Specified by:
isBoundImplementation in interface ServiceDirectoryAdmin
Parameters:
impl - The instance being searched for.
Returns:
Returns true or false depending on whether the instance has been found.

bindImplementation

public boolean bindImplementation(Class serviceName,
                                  ManagedService managedService)
                           throws ServiceBindingException
Description copied from interface: ServiceDirectoryAdmin
Here, we store the given impl for this service interface. At some point this could optionally become a pool or a list of impl objects that all implement the same interface and managers or selectors will decide which get used.

Note that this method supports registration of unbound service contracts by accepting a null value for the implementation and a placeholder will be supplied internally.

Specified by:
bindImplementation in interface ServiceDirectoryAdmin
Parameters:
serviceName - This is the class for the interface that defines the service contract.
managedService - This is the implementation instance for this interface which must extend the Adapter or
Returns:
returns false if there was a problem completing the task.
Throws:
ServiceBindingException - Thrown if there is a problem with the assignment.

unbindServiceImplementation

public void unbindServiceImplementation(Class serviceName)
Description copied from interface: ServiceDirectoryAdmin
Unbinding an implementation will set the given service to the default placeholder. A check is then made to see if this implementation is providing processing logic for any other service points and if it is found to no longer be used, it is removed from the collection of known service implementations as well.

Specified by:
unbindServiceImplementation in interface ServiceDirectoryAdmin
Parameters:
serviceName - The service class for the service point for which we wish to remove the impl.

unbindImplementation

public void unbindImplementation(VersionedProviderImplementationName versionedImplName)

unbindImplementation

public void unbindImplementation(ManagedService managedService)

registerContractWithDefaultBinding

public void registerContractWithDefaultBinding(Class serviceClass)
The given service Class will be registered with default binding. This also has the effect of replacing any existing implementation binding with the default.

Specified by:
registerContractWithDefaultBinding in interface ServiceDirectoryAdmin
Parameters:
serviceClass - The fq Class object for the service.

retireEntryPoint

public void retireEntryPoint(Class entryPointClass)
A little syntactic sugar since retiring an Entry Point is the same as for a Contract.

Parameters:
entryPointClass -

retireContract

public void retireContract(Class serviceClass)
Takes the given Contract (or EntryPoint) and removes it from the directory and frees the Contract and any implementation bound to it.

Specified by:
retireContract in interface ServiceDirectoryAdmin
Parameters:
serviceClass - The fq name of the service you wish to retire.

activateService

public void activateService(Class serviceName)
This is just an idea for lifecycle support that we might ask a organization implementation to mark itself as unavailable. This would affect the runtime routing without explicitly removing the impl mapping.

Specified by:
activateService in interface ServiceDirectoryAdmin
Parameters:
serviceName - Name of the service to be activated.

deactivateService

public void deactivateService(Class serviceName)
This is just an idea for lifecycle support that we might ask a organization implementation to mark itself as unavailable. This would affect the runtime routing without explicitly removing the impl mapping.

Specified by:
deactivateService in interface ServiceDirectoryAdmin
Parameters:
serviceName - Name of the service to be deactivated.

reset

public void reset()
This method will cause the Service Directory to flush all its internal mappings and reset its state to what it was when it was first created. This includes releasing all implementation class loaders which will take all related classes along with it.

Specified by:
reset in interface ServiceDirectoryAdmin

toXML

public String toXML()
This method will render the service directory structure as an xml string.

Specified by:
toXML in interface ServiceDirectory
Returns:
Returns the XML string.

toHTML

public String toHTML()
This method will render the service directory structure as an HTML string.

Specified by:
toHTML in interface ServiceDirectory
Returns:
Returns the HTML string.


Copyright © 2010. All Rights Reserved.