com.cafesoft.core.service
Class AbstractLifecycleService

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

public abstract class AbstractLifecycleService
extends Object
implements LifecycleService

An abstract implementation of the LifecycleService interface. This case serves as a base class for all implementing LifecycleService classes.

Since:
07/25/2002

Field Summary
protected  boolean debug
          A flag that controls logging of DEBUG-level messages.
protected  boolean initialized
          Boolean flag to indicate that the service has been initialized.
protected  List listenerList
          List of Lifecycle listeners.
protected  Logger logger
          The Logger object associated with the ServiceConfig's ServiceContext.
protected  ServiceConfig serviceConfig
          The ServiceConfig object that configures this Service
protected  boolean started
          Boolean flag to indicate if the service has been started.
 
Fields inherited from interface com.cafesoft.core.lifecycle.Lifecycle
START_EVENT, STOP_EVENT
 
Constructor Summary
AbstractLifecycleService()
          Create a new AbstractLifecycleService.
 
Method Summary
 void addLifecycleListener(LifecycleListener listener)
          Add a LifecycleEvent listener to this component.
 void destroy()
          Destroy the Service.
protected  void fireEvent(LifecycleEvent event)
          Fire a lifecycle event to all registered listeners
 ServiceConfig getServiceConfig()
          Get the ServiceConfig.
 void initialize(ServiceConfig config)
          Initialize the Service.
 boolean isStarted()
          Determine if the implementing Lifecycle object has been started.
 void removeLifecycleListener(LifecycleListener listener)
          Remove a LifecycleEvent listener from this component.
 boolean setDebug(boolean enable)
          Enable or disable debugging.
abstract  void start()
          Prepare for the beginning of active use of the public methods of this component.
abstract  void stop()
          Gracefully terminate the active use of the public methods of this component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serviceConfig

protected ServiceConfig serviceConfig
The ServiceConfig object that configures this Service


logger

protected Logger logger
The Logger object associated with the ServiceConfig's ServiceContext.


started

protected boolean started
Boolean flag to indicate if the service has been started.


initialized

protected boolean initialized
Boolean flag to indicate that the service has been initialized.


listenerList

protected List listenerList
List of Lifecycle listeners.


debug

protected boolean debug
A flag that controls logging of DEBUG-level messages.

Constructor Detail

AbstractLifecycleService

public AbstractLifecycleService()
Create a new AbstractLifecycleService.

Just a reminder this is an abstract class, cannot be instantiated.

Method Detail

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

destroy

public void destroy()
Destroy the Service. (This method removes references to serviceConfig, logger, and listenerList, so subclasses should invoke it).

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.

start

public abstract 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 abstract 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

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

fireEvent

protected void fireEvent(LifecycleEvent event)
Fire a lifecycle event to all registered listeners

Parameters:
event - the event to send to the listeners


Generated on 10:40:31 AM September 10, 2003, © 1996-2003 Cafésoft LLC. All rights reserved.