org.apache.turbine.services
Class BaseServiceBroker

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitableBroker
        |
        +--org.apache.turbine.services.BaseServiceBroker
All Implemented Interfaces:
InitableBroker, ServiceBroker
Direct Known Subclasses:
TurbineServices

public abstract class BaseServiceBroker
extends BaseInitableBroker
implements ServiceBroker

A generic implementation of a ServiceBroker. Functionality that ServiceBroker provides in addition to InitableBroker functionality includes:

Version:
$Id$
Author:
Kevin Burton, Rafal Krzewski, Daniel Rall

Field Summary
protected  org.apache.velocity.runtime.configuration.Configuration mapping
          Mapping of Service names to class names.
protected  java.util.Hashtable services
          A repository of Service instances.
 
Fields inherited from class org.apache.turbine.services.BaseInitableBroker
initables, stack
 
Constructor Summary
protected BaseServiceBroker()
          Default constructor of InitableBorker.
 
Method Summary
private  void doInitService(java.lang.Object data, java.lang.String name)
          Internal utility method for use in initServices() to prevent duplication of code.
 org.apache.velocity.runtime.configuration.Configuration getConfiguration(java.lang.String name)
          Returns the Configuration of a specific service.
 java.util.Properties getProperties(java.lang.String name)
          Returns the properites of a specific 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.
 void initService(java.lang.String name, java.lang.Object data)
          Performs early initialization of specified service.
 void initServices(java.lang.Object data)
          Performs early initialization of all services.
 void initServices(java.lang.Object data, boolean report)
          Performs early initiailzation of all services.
 boolean isRegistered(java.lang.String serviceName)
          Determines whether a service is registered in the configured TurbineResources.properties.
 void shutdownService(java.lang.String name)
          Shuts down a Service.
 void shutdownServices()
          Shuts down all Turbine services, releasing allocated resources and returning them to their initial (uninitailized) state.
 
Methods inherited from class org.apache.turbine.services.BaseInitableBroker
error, getInitable, getInitableInstance, initClass, notice, shutdownClass
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.InitableBroker
getInitable, initClass, shutdownClass
 

Field Detail

mapping

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

services

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

BaseServiceBroker

protected BaseServiceBroker()
Default constructor of InitableBorker. This constructor does nothing.
Method Detail

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.

initService

public void initService(java.lang.String name,
                        java.lang.Object data)
                 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).
data - An object to use for initialization activities.
Throws:
InitializationException - Initilaization of this service was not successful.

initServices

public void initServices(java.lang.Object data)
Performs early initialization of all services. Failed early initialization of a Service may be non-fatal to the system, thuss the exceptions are logged and then discarded.
Specified by:
initServices in interface ServiceBroker
Parameters:
data - An Object to use for initialization activities.

initServices

public void initServices(java.lang.Object data,
                         boolean report)
                  throws InstantiationException,
                         InitializationException
Performs early initiailzation of all services. You can decide to handle failed initizalizations if you wish, but then after one service fails, the other will not have the chance to initialize.
Parameters:
data - An Object to use for initialization activities.
report - true if you want exceptions thrown.

doInitService

private void doInitService(java.lang.Object data,
                           java.lang.String name)
                    throws InstantiationException,
                           InitializationException
Internal utility method for use in initServices() to prevent duplication of code.

shutdownService

public void shutdownService(java.lang.String name)
Shuts down a Service. This method is used to release resources allocated by a Service, and return it to its initial (uninitailized) 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 (uninitailized) 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 accesing the Services instances.
Parameters:
name - The name of the service requested.
Throws:
InstantiationException, - if the service is unknown or can't be initialized.

getProperties

public java.util.Properties getProperties(java.lang.String name)
Returns the properites of a specific service. Generic ServiceBroker returns empty set of Properties.
Specified by:
getProperties in interface ServiceBroker
Parameters:
name - The name of the service.
Returns:
Properties of requested Service.

getConfiguration

public org.apache.velocity.runtime.configuration.Configuration getConfiguration(java.lang.String name)
Returns the Configuration of a specific service. Generic ServiceBroker returns empty Configuration
Specified by:
getConfiguration in interface ServiceBroker
Parameters:
name - The name of the service.
Returns:
Properties of requested Service.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.