com.cafesoft.core.lifecycle
Class LifecycleBase

java.lang.Object
  |
  +--com.cafesoft.core.lifecycle.LifecycleBase
All Implemented Interfaces:
Lifecycle

public class LifecycleBase
extends Object
implements Lifecycle

A base implementation of the Lifecycle interface.

It is expected that any class that wants to implement the Lifecycle interface essentially extend this base class. It provides mechanisms to fireLifecycle events and provides certain instance variables that prove to be useful in the implementing Lifecycle objects.

Since:
12/5/01
See Also:
Lifecycle

Field Summary
protected  boolean started
          a boolean flag used to indicate whether the service has started or not.
 
Fields inherited from interface com.cafesoft.core.lifecycle.Lifecycle
START_EVENT, STOP_EVENT
 
Constructor Summary
LifecycleBase()
          Create a new LifecycleBase object
 
Method Summary
 void addLifecycleListener(LifecycleListener listener)
          Add a LifecycleEvent listener to this component.
 void fireLifecycleEvent(String type, Object data)
          Notify all lifecycle event listeners that a particular event has occurred for this Container.
 boolean isStarted()
          Determine if the implementing Lifecycle object has been started.
 void removeLifecycleListener(LifecycleListener listener)
          Remove a LifecycleEvent listener from this component.
 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, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

started

protected boolean started
a boolean flag used to indicate whether the service has started or not.

Constructor Detail

LifecycleBase

public LifecycleBase()
Create a new LifecycleBase object

Method Detail

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

addLifecycleListener

public final 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 final void removeLifecycleListener(LifecycleListener listener)
Remove a LifecycleEvent listener from this component.

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

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.

fireLifecycleEvent

public void fireLifecycleEvent(String type,
                               Object data)
Notify all lifecycle event listeners that a particular event has occurred for this Container. The default implementation performs this notification synchronously using the calling thread.

Parameters:
type - Event type
data - Event data


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