org.apache.catalina.core

Class ContainerBase

public abstract class ContainerBase extends Object implements Container, Lifecycle, Pipeline, MBeanRegistration, Serializable

Abstract implementation of the Container interface, providing common functionality required by nearly every implementation. Classes extending this base class must implement getInfo(), and may implement a replacement for invoke().

All subclasses of this abstract base class will include support for a Pipeline object that defines the processing to be performed for each request received by the invoke() method of this class, utilizing the "Chain of Responsibility" design pattern. A subclass should encapsulate its own processing functionality as a Valve, and configure this Valve into the pipeline by calling setBasic().

This implementation fires property change events, per the JavaBeans design pattern, for changes in singleton properties. In addition, it fires the following ContainerEvent events to listeners who register themselves with addContainerListener():

Type Data Description
addChild Container Child container added to this Container.
addValve Valve Valve added to this Container.
removeChild Container Child container removed from this Container.
removeValve Valve Valve removed from this Container.
start null Container was started.
stop null Container was stopped.
Subclasses that fire additional events should document them in the class comments of the implementation class.

Author: Craig R. McClanahan

Nested Class Summary
protected classContainerBase.ContainerBackgroundProcessor
Private thread class to invoke the backgroundProcess method of this container and its children after a fixed delay.
protected classContainerBase.PrivilegedAddChild
Perform addChild with the permissions of this class. addChild can be called with the XML parser on the stack, this allows the XML parser to have fewer privileges than Tomcat.
Field Summary
protected intbackgroundProcessorDelay
The processor delay for this component.
protected HashMapchildren
The child Containers belonging to this Container, keyed by name.
protected Clustercluster
The cluster with which this Container is associated.
protected ObjectNamecontroller
protected Stringdomain
protected booleaninitialized
protected LifecycleSupportlifecycle
The lifecycle event support for this component.
protected ArrayListlisteners
The container event listeners for this Container.
protected Loaderloader
The Loader implementation with which this Container is associated.
protected Loglogger
The Logger implementation with which this Container is associated.
protected StringlogName
Associated logger name.
protected Managermanager
The Manager implementation with which this Container is associated.
protected MBeanServermserver
protected Stringname
The human-readable name of this Container.
protected ObjectNameoname
protected Containerparent
The parent Container to which this Container is a child.
protected ClassLoaderparentClassLoader
The parent class loader to be configured when we install a Loader.
protected Pipelinepipeline
The Pipeline object with which this Container is associated.
protected Realmrealm
The Realm with which this Container is associated.
protected DirContextresources
The resources DirContext object with which this Container is associated.
protected static StringManagersm
The string manager for this package.
protected booleanstartChildren
Will children be started automatically when they are added.
protected booleanstarted
Has this component been started?
protected Stringsuffix
protected PropertyChangeSupportsupport
The property change support for this component.
protected Stringtype
Method Summary
voidaddChild(Container child)
Add a new child Container to those associated with this Container, if supported.
voidaddContainerListener(ContainerListener listener)
Add a container event listener to this component.
voidaddLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
voidaddPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.
voidaddValve(Valve valve)
Add a new Valve to the end of the pipeline associated with this Container.
voidbackgroundProcess()
Execute a periodic task, such as reloading, etc.
ObjectNamecreateObjectName(String domain, ObjectName parent)
voiddestroy()
ContainerfindChild(String name)
Return the child Container, associated with this Container, with the specified name (if any); otherwise, return null
Container[]findChildren()
Return the set of children Containers associated with this Container.
ContainerListener[]findContainerListeners()
Return the set of container listeners associated with this Container.
LifecycleListener[]findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle.
voidfireContainerEvent(String type, Object data)
Notify all container event listeners that a particular event has occurred for this Container.
intgetBackgroundProcessorDelay()
Get the delay between the invocation of the backgroundProcess method on this container and its children.
ValvegetBasic()

Return the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).

ObjectName[]getChildren()
ClustergetCluster()
Return the Cluster with which this Container is associated.
StringgetContainerSuffix()
StringgetDomain()
ValvegetFirst()
Return the first valve in the pipeline.
StringgetInfo()
Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.
ObjectNamegetJmxName()
protected StringgetJSR77Suffix()
LoadergetLoader()
Return the Loader with which this Container is associated.
LoggetLogger()
Return the Logger with which this Container is associated.
ManagergetManager()
Return the Manager with which this Container is associated.
ObjectgetMappingObject()
Return an object which may be utilized for mapping to this component.
StringgetName()
Return a name string (suitable for use by humans) that describes this Container.
StringgetObjectName()
ContainergetParent()
Return the Container for which this Container is a child, if there is one.
ClassLoadergetParentClassLoader()
Return the parent class loader (if any) for this web application.
ObjectNamegetParentName()
PipelinegetPipeline()
Return the Pipeline object that manages the Valves associated with this Container.
RealmgetRealm()
Return the Realm with which this Container is associated.
DirContextgetResources()
Return the resources DirContext object with which this Container is associated.
booleangetStartChildren()
Return if children of this container will be started automatically when they are added to this container.
StringgetType()
ObjectName[]getValveObjectNames()
Valve[]getValves()
Return the set of Valves in the pipeline associated with this Container, including the basic Valve (if any).
voidinit()
Init method, part of the MBean lifecycle.
voidinvoke(Request request, Response response)
Process the specified Request, to produce the corresponding Response, by invoking the first Valve in our pipeline (if any), or the basic Valve otherwise.
protected StringlogName()
Return the abbreviated name of this container for logging messsages
voidpostDeregister()
voidpostRegister(Boolean registrationDone)
voidpreDeregister()
ObjectNamepreRegister(MBeanServer server, ObjectName name)
voidremoveChild(Container child)
Remove an existing child Container from association with this parent Container.
voidremoveContainerListener(ContainerListener listener)
Remove a container event listener from this component.
voidremoveLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
voidremovePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.
voidremoveValve(Valve valve)
Remove the specified Valve from the pipeline associated with this Container, if it is found; otherwise, do nothing.
voidsetBackgroundProcessorDelay(int delay)
Set the delay between the invocation of the execute method on this container and its children.
voidsetBasic(Valve valve)

Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).

voidsetCluster(Cluster cluster)
Set the Cluster with which this Container is associated.
voidsetDomain(String domain)
voidsetLoader(Loader loader)
Set the Loader with which this Container is associated.
voidsetManager(Manager manager)
Set the Manager with which this Container is associated.
voidsetName(String name)
Set a name string (suitable for use by humans) that describes this Container.
voidsetParent(Container container)
Set the parent Container to which this Container is being added as a child.
voidsetParentClassLoader(ClassLoader parent)
Set the parent class loader (if any) for this web application.
voidsetRealm(Realm realm)
Set the Realm with which this Container is associated.
voidsetResources(DirContext resources)
Set the resources DirContext object with which this Container is associated.
voidsetStartChildren(boolean startChildren)
Set if children of this container will be started automatically when they are added to this container.
voidstart()
Prepare for active use of the public methods of this Component.
voidstop()
Gracefully shut down active use of the public methods of this Component.
protected voidthreadStart()
Start the background thread that will periodically check for session timeouts.
protected voidthreadStop()
Stop the background thread that is periodically checking for session timeouts.

Field Detail

backgroundProcessorDelay

protected int backgroundProcessorDelay
The processor delay for this component.

children

protected HashMap children
The child Containers belonging to this Container, keyed by name.

cluster

protected Cluster cluster
The cluster with which this Container is associated.

controller

protected ObjectName controller

domain

protected String domain

initialized

protected boolean initialized

lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.

listeners

protected ArrayList listeners
The container event listeners for this Container.

loader

protected Loader loader
The Loader implementation with which this Container is associated.

logger

protected Log logger
The Logger implementation with which this Container is associated.

logName

protected String logName
Associated logger name.

manager

protected Manager manager
The Manager implementation with which this Container is associated.

mserver

protected transient MBeanServer mserver

name

protected String name
The human-readable name of this Container.

oname

protected ObjectName oname

parent

protected Container parent
The parent Container to which this Container is a child.

parentClassLoader

protected ClassLoader parentClassLoader
The parent class loader to be configured when we install a Loader.

pipeline

protected Pipeline pipeline
The Pipeline object with which this Container is associated.

realm

protected Realm realm
The Realm with which this Container is associated.

resources

protected DirContext resources
The resources DirContext object with which this Container is associated.

sm

protected static StringManager sm
The string manager for this package.

startChildren

protected boolean startChildren
Will children be started automatically when they are added.

started

protected boolean started
Has this component been started?

suffix

protected String suffix

support

protected PropertyChangeSupport support
The property change support for this component.

type

protected String type

Method Detail

addChild

public void addChild(Container child)
Add a new child Container to those associated with this Container, if supported. Prior to adding this Container to the set of children, the child's setParent() method must be called, with this Container as an argument. This method may thrown an IllegalArgumentException if this Container chooses not to be attached to the specified Container, in which case it is not added

Parameters: child New child Container to be added

Throws: IllegalArgumentException if this exception is thrown by the setParent() method of the child Container IllegalArgumentException if the new child does not have a name unique from that of existing children of this Container IllegalStateException if this Container does not support child Containers

addContainerListener

public void addContainerListener(ContainerListener listener)
Add a container event listener to this component.

Parameters: listener The listener to add

addLifecycleListener

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

Parameters: listener The listener to add

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.

Parameters: listener The listener to add

addValve

public void addValve(Valve valve)
Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the Valve, the Valve's setContainer method must be called, with this Container as an argument. The method may throw an IllegalArgumentException if this Valve chooses not to be associated with this Container, or IllegalStateException if it is already associated with a different Container.

Parameters: valve Valve to be added

Throws: IllegalArgumentException if this Container refused to accept the specified Valve IllegalArgumentException if the specifie Valve refuses to be associated with this Container IllegalStateException if the specified Valve is already associated with a different Container

backgroundProcess

public void backgroundProcess()
Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container. Unexpected throwables will be caught and logged.

createObjectName

public ObjectName createObjectName(String domain, ObjectName parent)

destroy

public void destroy()

findChild

public Container findChild(String name)
Return the child Container, associated with this Container, with the specified name (if any); otherwise, return null

Parameters: name Name of the child Container to be retrieved

findChildren

public Container[] findChildren()
Return the set of children Containers associated with this Container. If this Container has no children, a zero-length array is returned.

findContainerListeners

public ContainerListener[] findContainerListeners()
Return the set of container listeners associated with this Container. If this Container has no registered container listeners, a zero-length array is returned.

findLifecycleListeners

public LifecycleListener[] findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.

fireContainerEvent

public void fireContainerEvent(String type, Object data)
Notify all container 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

getBackgroundProcessorDelay

public int getBackgroundProcessorDelay()
Get the delay between the invocation of the backgroundProcess method on this container and its children. Child containers will not be invoked if their delay value is not negative (which would mean they are using their own thread). Setting this to a positive value will cause a thread to be spawn. After waiting the specified amount of time, the thread will invoke the executePeriodic method on this container and all its children.

getBasic

public Valve getBasic()

Return the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).

getChildren

public ObjectName[] getChildren()

getCluster

public Cluster getCluster()
Return the Cluster with which this Container is associated. If there is no associated Cluster, return the Cluster associated with our parent Container (if any); otherwise return null.

getContainerSuffix

public String getContainerSuffix()

getDomain

public String getDomain()

getFirst

public Valve getFirst()
Return the first valve in the pipeline.

getInfo

public String getInfo()
Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.

getJmxName

public ObjectName getJmxName()

getJSR77Suffix

protected String getJSR77Suffix()

getLoader

public Loader getLoader()
Return the Loader with which this Container is associated. If there is no associated Loader, return the Loader associated with our parent Container (if any); otherwise, return null.

getLogger

public Log getLogger()
Return the Logger with which this Container is associated. If there is no associated Logger, return the Logger associated with our parent Container (if any); otherwise return null.

getManager

public Manager getManager()
Return the Manager with which this Container is associated. If there is no associated Manager, return the Manager associated with our parent Container (if any); otherwise return null.

getMappingObject

public Object getMappingObject()
Return an object which may be utilized for mapping to this component.

getName

public String getName()
Return a name string (suitable for use by humans) that describes this Container. Within the set of child containers belonging to a particular parent, Container names must be unique.

getObjectName

public String getObjectName()

getParent

public Container getParent()
Return the Container for which this Container is a child, if there is one. If there is no defined parent, return null.

getParentClassLoader

public ClassLoader getParentClassLoader()
Return the parent class loader (if any) for this web application. This call is meaningful only after a Loader has been configured.

getParentName

public ObjectName getParentName()

getPipeline

public Pipeline getPipeline()
Return the Pipeline object that manages the Valves associated with this Container.

getRealm

public Realm getRealm()
Return the Realm with which this Container is associated. If there is no associated Realm, return the Realm associated with our parent Container (if any); otherwise return null.

getResources

public DirContext getResources()
Return the resources DirContext object with which this Container is associated. If there is no associated resources object, return the resources associated with our parent Container (if any); otherwise return null.

getStartChildren

public boolean getStartChildren()
Return if children of this container will be started automatically when they are added to this container.

getType

public String getType()

getValveObjectNames

public ObjectName[] getValveObjectNames()

getValves

public Valve[] getValves()
Return the set of Valves in the pipeline associated with this Container, including the basic Valve (if any). If there are no such Valves, a zero-length array is returned.

init

public void init()
Init method, part of the MBean lifecycle. If the container was added via JMX, it'll register itself with the parent, using the ObjectName conventions to locate the parent. If the container was added directly and it doesn't have an ObjectName, it'll create a name and register itself with the JMX console. On destroy(), the object will unregister.

Throws: Exception

invoke

public void invoke(Request request, Response response)
Process the specified Request, to produce the corresponding Response, by invoking the first Valve in our pipeline (if any), or the basic Valve otherwise.

Parameters: request Request to be processed response Response to be produced

Throws: IllegalStateException if neither a pipeline or a basic Valve have been configured for this Container IOException if an input/output error occurred while processing ServletException if a ServletException was thrown while processing this request

logName

protected String logName()
Return the abbreviated name of this container for logging messsages

postDeregister

public void postDeregister()

postRegister

public void postRegister(Boolean registrationDone)

preDeregister

public void preDeregister()

preRegister

public ObjectName preRegister(MBeanServer server, ObjectName name)

removeChild

public void removeChild(Container child)
Remove an existing child Container from association with this parent Container.

Parameters: child Existing child Container to be removed

removeContainerListener

public void removeContainerListener(ContainerListener listener)
Remove a container event listener from this component.

Parameters: listener The listener to remove

removeLifecycleListener

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

Parameters: listener The listener to remove

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.

Parameters: listener The listener to remove

removeValve

public void removeValve(Valve valve)
Remove the specified Valve from the pipeline associated with this Container, if it is found; otherwise, do nothing.

Parameters: valve Valve to be removed

setBackgroundProcessorDelay

public void setBackgroundProcessorDelay(int delay)
Set the delay between the invocation of the execute method on this container and its children.

Parameters: delay The delay in seconds between the invocation of backgroundProcess methods

setBasic

public void setBasic(Valve valve)

Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any). Prioer to setting the basic Valve, the Valve's setContainer() will be called, if it implements Contained, with the owning Container as an argument. The method may throw an IllegalArgumentException if this Valve chooses not to be associated with this Container, or IllegalStateException if it is already associated with a different Container.

Parameters: valve Valve to be distinguished as the basic Valve

setCluster

public void setCluster(Cluster cluster)
Set the Cluster with which this Container is associated.

Parameters: cluster The newly associated Cluster

setDomain

public void setDomain(String domain)

setLoader

public void setLoader(Loader loader)
Set the Loader with which this Container is associated.

Parameters: loader The newly associated loader

setManager

public void setManager(Manager manager)
Set the Manager with which this Container is associated.

Parameters: manager The newly associated Manager

setName

public void setName(String name)
Set a name string (suitable for use by humans) that describes this Container. Within the set of child containers belonging to a particular parent, Container names must be unique.

Parameters: name New name of this container

Throws: IllegalStateException if this Container has already been added to the children of a parent Container (after which the name may not be changed)

setParent

public void setParent(Container container)
Set the parent Container to which this Container is being added as a child. This Container may refuse to become attached to the specified Container by throwing an exception.

Parameters: container Container to which this Container is being added as a child

Throws: IllegalArgumentException if this Container refuses to become attached to the specified Container

setParentClassLoader

public void setParentClassLoader(ClassLoader parent)
Set the parent class loader (if any) for this web application. This call is meaningful only before a Loader has been configured, and the specified value (if non-null) should be passed as an argument to the class loader constructor.

Parameters: parent The new parent class loader

setRealm

public void setRealm(Realm realm)
Set the Realm with which this Container is associated.

Parameters: realm The newly associated Realm

setResources

public void setResources(DirContext resources)
Set the resources DirContext object with which this Container is associated.

Parameters: resources The newly associated DirContext

setStartChildren

public void setStartChildren(boolean startChildren)
Set if children of this container will be started automatically when they are added to this container.

Parameters: startChildren New value of the startChildren flag

start

public void start()
Prepare for active use of the public methods of this Component.

Throws: LifecycleException if this component detects a fatal error that prevents it from being started

stop

public void stop()
Gracefully shut down active use of the public methods of this Component.

Throws: LifecycleException if this component detects a fatal error that needs to be reported

threadStart

protected void threadStart()
Start the background thread that will periodically check for session timeouts.

threadStop

protected void threadStop()
Stop the background thread that is periodically checking for session timeouts.
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.