Top Description Fields Constructors Methods
org.apache.catalina.util

public abstract Class LifecycleBase

extends Object
implements Lifecycle
Class Inheritance
All Implemented Interfaces
org.apache.catalina.Lifecycle
Known Direct Subclasses
org.apache.catalina.util.LifecycleMBeanBase, org.apache.catalina.util.SessionIdGeneratorBase, org.apache.catalina.webresources.AbstractResourceSet, org.apache.catalina.webresources.EmptyResourceSet, org.apache.catalina.core.StandardPipeline, org.apache.catalina.session.StoreBase
Imports
java.util.List, java.util.concurrent.CopyOnWriteArrayList, org.apache.catalina.Lifecycle, .LifecycleEvent, .LifecycleException, .LifecycleListener, .LifecycleState, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.ExceptionUtils, org.apache.tomcat.util.res.StringManager

Base implementation of the Lifecycle interface that implements the state transition rules for Lifecycle#start() and Lifecycle#stop()

Field Summary

Modifier and TypeField and Description
private final List<LifecycleListener>
lifecycleListeners

The list of registered LifecycleListeners for event notifications.

private static final Log
private static final StringManager
private volatile LifecycleState
state

The current state of the source component.

private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addLifecycleListener(LifecycleListener
The listener to add
listener
)

Implements org.apache.catalina.Lifecycle.addLifecycleListener.

Add a LifecycleEvent listener to this component.

public final synchronized void
destroy()

Implements org.apache.catalina.Lifecycle.destroy.

Prepare to discard the object.

protected abstract void
destroyInternal()

Sub-classes implement this method to perform any instance destruction required.

public LifecycleListener[]
findLifecycleListeners()

Implements org.apache.catalina.Lifecycle.findLifecycleListeners.

Get the life cycle listeners associated with this life cycle.

protected void
fireLifecycleEvent(String
Event type
type
,
Object
Data associated with event.
data
)

Allow sub classes to fire Lifecycle events.

public LifecycleState
getState()

Implements org.apache.catalina.Lifecycle.getState.

Obtain the current state of the source component.

public String
getStateName()

Implements org.apache.catalina.Lifecycle.getStateName.

Obtain a textual representation of the current component state.

public boolean

Returns:

true if the exception will be re-thrown, otherwise false
getThrowOnFailure
()

Will a LifecycleException thrown by a sub-class during initInternal(), startInternal(), stopInternal() or destroyInternal() be re-thrown for the caller to handle or will it be logged instead?

private void
public final synchronized void
init()

Implements org.apache.catalina.Lifecycle.init.

Prepare the component for starting.

protected abstract void
initInternal()

Sub-classes implement this method to perform any instance initialisation required.

private void
public void
removeLifecycleListener(LifecycleListener
The listener to remove
listener
)

Implements org.apache.catalina.Lifecycle.removeLifecycleListener.

Remove a LifecycleEvent listener from this component.

protected synchronized void
setState(LifecycleState
The new state for this component
state
)

Provides a mechanism for sub-classes to update the component state.

protected synchronized void
setState(LifecycleState
The new state for this component
state
,
Object
The data to pass to the associated Lifecycle event
data
)

Provides a mechanism for sub-classes to update the component state.

private synchronized void
setStateInternal(LifecycleState state, Object data, boolean check)

public void
setThrowOnFailure(boolean
true if the exception should be re-thrown, otherwise false
throwOnFailure
)

Configure if a LifecycleException thrown by a sub-class during initInternal(), startInternal(), stopInternal() or destroyInternal() will be re-thrown for the caller to handle or if it will be logged instead.

public final synchronized void
start()

Implements org.apache.catalina.Lifecycle.start.

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 void
startInternal()

Sub-classes must ensure that the state is changed to LifecycleState#STARTING during the execution of this method.

public final synchronized void
stop()

Implements org.apache.catalina.Lifecycle.stop.

Gracefully terminate the active use of the public methods other than property getters/setters and life cycle methods of this component.

protected abstract void
stopInternal()

Sub-classes must ensure that the state is changed to LifecycleState#STOPPING during the execution of this method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lifecycleListenersback to summary
private final List<LifecycleListener> lifecycleListeners

The list of registered LifecycleListeners for event notifications.

logback to summary
private static final Log log
smback to summary
private static final StringManager sm
stateback to summary
private volatile LifecycleState state

The current state of the source component.

throwOnFailureback to summary
private boolean throwOnFailure

Constructor Detail

LifecycleBaseback to summary
public LifecycleBase()

Method Detail

addLifecycleListenerback to summary
public void addLifecycleListener(LifecycleListener listener)

Implements org.apache.catalina.Lifecycle.addLifecycleListener.

Doc from org.apache.catalina.Lifecycle.addLifecycleListener.

Add a LifecycleEvent listener to this component.

Parameters
listener:LifecycleListener

The listener to add

Annotations
@Override
destroyback to summary
public final synchronized void destroy() throws LifecycleException

Implements org.apache.catalina.Lifecycle.destroy.

Doc from org.apache.catalina.Lifecycle.destroy.

Prepare to discard the object. The following LifecycleEvents will be fired in the following order:

  1. DESTROY_EVENT: On the successful completion of component destruction.
Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that prevents this component from being used
destroyInternalback to summary
protected abstract void destroyInternal() throws LifecycleException

Sub-classes implement this method to perform any instance destruction required.

Exceptions
LifecycleException:
If the destruction fails
findLifecycleListenersback to summary
public LifecycleListener[] findLifecycleListeners()

Implements org.apache.catalina.Lifecycle.findLifecycleListeners.

Doc from org.apache.catalina.Lifecycle.findLifecycleListeners.

Get the life cycle listeners associated with this life cycle.

Returns:LifecycleListener[]

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.

Annotations
@Override
fireLifecycleEventback to summary
protected void fireLifecycleEvent(String type, Object data)

Allow sub classes to fire Lifecycle events.

Parameters
type:String

Event type

data:Object

Data associated with event.

getStateback to summary
public LifecycleState getState()

Implements org.apache.catalina.Lifecycle.getState.

Doc from org.apache.catalina.Lifecycle.getState.

Obtain the current state of the source component.

Returns:LifecycleState

The current state of the source component.

Annotations
@Override
getStateNameback to summary
public String getStateName()

Implements org.apache.catalina.Lifecycle.getStateName.

Doc from org.apache.catalina.Lifecycle.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, use getState().

Returns:String

The name of the current component state.

Annotations
@Override
getThrowOnFailureback to summary
public boolean getThrowOnFailure()

Will a LifecycleException thrown by a sub-class during initInternal(), startInternal(), stopInternal() or destroyInternal() be re-thrown for the caller to handle or will it be logged instead?

Returns:boolean

true if the exception will be re-thrown, otherwise false

handleSubClassExceptionback to summary
private void handleSubClassException(Throwable t, String key, Object... args) throws LifecycleException
initback to summary
public final synchronized void init() throws LifecycleException

Implements org.apache.catalina.Lifecycle.init.

Doc from org.apache.catalina.Lifecycle.init.

Prepare the component for starting. This method should perform any initialization required post object creation. The following LifecycleEvents will be fired in the following order:

  1. INIT_EVENT: On the successful completion of component initialization.
Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that prevents this component from being used
initInternalback to summary
protected abstract void initInternal() throws LifecycleException

Sub-classes implement this method to perform any instance initialisation required.

Exceptions
LifecycleException:
If the initialisation fails
invalidTransitionback to summary
private void invalidTransition(String type) throws LifecycleException
removeLifecycleListenerback to summary
public void removeLifecycleListener(LifecycleListener listener)

Implements org.apache.catalina.Lifecycle.removeLifecycleListener.

Doc from org.apache.catalina.Lifecycle.removeLifecycleListener.

Remove a LifecycleEvent listener from this component.

Parameters
listener:LifecycleListener

The listener to remove

Annotations
@Override
setStateback to summary
protected synchronized void setState(LifecycleState state) throws LifecycleException

Provides a mechanism for sub-classes to update the component state. Calling this method will automatically fire any associated Lifecycle event. It will also check that any attempted state transition is valid for a sub-class.

Parameters
state:LifecycleState

The new state for this component

Exceptions
LifecycleException:
when attempting to set an invalid state
setStateback to summary
protected synchronized void setState(LifecycleState state, Object data) throws LifecycleException

Provides a mechanism for sub-classes to update the component state. Calling this method will automatically fire any associated Lifecycle event. It will also check that any attempted state transition is valid for a sub-class.

Parameters
state:LifecycleState

The new state for this component

data:Object

The data to pass to the associated Lifecycle event

Exceptions
LifecycleException:
when attempting to set an invalid state
setStateInternalback to summary
private synchronized void setStateInternal(LifecycleState state, Object data, boolean check) throws LifecycleException
setThrowOnFailureback to summary
public void setThrowOnFailure(boolean throwOnFailure)

Configure if a LifecycleException thrown by a sub-class during initInternal(), startInternal(), stopInternal() or destroyInternal() will be re-thrown for the caller to handle or if it will be logged instead.

Parameters
throwOnFailure:boolean

true if the exception should be re-thrown, otherwise false

startback to summary
public final synchronized void start() throws LifecycleException

Implements org.apache.catalina.Lifecycle.start.

Doc from org.apache.catalina.Lifecycle.start.

Prepare 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 following LifecycleEvents will be fired in the following order:

  1. BEFORE_START_EVENT: At the beginning of the method. It is as this point the state transitions to LifecycleState#STARTING_PREP.
  2. 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#STARTING and that the public methods other than property getters/setters and life cycle methods may be used.
  3. 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.
Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that prevents this component from being used
startInternalback to summary
protected abstract void startInternal() throws LifecycleException

Sub-classes must ensure that the state is changed to LifecycleState#STARTING during the execution of this method. Changing state will trigger the Lifecycle#START_EVENT event. If a component fails to start it may either throw a LifecycleException which will cause it's parent to fail to start or it can place itself in the error state in which case stop() will be called on the failed component but the parent component will continue to start normally.

Exceptions
LifecycleException:
Start error occurred
stopback to summary
public final synchronized void stop() throws LifecycleException

Implements org.apache.catalina.Lifecycle.stop.

Doc from org.apache.catalina.Lifecycle.stop.

Gracefully 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 following LifecycleEvents will be fired in the following order:

  1. BEFORE_STOP_EVENT: At the beginning of the method. It is at this point that the state transitions to LifecycleState#STOPPING_PREP.
  2. 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#STOPPING and that the public methods other than property getters/setters and life cycle methods may no longer be used.
  3. 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.
Note that if transitioning from LifecycleState#FAILED then the three events above will be fired but the component will transition directly from LifecycleState#FAILED to LifecycleState#STOPPING, bypassing LifecycleState#STOPPING_PREP
Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that needs to be reported
stopInternalback to summary
protected abstract void stopInternal() throws LifecycleException

Sub-classes must ensure that the state is changed to LifecycleState#STOPPING during the execution of this method. Changing state will trigger the Lifecycle#STOP_EVENT event.

Exceptions
LifecycleException:
Stop error occurred