Package org.apache.catalina.util
Class LifecycleBase
- java.lang.Object
- 
- org.apache.catalina.util.LifecycleBase
 
- 
- All Implemented Interfaces:
- Lifecycle
 - Direct Known Subclasses:
- AbstractResourceSet,- EmptyResourceSet,- LifecycleMBeanBase,- SessionIdGeneratorBase,- StandardPipeline,- StoreBase
 
 public abstract class LifecycleBase extends java.lang.Object implements Lifecycle Base implementation of theLifecycleinterface that implements the state transition rules forLifecycle.start()andLifecycle.stop()
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.apache.catalina.LifecycleLifecycle.SingleUse
 
- 
 - 
Field Summary- 
Fields inherited from interface org.apache.catalina.LifecycleAFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
 
- 
 - 
Constructor SummaryConstructors Constructor Description LifecycleBase()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddLifecycleListener(LifecycleListener listener)Add a LifecycleEvent listener to this component.voiddestroy()Prepare to discard the object.protected abstract voiddestroyInternal()Sub-classes implement this method to perform any instance destruction required.LifecycleListener[]findLifecycleListeners()Get the life cycle listeners associated with this life cycle.protected voidfireLifecycleEvent(java.lang.String type, java.lang.Object data)Allow sub classes to fireLifecycleevents.LifecycleStategetState()Obtain the current state of the source component.java.lang.StringgetStateName()Obtain a textual representation of the current component state.booleangetThrowOnFailure()Will aLifecycleExceptionthrown by a sub-class duringinitInternal(),startInternal(),stopInternal()ordestroyInternal()be re-thrown for the caller to handle or will it be logged instead?voidinit()Prepare the component for starting.protected abstract voidinitInternal()Sub-classes implement this method to perform any instance initialisation required.voidremoveLifecycleListener(LifecycleListener listener)Remove a LifecycleEvent listener from this component.protected voidsetState(LifecycleState state)Provides a mechanism for sub-classes to update the component state.protected voidsetState(LifecycleState state, java.lang.Object data)Provides a mechanism for sub-classes to update the component state.voidsetThrowOnFailure(boolean throwOnFailure)Configure if aLifecycleExceptionthrown by a sub-class duringinitInternal(),startInternal(),stopInternal()ordestroyInternal()will be re-thrown for the caller to handle or if it will be logged instead.voidstart()Prepare for the beginning of active use of the public methods other than property getters/setters and life cycle methods of this component.protected abstract voidstartInternal()Sub-classes must ensure that the state is changed toLifecycleState.STARTINGduring the execution of this method.voidstop()Gracefully terminate the active use of the public methods other than property getters/setters and life cycle methods of this component.protected abstract voidstopInternal()Sub-classes must ensure that the state is changed toLifecycleState.STOPPINGduring the execution of this method.
 
- 
- 
- 
Method Detail- 
getThrowOnFailurepublic boolean getThrowOnFailure() Will aLifecycleExceptionthrown by a sub-class duringinitInternal(),startInternal(),stopInternal()ordestroyInternal()be re-thrown for the caller to handle or will it be logged instead?- Returns:
- trueif the exception will be re-thrown, otherwise- false
 
 - 
setThrowOnFailurepublic void setThrowOnFailure(boolean throwOnFailure) Configure if aLifecycleExceptionthrown by a sub-class duringinitInternal(),startInternal(),stopInternal()ordestroyInternal()will be re-thrown for the caller to handle or if it will be logged instead.- Parameters:
- throwOnFailure-- trueif the exception should be re-thrown, otherwise- false
 
 - 
addLifecycleListenerpublic void addLifecycleListener(LifecycleListener listener) Add a LifecycleEvent listener to this component.- Specified by:
- addLifecycleListenerin interface- Lifecycle
- Parameters:
- listener- The listener to add
 
 - 
findLifecycleListenerspublic LifecycleListener[] findLifecycleListeners() Get the life cycle listeners associated with this life cycle.- Specified by:
- findLifecycleListenersin interface- Lifecycle
- Returns:
- An array containing the life cycle listeners associated with this life cycle. If this component has no listeners registered, a zero-length array is returned.
 
 - 
removeLifecycleListenerpublic void removeLifecycleListener(LifecycleListener listener) Remove a LifecycleEvent listener from this component.- Specified by:
- removeLifecycleListenerin interface- Lifecycle
- Parameters:
- listener- The listener to remove
 
 - 
fireLifecycleEventprotected void fireLifecycleEvent(java.lang.String type, java.lang.Object data)Allow sub classes to fireLifecycleevents.- Parameters:
- type- Event type
- data- Data associated with event.
 
 - 
initpublic final void init() throws LifecycleExceptionDescription copied from interface:LifecyclePrepare the component for starting. This method should perform any initialization required post object creation. The followingLifecycleEvents will be fired in the following order:- INIT_EVENT: On the successful completion of component initialization.
 - Specified by:
- initin interface- Lifecycle
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
initInternalprotected abstract void initInternal() throws LifecycleExceptionSub-classes implement this method to perform any instance initialisation required.- Throws:
- LifecycleException- If the initialisation fails
 
 - 
startpublic final void start() throws LifecycleExceptionPrepare for the beginning of active use of the public methods other than property getters/setters and life cycle methods of this component. This method should be called before any of the public methods other than property getters/setters and life cycle methods of this component are utilized. The followingLifecycleEvents will be fired in the following order:- BEFORE_START_EVENT: At the beginning of the method. It is as this
                           point the state transitions to
                           LifecycleState.STARTING_PREP.
- START_EVENT: During the method once it is safe to call start() for
                    any child components. It is at this point that the
                    state transitions to LifecycleState.STARTINGand that the public methods other than property getters/setters and life cycle methods may be used.
- AFTER_START_EVENT: At the end of the method, immediately before it
                          returns. It is at this point that the state
                          transitions to LifecycleState.STARTED.
 - Specified by:
- startin interface- Lifecycle
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
- BEFORE_START_EVENT: At the beginning of the method. It is as this
                           point the state transitions to
                           
 - 
startInternalprotected abstract void startInternal() throws LifecycleExceptionSub-classes must ensure that the state is changed toLifecycleState.STARTINGduring the execution of this method. Changing state will trigger theLifecycle.START_EVENTevent. If a component fails to start it may either throw aLifecycleExceptionwhich will cause it's parent to fail to start or it can place itself in the error state in which casestop()will be called on the failed component but the parent component will continue to start normally.- Throws:
- LifecycleException- Start error occurred
 
 - 
stoppublic final void stop() throws LifecycleExceptionGracefully terminate the active use of the public methods other than property getters/setters and life cycle methods of this component. Once the STOP_EVENT is fired, the public methods other than property getters/setters and life cycle methods should not be used. The followingLifecycleEvents will be fired in the following order:- BEFORE_STOP_EVENT: At the beginning of the method. It is at this
                          point that the state transitions to
                          LifecycleState.STOPPING_PREP.
- STOP_EVENT: During the method once it is safe to call stop() for
                   any child components. It is at this point that the
                   state transitions to LifecycleState.STOPPINGand that the public methods other than property getters/setters and life cycle methods may no longer be used.
- AFTER_STOP_EVENT: At the end of the method, immediately before it
                         returns. It is at this point that the state
                         transitions to LifecycleState.STOPPED.
 LifecycleState.FAILEDthen the three events above will be fired but the component will transition directly fromLifecycleState.FAILEDtoLifecycleState.STOPPING, bypassingLifecycleState.STOPPING_PREP- Specified by:
- stopin interface- Lifecycle
- Throws:
- LifecycleException- if this component detects a fatal error that needs to be reported
 
- BEFORE_STOP_EVENT: At the beginning of the method. It is at this
                          point that the state transitions to
                          
 - 
stopInternalprotected abstract void stopInternal() throws LifecycleExceptionSub-classes must ensure that the state is changed toLifecycleState.STOPPINGduring the execution of this method. Changing state will trigger theLifecycle.STOP_EVENTevent.- Throws:
- LifecycleException- Stop error occurred
 
 - 
destroypublic final void destroy() throws LifecycleExceptionDescription copied from interface:LifecyclePrepare to discard the object. The followingLifecycleEvents will be fired in the following order:- DESTROY_EVENT: On the successful completion of component destruction.
 - Specified by:
- destroyin interface- Lifecycle
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
destroyInternalprotected abstract void destroyInternal() throws LifecycleExceptionSub-classes implement this method to perform any instance destruction required.- Throws:
- LifecycleException- If the destruction fails
 
 - 
getStatepublic LifecycleState getState() Obtain the current state of the source component.
 - 
getStateNamepublic java.lang.String getStateName() Obtain a textual representation of the current component state. Useful for JMX. The format of this string may vary between point releases and should not be relied upon to determine component state. To determine component state, useLifecycle.getState().- Specified by:
- getStateNamein interface- Lifecycle
- Returns:
- The name of the current component state.
 
 - 
setStateprotected void setState(LifecycleState state) throws LifecycleException Provides a mechanism for sub-classes to update the component state. Calling this method will automatically fire any associatedLifecycleevent. It will also check that any attempted state transition is valid for a sub-class.- Parameters:
- state- The new state for this component
- Throws:
- LifecycleException- when attempting to set an invalid state
 
 - 
setStateprotected void setState(LifecycleState state, java.lang.Object data) throws LifecycleException Provides a mechanism for sub-classes to update the component state. Calling this method will automatically fire any associatedLifecycleevent. It will also check that any attempted state transition is valid for a sub-class.- Parameters:
- state- The new state for this component
- data- The data to pass to the associated- Lifecycleevent
- Throws:
- LifecycleException- when attempting to set an invalid state
 
 
- 
 
-