com.cafesoft.core.service
Class StandardServiceManager

java.lang.Object
  |
  +--com.cafesoft.core.service.StandardServiceManager
All Implemented Interfaces:
Debuggable, Lifecycle, LifecycleService, Service, ServiceManager
Direct Known Subclasses:
StandardServiceProvider

public class StandardServiceManager
extends Object
implements ServiceManager

StandardServiceManager implements a ServiceManager, which provides a way to register, lookup, and remove Service implementations. A Service is uniquely identified within a ServiceManager by it's identifier, but is also characterized by the interface that it implements.


Field Summary
protected  ServiceConfig serviceConfig
          The ServiceConfig for this ServiceManager (because it's also a Service).
 
Fields inherited from interface com.cafesoft.core.lifecycle.Lifecycle
START_EVENT, STOP_EVENT
 
Constructor Summary
StandardServiceManager()
          Create a new StandardServiceManager.
 
Method Summary
 void add(Class type, Service service)
          Add a Service to the registry.
 void addLifecycleListener(LifecycleListener listener)
          Add a LifecycleEvent listener to this component.
 void destroy()
          Destroy all Objects referenced by this ServiceManager.
protected  void finalize()
          Cleanup Object references.
 ServiceConfig getServiceConfig()
          Get the ServiceConfig.
 Service[] getServices()
          Returns all of the Services in the registry.
 void initialize(ServiceConfig config)
          Initialize the Service.
 boolean isStarted()
          Determine if the implementing Lifecycle object has been started.
 Service[] lookup(Class type)
          Lookup Services from the registry by type.
 Service lookup(String id)
          Lookup a Service from the registry by unique identifier.
 Service lookup(String id, Class type)
          Lookup a Service from the registry by unique identifier and type.
 void remove(Service service)
          Remove a Service from the registry.
 void removeLifecycleListener(LifecycleListener listener)
          Remove a LifecycleEvent listener from this component.
 boolean setDebug(boolean enable)
          Enable or disable debugging.
 void setServiceStarter(ServiceStarter serviceStarter)
          Set a ServiceStarter.
 void setServiceStopper(ServiceStopper serviceStopper)
          Set a ServiceStopper.
 void start()
          Prepare for the beginning of active use of the public methods of this component.
 void stop()
          Gracefully terminate the active use of the public methods of this component.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serviceConfig

protected ServiceConfig serviceConfig
The ServiceConfig for this ServiceManager (because it's also a Service).

Constructor Detail

StandardServiceManager

public StandardServiceManager()
Create a new StandardServiceManager.

Method Detail

finalize

protected void finalize()
                 throws Throwable
Cleanup Object references.

Overrides:
finalize in class Object
Throwable

initialize

public void initialize(ServiceConfig config)
                throws ServiceException
Initialize the Service.

Specified by:
initialize in interface Service
Parameters:
config - the ServiceConfig
Throws:
ServiceException - if an error initializing the Service

getServiceConfig

public ServiceConfig getServiceConfig()
Get the ServiceConfig.

Specified by:
getServiceConfig in interface Service
Returns:
the ServiceConfig

add

public void add(Class type,
                Service service)
         throws ServiceException
Add a Service to the registry.

Specified by:
add in interface ServiceManager
Parameters:
type - the Class that identifies the type of service.
service - the Service to be added.
Throws:
ServiceException - if the service is already registered.

remove

public void remove(Service service)
            throws ServiceException
Remove a Service from the registry.

Specified by:
remove in interface ServiceManager
Parameters:
service - the Service to be removed.
Throws:
ServiceException - if the service is not registered.

getServices

public Service[] getServices()
Returns all of the Services in the registry.

Specified by:
getServices in interface ServiceManager
Returns:
all of the Services in the registry

lookup

public Service[] lookup(Class type)
                 throws ServiceException
Lookup Services from the registry by type.

Specified by:
lookup in interface ServiceManager
Parameters:
type - the Service Class.
Returns:
an array of Service instances implemented by the specified type.
Throws:
ServiceException - if no service with the specified type is registered.

lookup

public Service lookup(String id)
               throws ServiceException
Lookup a Service from the registry by unique identifier.

Specified by:
lookup in interface ServiceManager
Parameters:
id - the Service identifier.
Returns:
the Service with the specified identifier.
Throws:
ServiceException - if no service with the specified identifier is registered.

lookup

public Service lookup(String id,
                      Class type)
               throws ServiceException
Lookup a Service from the registry by unique identifier and type.

Specified by:
lookup in interface ServiceManager
Parameters:
id - the Service identifier.
type - the Service type.
Returns:
the Service with the specified identifier and type.
Throws:
ServiceException - if no service with the specified identifier and type is registered.

setServiceStarter

public void setServiceStarter(ServiceStarter serviceStarter)
Set a ServiceStarter.

Specified by:
setServiceStarter in interface ServiceManager
Parameters:
serviceStarter - the ServiceStarter that will handle startup of Service instances when this ServiceManager is started, or null if the default ServiceManager startup behaviour is desired.

setServiceStopper

public void setServiceStopper(ServiceStopper serviceStopper)
Set a ServiceStopper.

Specified by:
setServiceStopper in interface ServiceManager
Parameters:
serviceStopper - the ServiceStopper that will handle stopping of Service instances when this ServiceManager is stopped, or null if the default ServiceManager stopping behaviour is desired.

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a LifecycleEvent listener to this component.

Specified by:
addLifecycleListener in interface Lifecycle
Parameters:
listener - The listener to add

removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)
Remove a LifecycleEvent listener from this component.

Specified by:
removeLifecycleListener in interface Lifecycle
Parameters:
listener - The listener to remove

start

public void start()
           throws LifecycleException
Prepare for the beginning of active use of the public methods of this component. This method should be called before any of the public methods of this component are utilized. It should also send a LifecycleEvent of type START_EVENT to any registered listeners.

Specified by:
start in interface Lifecycle
Throws:
IllegalStateException - if this component has already been started
LifecycleException - if this component detects a fatal error that prevents this component from being used

stop

public void stop()
          throws LifecycleException
Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component. It should also send a LifecycleEvent of type STOP_EVENT to any registered listeners.

Specified by:
stop in interface Lifecycle
Throws:
IllegalStateException - if this component has not been started
LifecycleException - if this component detects a fatal error that needs to be reported

isStarted

public boolean isStarted()
Determine if the implementing Lifecycle object has been started.

Specified by:
isStarted in interface Lifecycle
Returns:
true if the Lifecycle object has been started, false otherwise.

destroy

public void destroy()
Destroy all Objects referenced by this ServiceManager.

Specified by:
destroy in interface Service

setDebug

public boolean setDebug(boolean enable)
Enable or disable debugging.

Specified by:
setDebug in interface Debuggable
Parameters:
enable - if true, enable debugging, else disable debugging.
Returns:
the previous value of the debug flag, which is useful for restoring the debug state if temporarily changed.


Generated on 8:41:50 AM June 06, 2005, © 1996-2005 Cafésoft LLC. All rights reserved.