org.apache.hivemind.impl
Class RegistryInfrastructureImpl

java.lang.Object
  extended by org.apache.hivemind.impl.RegistryInfrastructureImpl
All Implemented Interfaces:
RegistryInfrastructure, ServiceSerializationSupport, SymbolSource

public final class RegistryInfrastructureImpl
extends java.lang.Object
implements RegistryInfrastructure, ServiceSerializationSupport

Implementation of RegistryInfrastructure.

Author:
Howard Lewis Ship

Constructor Summary
RegistryInfrastructureImpl(ErrorHandler errorHandler, java.util.Locale locale)
           
 
Method Summary
 void addConfigurationPoint(ConfigurationPoint point)
           
 void addServicePoint(ServicePoint point)
           
 void cleanupThread()
          Convienience for invoking ThreadEventNotifier.fireThreadCleanup().
 boolean containsConfiguration(java.lang.String configurationId, Module module)
          Returns true if a configuration for the specified id exists (and is visible to the specified module).
 boolean containsService(java.lang.Class serviceInterface, Module module)
          Returns true if a single service exists which implements the specified service interface and is visible to the given module.
 boolean containsService(java.lang.String serviceId, java.lang.Class serviceInterface, Module module)
          Returns true if a single service with the given id exists which implements the specified service interface and is visible to the given module.
 java.lang.String expandSymbols(java.lang.String text, Location location)
          Expands any substitution symbols in the input string, replacing each symbol with the symbols value (if known).
 java.util.List getConfiguration(java.lang.String configurationId, Module module)
          Returns the converted items contributed to the configuration point.
 java.util.Map getConfigurationAsMap(java.lang.String configurationId, Module module)
          Returns the elements of the given configuration point as an unmodifiable Map.
 ConfigurationPoint getConfigurationPoint(java.lang.String configurationId, Module module)
          Returns the configuration point.
 ErrorHandler getErrorHander()
          Returns the ErrorHandler for this Registry.
 java.util.Locale getLocale()
          Returns the locale for which the registry was created.
 Module getModule(java.lang.String moduleId)
          Returns the module with the corresponding module id.
 java.lang.Object getService(java.lang.Class serviceInterface, Module module)
          Finds a service that implements the provided interface.
 java.lang.Object getService(java.lang.String serviceId, java.lang.Class serviceInterface, Module module)
          Obtains a service from the registry.
 java.lang.Object getServiceFromToken(ServiceToken token)
          Returns the service (proxy) for the indicated token.
 java.util.List getServiceIds(java.lang.Class serviceInterface)
           
 ServiceModelFactory getServiceModelFactory(java.lang.String name)
          Returns a named service-model factory
 ServicePoint getServicePoint(java.lang.String serviceId, Module module)
          Returns the identified service extension point.
 ServiceToken getServiceTokenForService(java.lang.String serviceId)
          Returns a ServiceToken corresponding to the indicated serviceId.
 Translator getTranslator(java.lang.String constructor)
          Gets a Translator instance.
 boolean isConfigurationMappable(java.lang.String configurationId, Module module)
          Returns true if the elements contributed to the given configuration point can be retrieved as a Map.
 void setShutdownCoordinator(ShutdownCoordinator coordinator)
           
 void setupThread()
          Sets the current RI up as the ServiceSerializationSupport.
 void shutdown()
          Invokes ShutdownCoordinator.shutdown(), then releases the coordinator, modules and variable sources.
 void startup()
          Starts up the Registry after all service and configuration points have been defined.
 java.lang.String toString()
           
 java.lang.String valueForSymbol(java.lang.String name)
          Returns the value for the symbol, if this source can provide one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RegistryInfrastructureImpl

public RegistryInfrastructureImpl(ErrorHandler errorHandler,
                                  java.util.Locale locale)
Method Detail

getLocale

public java.util.Locale getLocale()
Description copied from interface: RegistryInfrastructure
Returns the locale for which the registry was created.

Specified by:
getLocale in interface RegistryInfrastructure

addServicePoint

public void addServicePoint(ServicePoint point)

addConfigurationPoint

public void addConfigurationPoint(ConfigurationPoint point)

getServicePoint

public ServicePoint getServicePoint(java.lang.String serviceId,
                                    Module module)
Description copied from interface: RegistryInfrastructure
Returns the identified service extension point.

Specified by:
getServicePoint in interface RegistryInfrastructure
Parameters:
serviceId - fully qualified id of the service point
module - the referencing module, used for visibility checks (null means no module, which requires that the service be public)

getService

public java.lang.Object getService(java.lang.String serviceId,
                                   java.lang.Class serviceInterface,
                                   Module module)
Description copied from interface: RegistryInfrastructure
Obtains a service from the registry. Typically, what's returned is a proxy, but that's irrelevant to the caller, which simply will invoke methods of the service interface.

Specified by:
getService in interface RegistryInfrastructure
Parameters:
serviceId - the fully qualified id of the service to obtain
serviceInterface - the class to which the service will be cast
module - the referencing module, used for visibility checks (null means no module, which requires that the service be public)
Returns:
the service

getService

public java.lang.Object getService(java.lang.Class serviceInterface,
                                   Module module)
Description copied from interface: RegistryInfrastructure
Finds a service that implements the provided interface. Exactly one such service may exist or an exception is thrown.

Specified by:
getService in interface RegistryInfrastructure
Parameters:
serviceInterface - used to locate the service
module - the referencing module, used for visibility checks. If null, then only public service points will be considered.

getConfigurationPoint

public ConfigurationPoint getConfigurationPoint(java.lang.String configurationId,
                                                Module module)
Description copied from interface: RegistryInfrastructure
Returns the configuration point.

Specified by:
getConfigurationPoint in interface RegistryInfrastructure
Parameters:
configurationId - the fully qualified id of the configuration
module - the referencing module, used for visibility checks (null means no module, which requires that the configuration be public)
Returns:
ConfigurationPoint matching the configuration id

getConfiguration

public java.util.List getConfiguration(java.lang.String configurationId,
                                       Module module)
Description copied from interface: RegistryInfrastructure
Returns the converted items contributed to the configuration point.

Specified by:
getConfiguration in interface RegistryInfrastructure
Parameters:
configurationId - the fully qualified id of the configuration
module - the referencing module, used for visibility checks (null means no module, which requires that the configuration be public)
Returns:
List of converted elements

isConfigurationMappable

public boolean isConfigurationMappable(java.lang.String configurationId,
                                       Module module)
Description copied from interface: RegistryInfrastructure
Returns true if the elements contributed to the given configuration point can be retrieved as a Map.

Specified by:
isConfigurationMappable in interface RegistryInfrastructure
Parameters:
configurationId - the fully qualified id of the configuration
module - the referencing module, used for visibility checks (null means no module, which requires that the configuration be public)
See Also:
Module.isConfigurationMappable(String)

getConfigurationAsMap

public java.util.Map getConfigurationAsMap(java.lang.String configurationId,
                                           Module module)
Description copied from interface: RegistryInfrastructure
Returns the elements of the given configuration point as an unmodifiable Map. It may be empty, but not null.

Specified by:
getConfigurationAsMap in interface RegistryInfrastructure
Parameters:
configurationId - the fully qualified id of the configuration
module - the referencing module, used for visibility checks (null means no module, which requires that the configuration be public)
See Also:
Module.getConfigurationAsMap(String), #isConfigurationMappable(String)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

expandSymbols

public java.lang.String expandSymbols(java.lang.String text,
                                      Location location)
Description copied from interface: RegistryInfrastructure
Expands any substitution symbols in the input string, replacing each symbol with the symbols value (if known). If a symbol is unknown, then the symbol is passed through unchanged (complete with the ${ and } delimiters) and an error is logged.

Specified by:
expandSymbols in interface RegistryInfrastructure
Parameters:
text - input string to be converted, which may (or may not) contain any symbols.
location - the location from which the string was obtained, used if an error is logged.

valueForSymbol

public java.lang.String valueForSymbol(java.lang.String name)
Description copied from interface: SymbolSource
Returns the value for the symbol, if this source can provide one. Returns null if the source can not provide a value.

Specified by:
valueForSymbol in interface SymbolSource

setShutdownCoordinator

public void setShutdownCoordinator(ShutdownCoordinator coordinator)

shutdown

public void shutdown()
Invokes ShutdownCoordinator.shutdown(), then releases the coordinator, modules and variable sources.

Specified by:
shutdown in interface RegistryInfrastructure

startup

public void startup()
Starts up the Registry after all service and configuration points have been defined. This locks down the Registry so that no further extension points may be added. This method may only be invoked once.

This instance is stored into ServiceSerializationHelper.setServiceSerializationSupport(ServiceSerializationSupport). This may cause errors (and incorrect behavior) if multiple Registries exist in a single JVM.

In addition, the service hivemind.Startup is obtained and run() is invoked on it. This allows additional startup, provided in the hivemind.Startup configuration point, to be executed.

Specified by:
startup in interface RegistryInfrastructure

getServiceModelFactory

public ServiceModelFactory getServiceModelFactory(java.lang.String name)
Description copied from interface: RegistryInfrastructure
Returns a named service-model factory

Specified by:
getServiceModelFactory in interface RegistryInfrastructure

cleanupThread

public void cleanupThread()
Description copied from interface: RegistryInfrastructure
Convienience for invoking ThreadEventNotifier.fireThreadCleanup().

Specified by:
cleanupThread in interface RegistryInfrastructure

containsConfiguration

public boolean containsConfiguration(java.lang.String configurationId,
                                     Module module)
Description copied from interface: RegistryInfrastructure
Returns true if a configuration for the specified id exists (and is visible to the specified module).

Specified by:
containsConfiguration in interface RegistryInfrastructure
Parameters:
configurationId - to search for
module - the configuration must be visible to, or null for no module (the application's view
Returns:
true if a configuration for the specified id exists (and is visible to the module)

containsService

public boolean containsService(java.lang.Class serviceInterface,
                               Module module)
Description copied from interface: RegistryInfrastructure
Returns true if a single service exists which implements the specified service interface and is visible to the given module.

Specified by:
containsService in interface RegistryInfrastructure
module - the service must be visible to the module (or null for the application's view)
Returns:
true if a single visible service for the specified service interface exists

containsService

public boolean containsService(java.lang.String serviceId,
                               java.lang.Class serviceInterface,
                               Module module)
Description copied from interface: RegistryInfrastructure
Returns true if a single service with the given id exists which implements the specified service interface and is visible to the given module.

Specified by:
containsService in interface RegistryInfrastructure
module - the service must be visible to the module (or null for the application's view)
Returns:
true if a single visible service for the specified service id and service interface exists

getErrorHander

public ErrorHandler getErrorHander()
Description copied from interface: RegistryInfrastructure
Returns the ErrorHandler for this Registry.

Specified by:
getErrorHander in interface RegistryInfrastructure

getTranslator

public Translator getTranslator(java.lang.String constructor)
Description copied from interface: RegistryInfrastructure
Gets a Translator instance. The Translator may be a shared, cached instance (Translators should be stateless). Translators are identified by a constructor, which may be the name of a translator defined in the hivemind.Translators extension point (a single builtin translator, class, is hardcoded). Alternately, the name may consist of a translator name, a comma, and an initializer string for the service (example: int,min=5).

Specified by:
getTranslator in interface RegistryInfrastructure
Parameters:
constructor - the name and optional initialization of a Translator
Returns:
a Translator instance

getServiceFromToken

public java.lang.Object getServiceFromToken(ServiceToken token)
Description copied from interface: ServiceSerializationSupport
Returns the service (proxy) for the indicated token.

Specified by:
getServiceFromToken in interface ServiceSerializationSupport

getServiceTokenForService

public ServiceToken getServiceTokenForService(java.lang.String serviceId)
Description copied from interface: ServiceSerializationSupport
Returns a ServiceToken corresponding to the indicated serviceId. A ServiceToken takes the place of a service (proxy) during serialization.

Specified by:
getServiceTokenForService in interface ServiceSerializationSupport

setupThread

public void setupThread()
Sets the current RI up as the ServiceSerializationSupport. Any service proxy tokens that are de-serialized will find their proxies within this Registry.

Specified by:
setupThread in interface RegistryInfrastructure
Since:
1.1
See Also:
ServiceSerializationHelper, ServiceSerializationSupport

getModule

public Module getModule(java.lang.String moduleId)
Description copied from interface: RegistryInfrastructure
Returns the module with the corresponding module id.

Specified by:
getModule in interface RegistryInfrastructure
Returns:
the module with the corresponding module id

getServiceIds

public java.util.List getServiceIds(java.lang.Class serviceInterface)
Specified by:
getServiceIds in interface RegistryInfrastructure