org.apache.turbine.services
Class BaseServiceBroker

java.lang.Object
  extended byorg.apache.turbine.services.BaseServiceBroker
All Implemented Interfaces:
ServiceBroker
Direct Known Subclasses:
TurbineServices

public abstract class BaseServiceBroker
extends java.lang.Object
implements ServiceBroker

A generic implementation of a ServiceBroker which provides:

Version:
$Id: BaseServiceBroker.java 534527 2007-05-02 16:10:59Z tv $
Author:
Kevin Burton, Rafal Krzewski, Daniel Rall, Jason van Zyl, Martin Poeschl, Henning P. Schmiedehausen

Field Summary
protected  java.lang.String applicationRoot
          Application root path as set by the parent application.
static java.lang.String CLASSNAME_SUFFIX
          A Service property determining its implementing class name .
protected  org.apache.commons.configuration.Configuration configuration
          Configuration for the services broker.
protected  org.apache.commons.configuration.Configuration mapping
          Mapping of Service names to class names.
static java.lang.String SERVICE_PREFIX
          A prefix for Service properties in TurbineResource.properties.
protected  java.util.Hashtable serviceObjects
          These are objects that the parent application can provide so that application specific services have a mechanism to retrieve specialized information.
protected  java.util.Hashtable services
          A repository of Service instances.
 
Constructor Summary
protected BaseServiceBroker()
          Default constructor, protected as to only be useable by subclasses.
 
Method Summary
 java.lang.String getApplicationRoot()
          Get the application root as set by the parent application.
 org.apache.commons.configuration.Configuration getConfiguration()
          Get the configuration for this service manager.
 org.apache.commons.configuration.Configuration getConfiguration(java.lang.String name)
          Returns the configuration for the specified service.
 Service getService(java.lang.String name)
          Returns an instance of requested Service.
protected  Service getServiceInstance(java.lang.String name)
          Retrieves an instance of a Service without triggering late initialization.
 java.util.Iterator getServiceNames()
          Returns an Iterator over all known service names.
 java.util.Iterator getServiceNames(java.lang.String prefix)
          Returns an Iterator over all known service names beginning with the provided prefix.
 java.lang.Object getServiceObject(java.lang.String name)
          Get an application specific service object.
 void init()
          Initialize this service manager.
protected  void initMapping()
          Creates a mapping between Service names and class names.
 void initService(java.lang.String name)
          Performs early initialization of specified service.
 void initServices()
          Performs early initialization of all services.
 void initServices(boolean report)
          Performs early initialization of all services.
 boolean isRegistered(java.lang.String serviceName)
          Determines whether a service is registered in the configured TurbineResources.properties.
 void setApplicationRoot(java.lang.String applicationRoot)
          Set the application root.
 void setConfiguration(org.apache.commons.configuration.Configuration configuration)
          Set the configuration object for the services broker.
 void setServiceObject(java.lang.String name, java.lang.Object value)
          Set an application specific service object that can be used by application specific services.
 void shutdownService(java.lang.String name)
          Shuts down a Service, releasing resources allocated by an Service, and returns it to its initial (uninitialized) state.
 void shutdownServices()
          Shuts down all Turbine services, releasing allocated resources and returning them to their initial (uninitialized) state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapping

protected org.apache.commons.configuration.Configuration mapping
Mapping of Service names to class names.


services

protected java.util.Hashtable services
A repository of Service instances.


configuration

protected org.apache.commons.configuration.Configuration configuration
Configuration for the services broker. The configuration should be set by the application in which the services framework is running.


SERVICE_PREFIX

public static final java.lang.String SERVICE_PREFIX
A prefix for Service properties in TurbineResource.properties.

See Also:
Constant Field Values

CLASSNAME_SUFFIX

public static final java.lang.String CLASSNAME_SUFFIX
A Service property determining its implementing class name .

See Also:
Constant Field Values

serviceObjects

protected java.util.Hashtable serviceObjects
These are objects that the parent application can provide so that application specific services have a mechanism to retrieve specialized information. For example, in Turbine there are services that require the RunData object: these services can retrieve the RunData object that Turbine has placed in the service manager. This alleviates us of the requirement of having init(Object) all together.


applicationRoot

protected java.lang.String applicationRoot
Application root path as set by the parent application.

Constructor Detail

BaseServiceBroker

protected BaseServiceBroker()
Default constructor, protected as to only be useable by subclasses. This constructor does nothing.

Method Detail

setConfiguration

public void setConfiguration(org.apache.commons.configuration.Configuration configuration)
Set the configuration object for the services broker. This is the configuration that contains information about all services in the care of this service manager.

Parameters:
configuration - Broker configuration.

getConfiguration

public org.apache.commons.configuration.Configuration getConfiguration()
Get the configuration for this service manager.

Returns:
Broker configuration.

init

public void init()
          throws InitializationException
Initialize this service manager.

Throws:
InitializationException

setServiceObject

public void setServiceObject(java.lang.String name,
                             java.lang.Object value)
Set an application specific service object that can be used by application specific services.

Parameters:
name - name of service object
value - value of service object

getServiceObject

public java.lang.Object getServiceObject(java.lang.String name)
Get an application specific service object.

Returns:
Object application specific service object

initMapping

protected void initMapping()
Creates a mapping between Service names and class names. The mapping is built according to settings present in TurbineResources.properties. The entries should have the following form:
 services.MyService.classname=com.mycompany.MyServiceImpl
 services.MyOtherService.classname=com.mycompany.MyOtherServiceImpl
 

Generic ServiceBroker provides no Services.


isRegistered

public boolean isRegistered(java.lang.String serviceName)
Determines whether a service is registered in the configured TurbineResources.properties.

Specified by:
isRegistered in interface ServiceBroker
Parameters:
serviceName - The name of the service whose existance to check.
Returns:
Registration predicate for the desired services.

getServiceNames

public java.util.Iterator getServiceNames()
Returns an Iterator over all known service names.

Returns:
An Iterator of service names.

getServiceNames

public java.util.Iterator getServiceNames(java.lang.String prefix)
Returns an Iterator over all known service names beginning with the provided prefix.

Parameters:
prefix - The prefix against which to test.
Returns:
An Iterator of service names which match the prefix.

initService

public void initService(java.lang.String name)
                 throws InitializationException
Performs early initialization of specified service.

Specified by:
initService in interface ServiceBroker
Parameters:
name - The name of the service (generally the SERVICE_NAME constant of the service's interface definition).
Throws:
InitializationException - Initialization of this service was not successful.

initServices

public void initServices()
Performs early initialization of all services. Failed early initialization of a Service may be non-fatal to the system, thus any exceptions are logged and the initialization process continues.


initServices

public void initServices(boolean report)
                  throws InstantiationException,
                         InitializationException
Performs early initialization of all services. You can decide to handle failed initializations if you wish, but then after one service fails, the other will not have the chance to initialize.

Parameters:
report - true if you want exceptions thrown.
Throws:
InstantiationException
InitializationException

shutdownService

public void shutdownService(java.lang.String name)
Shuts down a Service, releasing resources allocated by an Service, and returns it to its initial (uninitialized) state.

Specified by:
shutdownService in interface ServiceBroker
Parameters:
name - The name of the Service to be uninitialized.

shutdownServices

public void shutdownServices()
Shuts down all Turbine services, releasing allocated resources and returning them to their initial (uninitialized) state.

Specified by:
shutdownServices in interface ServiceBroker

getService

public Service getService(java.lang.String name)
                   throws InstantiationException
Returns an instance of requested Service.

Specified by:
getService in interface ServiceBroker
Parameters:
name - The name of the Service requested.
Returns:
An instance of requested Service.
Throws:
InstantiationException - if the service is unknown or can't be initialized.

getServiceInstance

protected Service getServiceInstance(java.lang.String name)
                              throws InstantiationException
Retrieves an instance of a Service without triggering late initialization. Early initialization of a Service can require access to Service properties. The Service must have its name and serviceBroker set by then. Therefore, before calling Initable.initClass(Object), the class must be instantiated with InitableBroker.getInitableInstance(), and Service.setServiceBroker() and Service.setName() must be called. This calls for two - level accessing the Services instances.

Parameters:
name - The name of the service requested.
Throws:
InstantiationException - The service is unknown or can't be initialized.

getConfiguration

public org.apache.commons.configuration.Configuration getConfiguration(java.lang.String name)
Returns the configuration for the specified service.

Specified by:
getConfiguration in interface ServiceBroker
Parameters:
name - The name of the service.
Returns:
Configuration of requested Service.

setApplicationRoot

public void setApplicationRoot(java.lang.String applicationRoot)
Set the application root.

Parameters:
applicationRoot - application root

getApplicationRoot

public java.lang.String getApplicationRoot()
Get the application root as set by the parent application.

Returns:
String application root


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.