solar.service
Class BaseServiceManager

java.lang.Object
  |
  +--solar.service.BaseServiceManager
All Implemented Interfaces:
ServiceManager
Direct Known Subclasses:
SolarServices

public class BaseServiceManager
extends java.lang.Object
implements ServiceManager

A base implementation of service manager.

Version:
$Id: BaseServiceManager.java,v 1.11 2003/10/02 06:14:28 glchen Exp $
Author:
Guanling Chen

Field Summary
protected  serp.util.Options _config
          Configurations used for all the services.
protected static org.apache.log4j.Logger _log
          Logging facility.
protected  java.util.Hashtable _mapping
          Mapping of service names to class names.
protected  java.util.Hashtable _serviceObjects
          A repository of application-specific service objects.
protected  java.util.Hashtable _services
          A repository of service instances.
static java.lang.String CLASSNAME_SUFFIX
          A service property determining its implementing class name.
static java.lang.String SERVICE_PREFIX
          A prefix for service properties configuration file.
 
Constructor Summary
protected BaseServiceManager()
           
 
Method Summary
 Service getService(java.lang.String name)
          Return an instance of specified service.
 serp.util.Options getServiceConfig(java.lang.String name)
          Return the configuration of a specified service.
private  Service getServiceInstance(java.lang.String name)
          Retrieves an instance of a service without triggering late initialization.
 java.lang.Object getServiceObject(java.lang.String name)
          Get an application-specific service object.
 boolean hasRegistered(java.lang.String name)
          Determines whether a service is registered.
 void init(serp.util.Options opts)
          Init the service manager with configurations of all services.
private  void initMapping()
          Creates a mapping between service names and class names.
private  void initServices()
          Performs early initialization of all needed services.
 void setServiceObject(java.lang.String name, java.lang.Object obj)
          Set application-specific service object.
 void stopService(java.lang.String name)
          Stop a specified service.
 void stopServices()
          Stop all services.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE_PREFIX

public static final java.lang.String SERVICE_PREFIX
A prefix for service properties configuration file.

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

_log

protected static org.apache.log4j.Logger _log
Logging facility.


_config

protected serp.util.Options _config
Configurations used for all the services.


_mapping

protected java.util.Hashtable _mapping
Mapping of service names to class names.


_services

protected java.util.Hashtable _services
A repository of service instances.


_serviceObjects

protected java.util.Hashtable _serviceObjects
A repository of application-specific service objects.

Constructor Detail

BaseServiceManager

protected BaseServiceManager()
Method Detail

init

public void init(serp.util.Options opts)
          throws ServiceException
Description copied from interface: ServiceManager
Init the service manager with configurations of all services.

Specified by:
init in interface ServiceManager
ServiceException

hasRegistered

public boolean hasRegistered(java.lang.String name)
Description copied from interface: ServiceManager
Determines whether a service is registered.

Specified by:
hasRegistered in interface ServiceManager

getService

public Service getService(java.lang.String name)
                   throws ServiceException
Description copied from interface: ServiceManager
Return an instance of specified service.

Specified by:
getService in interface ServiceManager
ServiceException

getServiceConfig

public serp.util.Options getServiceConfig(java.lang.String name)
                                   throws ServiceException
Description copied from interface: ServiceManager
Return the configuration of a specified service.

Specified by:
getServiceConfig in interface ServiceManager
ServiceException

setServiceObject

public void setServiceObject(java.lang.String name,
                             java.lang.Object obj)
Description copied from interface: ServiceManager
Set application-specific service object.

Specified by:
setServiceObject in interface ServiceManager

getServiceObject

public java.lang.Object getServiceObject(java.lang.String name)
Description copied from interface: ServiceManager
Get an application-specific service object.

Specified by:
getServiceObject in interface ServiceManager

stopService

public void stopService(java.lang.String name)
Description copied from interface: ServiceManager
Stop a specified service.

Specified by:
stopService in interface ServiceManager

stopServices

public void stopServices()
Description copied from interface: ServiceManager
Stop all services.

Specified by:
stopServices in interface ServiceManager

initMapping

private void initMapping()
Creates a mapping between service names and class names. The mapping is built according to settings present in configuration file. The entries should have the following form:
 service.MyService.classname=com.mycompany.MyServiceImpl
 service.MyOtherService.classname=com.mycompany.MyOtherServiceImpl
 


initServices

private void initServices()
                   throws ServiceException
Performs early initialization of all needed services.

ServiceException

getServiceInstance

private Service getServiceInstance(java.lang.String name)
                            throws ServiceException
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 ServiceManager set by then. Therefore, before calling Initable.initClass(Object), the class must be instantiated with InitableBroker.getInitableInstance(), and Service.setManagerBroker() and Service.setName() must be called. This calls for two - level accessing the services instances.

ServiceException