Package org.apache.catalina.core
Class ContainerBase
- java.lang.Object
- 
- org.apache.catalina.util.LifecycleBase
- 
- org.apache.catalina.util.LifecycleMBeanBase
- 
- org.apache.catalina.core.ContainerBase
 
 
 
- 
- All Implemented Interfaces:
- javax.management.MBeanRegistration,- Container,- JmxEnabled,- Lifecycle
 - Direct Known Subclasses:
- StandardContext,- StandardEngine,- StandardHost,- StandardWrapper
 
 public abstract class ContainerBase extends LifecycleMBeanBase implements Container Abstract implementation of the Container interface, providing common functionality required by nearly every implementation. Classes extending this base class must may implement a replacement forinvoke().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 aValve, and configure this Valve into the pipeline by callingsetBasic().This implementation fires property change events, per the JavaBeans design pattern, for changes in singleton properties. In addition, it fires the following ContainerEventevents to listeners who register themselves withaddContainerListener():
 Subclasses that fire additional events should document them in the class comments of the implementation class.ContainerEvents fired by this implementation Type Data Description addChildContainerChild container added to this Container. pipeline.addValveValveValve added to this Container. removeChildContainerChild container removed from this Container. pipeline.removeValveValveValve removed from this Container. startnullContainer was started. stopnullContainer was stopped. - Author:
- Craig R. McClanahan
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected classContainerBase.ContainerBackgroundProcessorPrivate runnable class to invoke the backgroundProcess method of this container and its children after a fixed delay.protected classContainerBase.ContainerBackgroundProcessorMonitorprotected classContainerBase.PrivilegedAddChildPerform 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.- 
Nested classes/interfaces inherited from interface org.apache.catalina.LifecycleLifecycle.SingleUse
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected AccessLogaccessLogThe access log to use for requests normally handled by this container that have been handled earlier in the processing chain.protected intbackgroundProcessorDelayThe processor delay for this component.protected java.util.concurrent.ScheduledFuture<?>backgroundProcessorFutureThe future allowing control of the background processor.protected java.util.HashMap<java.lang.String,Container>childrenThe child Containers belonging to this Container, keyed by name.protected ClusterclusterThe cluster with which this Container is associated.protected java.util.List<ContainerListener>listenersThe container event listeners for this Container.protected LogloggerThe Logger implementation with which this Container is associated.protected java.lang.StringlogNameAssociated logger name.protected java.util.concurrent.ScheduledFuture<?>monitorFutureprotected java.lang.StringnameThe human-readable name of this Container.protected ContainerparentThe parent Container to which this Container is a child.protected java.lang.ClassLoaderparentClassLoaderThe parent class loader to be configured when we install a Loader.protected PipelinepipelineThe Pipeline object with which this Container is associated.protected static StringManagersmThe string manager for this package.protected booleanstartChildrenWill children be started automatically when they are added.protected java.util.concurrent.ExecutorServicestartStopExecutorprotected java.beans.PropertyChangeSupportsupportThe property change support for this component.- 
Fields inherited from class org.apache.catalina.util.LifecycleMBeanBasemserver
 - 
Fields inherited from interface org.apache.catalina.ContainerADD_CHILD_EVENT, ADD_VALVE_EVENT, REMOVE_CHILD_EVENT, REMOVE_VALVE_EVENT
 - 
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 ContainerBase()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Add a property change listener to this component.voidaddValve(Valve valve)Convenience method, intended for use by the digester to simplify the process of adding Valves to containers.voidbackgroundProcess()Execute a periodic task, such as reloading, etc.protected voiddestroyInternal()Sub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.ContainerfindChild(java.lang.String name)Return the child Container, associated with this Container, with the specified name (if any); otherwise, returnnullContainer[]findChildren()Return the set of children Containers associated with this Container.ContainerListener[]findContainerListeners()Return the set of container listeners associated with this Container.voidfireContainerEvent(java.lang.String type, java.lang.Object data)Notify all container event listeners that a particular event has occurred for this Container.AccessLoggetAccessLog()Obtain the AccessLog to use to log a request/response that is destined for this container.intgetBackgroundProcessorDelay()Get the delay between the invocation of the backgroundProcess method on this container and its children.java.io.FilegetCatalinaBase()Obtain the location of CATALINA_BASE.java.io.FilegetCatalinaHome()Obtain the location of CATALINA_HOME.javax.management.ObjectName[]getChildren()ClustergetCluster()Return the Cluster with which this Container is associated.protected ClustergetClusterInternal()protected java.lang.StringgetDomainInternal()Method implemented by sub-classes to identify the domain in which MBeans should be registered.LoggetLogger()Return the Logger for this Container.java.lang.StringgetLogName()Return the logger name that the container will use.java.lang.StringgetMBeanKeyProperties()Calculate the key properties string to be added to an object'sObjectNameto indicate that it is associated with this container.java.lang.StringgetName()Return a name string (suitable for use by humans) that describes this Container.ContainergetParent()Return the Container for which this Container is a child, if there is one.java.lang.ClassLoadergetParentClassLoader()Return the parent class loader (if any) for this web application.PipelinegetPipeline()Return the Pipeline object that manages the Valves associated with this Container.RealmgetRealm()Return the Realm with which this Container is associated.protected RealmgetRealmInternal()booleangetStartChildren()Return if children of this container will be started automatically when they are added to this container.intgetStartStopThreads()Obtain the number of threads available for starting and stopping any children associated with this container.voidlogAccess(Request request, Response response, long time, boolean useDefault)Check this container for an access log and if none is found, look to the parent.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.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Remove a property change listener from this component.voidsetBackgroundProcessorDelay(int delay)Set the delay between the invocation of the execute method on this container and its children.voidsetCluster(Cluster cluster)Set the Cluster with which this Container is associated.voidsetName(java.lang.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(java.lang.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.voidsetStartChildren(boolean startChildren)Set if children of this container will be started automatically when they are added to this container.voidsetStartStopThreads(int startStopThreads)Sets the number of threads available for starting and stopping any children associated with this container.protected voidstartInternal()Start this component and implement the requirements ofLifecycleBase.startInternal().protected voidstopInternal()Stop this component and implement the requirements ofLifecycleBase.stopInternal().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.java.lang.StringtoString()- 
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBasegetDomain, getObjectName, getObjectNameKeyProperties, initInternal, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister
 - 
Methods inherited from class org.apache.catalina.util.LifecycleBaseaddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.apache.catalina.ContainergetDomain, getObjectName
 - 
Methods inherited from interface org.apache.catalina.LifecycleaddLifecycleListener, destroy, findLifecycleListeners, getState, getStateName, init, removeLifecycleListener, start, stop
 
- 
 
- 
- 
- 
Field Detail- 
childrenprotected final java.util.HashMap<java.lang.String,Container> children The child Containers belonging to this Container, keyed by name.
 - 
backgroundProcessorDelayprotected int backgroundProcessorDelay The processor delay for this component.
 - 
backgroundProcessorFutureprotected java.util.concurrent.ScheduledFuture<?> backgroundProcessorFuture The future allowing control of the background processor.
 - 
monitorFutureprotected java.util.concurrent.ScheduledFuture<?> monitorFuture 
 - 
listenersprotected final java.util.List<ContainerListener> listeners The container event listeners for this Container. Implemented as a CopyOnWriteArrayList since listeners may invoke methods to add/remove themselves or other listeners and with a ReadWriteLock that would trigger a deadlock.
 - 
loggerprotected Log logger The Logger implementation with which this Container is associated.
 - 
logNameprotected java.lang.String logName Associated logger name.
 - 
clusterprotected Cluster cluster The cluster with which this Container is associated.
 - 
nameprotected java.lang.String name The human-readable name of this Container.
 - 
parentprotected Container parent The parent Container to which this Container is a child.
 - 
parentClassLoaderprotected java.lang.ClassLoader parentClassLoader The parent class loader to be configured when we install a Loader.
 - 
pipelineprotected final Pipeline pipeline The Pipeline object with which this Container is associated.
 - 
smprotected static final StringManager sm The string manager for this package.
 - 
startChildrenprotected boolean startChildren Will children be started automatically when they are added.
 - 
supportprotected final java.beans.PropertyChangeSupport support The property change support for this component.
 - 
accessLogprotected volatile AccessLog accessLog The access log to use for requests normally handled by this container that have been handled earlier in the processing chain.
 - 
startStopExecutorprotected java.util.concurrent.ExecutorService startStopExecutor 
 
- 
 - 
Method Detail- 
getStartStopThreadspublic int getStartStopThreads() Description copied from interface:ContainerObtain the number of threads available for starting and stopping any children associated with this container. This allows start/stop calls to children to be processed in parallel.- Specified by:
- getStartStopThreadsin interface- Container
- Returns:
- The currently configured number of threads used to start/stop children associated with this container
 
 - 
setStartStopThreadspublic void setStartStopThreads(int startStopThreads) Description copied from interface:ContainerSets the number of threads available for starting and stopping any children associated with this container. This allows start/stop calls to children to be processed in parallel.- Specified by:
- setStartStopThreadsin interface- Container
- Parameters:
- startStopThreads- The new number of threads to be used
 
 - 
getBackgroundProcessorDelaypublic 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.- Specified by:
- getBackgroundProcessorDelayin interface- Container
- Returns:
- The delay between the invocation of the backgroundProcess method on this container and its children. A non-positive value indicates that background processing will be managed by the parent.
 
 - 
setBackgroundProcessorDelaypublic void setBackgroundProcessorDelay(int delay) Set the delay between the invocation of the execute method on this container and its children.- Specified by:
- setBackgroundProcessorDelayin interface- Container
- Parameters:
- delay- The delay in seconds between the invocation of backgroundProcess methods
 
 - 
getLoggerpublic Log getLogger() Return the Logger for this Container.
 - 
getLogNamepublic java.lang.String getLogName() Description copied from interface:ContainerReturn the logger name that the container will use.- Specified by:
- getLogNamein interface- Container
- Returns:
- the abbreviated name of this container for logging messages
 
 - 
getClusterpublic 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 returnnull.- Specified by:
- getClusterin interface- Container
- Returns:
- 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.
 
 - 
getClusterInternalprotected Cluster getClusterInternal() 
 - 
setClusterpublic void setCluster(Cluster cluster) Set the Cluster with which this Container is associated.- Specified by:
- setClusterin interface- Container
- Parameters:
- cluster- The newly associated Cluster
 
 - 
getNamepublic java.lang.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.
 - 
setNamepublic void setName(java.lang.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.
 - 
getStartChildrenpublic boolean getStartChildren() Return if children of this container will be started automatically when they are added to this container.- Returns:
- trueif the children will be started
 
 - 
setStartChildrenpublic 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
 
 - 
getParentpublic Container getParent() Return the Container for which this Container is a child, if there is one. If there is no defined parent, returnnull.
 - 
setParentpublic 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.
 - 
getParentClassLoaderpublic java.lang.ClassLoader getParentClassLoader() Return the parent class loader (if any) for this web application. This call is meaningful only after a Loader has been configured.- Specified by:
- getParentClassLoaderin interface- Container
- Returns:
- the parent class loader for this component. If not set, return
         Container.getParent().Container.getParentClassLoader(). If no parent has been set, return the system class loader.
 
 - 
setParentClassLoaderpublic void setParentClassLoader(java.lang.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.- Specified by:
- setParentClassLoaderin interface- Container
- Parameters:
- parent- The new parent class loader
 
 - 
getPipelinepublic Pipeline getPipeline() Return the Pipeline object that manages the Valves associated with this Container.- Specified by:
- getPipelinein interface- Container
- Returns:
- The Pipeline
 
 - 
getRealmpublic 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 returnnull.
 - 
getRealmInternalprotected Realm getRealmInternal() 
 - 
setRealmpublic void setRealm(Realm realm) Set the Realm with which this Container is associated.
 - 
addChildpublic 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'ssetParent()method must be called, with this Container as an argument. This method may thrown anIllegalArgumentExceptionif this Container chooses not to be attached to the specified Container, in which case it is not added- Specified by:
- addChildin interface- Container
- Parameters:
- child- New child Container to be added
- Throws:
- java.lang.IllegalArgumentException- if this exception is thrown by the- setParent()method of the child Container
- java.lang.IllegalArgumentException- if the new child does not have a name unique from that of existing children of this Container
- java.lang.IllegalStateException- if this Container does not support child Containers
 
 - 
addContainerListenerpublic void addContainerListener(ContainerListener listener) Add a container event listener to this component.- Specified by:
- addContainerListenerin interface- Container
- Parameters:
- listener- The listener to add
 
 - 
addPropertyChangeListenerpublic void addPropertyChangeListener(java.beans.PropertyChangeListener listener) Add a property change listener to this component.- Specified by:
- addPropertyChangeListenerin interface- Container
- Parameters:
- listener- The listener to add
 
 - 
findChildpublic Container findChild(java.lang.String name) Return the child Container, associated with this Container, with the specified name (if any); otherwise, returnnull
 - 
findChildrenpublic Container[] findChildren() Return the set of children Containers associated with this Container. If this Container has no children, a zero-length array is returned.- Specified by:
- findChildrenin interface- Container
- Returns:
- An array containing all children of this container. If this Container has no children, a zero-length array is returned.
 
 - 
findContainerListenerspublic 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.- Specified by:
- findContainerListenersin interface- Container
- Returns:
- An array containing the container listeners associated with this Container. If this Container has no registered container listeners, a zero-length array is returned.
 
 - 
removeChildpublic void removeChild(Container child) Remove an existing child Container from association with this parent Container.- Specified by:
- removeChildin interface- Container
- Parameters:
- child- Existing child Container to be removed
 
 - 
removeContainerListenerpublic void removeContainerListener(ContainerListener listener) Remove a container event listener from this component.- Specified by:
- removeContainerListenerin interface- Container
- Parameters:
- listener- The listener to remove
 
 - 
removePropertyChangeListenerpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener) Remove a property change listener from this component.- Specified by:
- removePropertyChangeListenerin interface- Container
- Parameters:
- listener- The listener to remove
 
 - 
startInternalprotected void startInternal() throws LifecycleExceptionStart this component and implement the requirements ofLifecycleBase.startInternal().- Specified by:
- startInternalin class- LifecycleBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
stopInternalprotected void stopInternal() throws LifecycleExceptionStop this component and implement the requirements ofLifecycleBase.stopInternal().- Specified by:
- stopInternalin class- LifecycleBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
destroyInternalprotected void destroyInternal() throws LifecycleExceptionDescription copied from class:LifecycleMBeanBaseSub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.- Overrides:
- destroyInternalin class- LifecycleMBeanBase
- Throws:
- LifecycleException- If the destruction fails
 
 - 
logAccesspublic void logAccess(Request request, Response response, long time, boolean useDefault) Check this container for an access log and if none is found, look to the parent. If there is no parent and still none is found, use the NoOp access log.- Specified by:
- logAccessin interface- Container
- Parameters:
- request- Request (associated with the response) to log
- response- Response (associated with the request) to log
- time- Time taken to process the request/response in milliseconds (use 0 if not known)
- useDefault- Flag that indicates that the request/response should be logged in the engine's default access log
 
 - 
getAccessLogpublic AccessLog getAccessLog() Description copied from interface:ContainerObtain the AccessLog to use to log a request/response that is destined for this container. This is typically used when the request/response was handled (and rejected) earlier in the processing chain so that the request/response still appears in the correct access logs.- Specified by:
- getAccessLogin interface- Container
- Returns:
- The AccessLog to use for a request/response destined for this container
 
 - 
addValvepublic void addValve(Valve valve) Convenience method, intended for use by the digester to simplify the process of adding Valves to containers. SeePipeline.addValve(Valve)for full details. Components other than the digester should usegetPipeline().addValve(Valve)in case a future implementation provides an alternative method for the digester to use.- Parameters:
- valve- Valve to be added
- Throws:
- java.lang.IllegalArgumentException- if this Container refused to accept the specified Valve
- java.lang.IllegalArgumentException- if the specified Valve refuses to be associated with this Container
- java.lang.IllegalStateException- if the specified Valve is already associated with a different Container
 
 - 
backgroundProcesspublic 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.- Specified by:
- backgroundProcessin interface- Container
 
 - 
getCatalinaBasepublic java.io.File getCatalinaBase() Description copied from interface:ContainerObtain the location of CATALINA_BASE.- Specified by:
- getCatalinaBasein interface- Container
- Returns:
- The location of CATALINA_BASE.
 
 - 
getCatalinaHomepublic java.io.File getCatalinaHome() Description copied from interface:ContainerObtain the location of CATALINA_HOME.- Specified by:
- getCatalinaHomein interface- Container
- Returns:
- The location of CATALINA_HOME.
 
 - 
fireContainerEventpublic void fireContainerEvent(java.lang.String type, java.lang.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.- Specified by:
- fireContainerEventin interface- Container
- Parameters:
- type- Event type
- data- Event data
 
 - 
getDomainInternalprotected java.lang.String getDomainInternal() Description copied from class:LifecycleMBeanBaseMethod implemented by sub-classes to identify the domain in which MBeans should be registered.- Specified by:
- getDomainInternalin class- LifecycleMBeanBase
- Returns:
- The name of the domain to use to register MBeans.
 
 - 
getMBeanKeyPropertiespublic java.lang.String getMBeanKeyProperties() Description copied from interface:ContainerCalculate the key properties string to be added to an object'sObjectNameto indicate that it is associated with this container.- Specified by:
- getMBeanKeyPropertiesin interface- Container
- Returns:
- A string suitable for appending to the ObjectName
 
 - 
getChildrenpublic javax.management.ObjectName[] getChildren() 
 - 
threadStartprotected void threadStart() Start the background thread that will periodically check for session timeouts.
 - 
threadStopprotected void threadStop() Stop the background thread that is periodically checking for session timeouts.
 - 
toStringpublic final java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 
- 
 
-