Class ContainerBase
- java.lang.Object
-
- org.apache.catalina.core.ContainerBase
-
- Direct Known Subclasses:
StandardContext,StandardEngine,StandardHost,StandardWrapper
public abstract class ContainerBase extends Object implements Container, Lifecycle, Pipeline
Abstract implementation of the Container interface, providing common functionality required by nearly every implementation. Classes extending this base class must implementgetInfo(), and 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.Type Data Description addChildContainerChild container added to this Container. addValveValveValve added to this Container. removeChildContainerChild container removed from this Container. removeValveValveValve removed from this Container. startnullContainer was started. stopnullContainer was stopped. - Author:
- Craig R. McClanahan
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classContainerBase.ContainerBackgroundProcessorPrivate thread class to invoke the backgroundProcess method of this container and its children after a fixed delay.protected classContainerBase.PrivilegedAddChildPerform addChild with the permissions of this class.
-
Field Summary
Fields Modifier and Type Field Description protected intbackgroundProcessorDelayThe processor delay for this component.protected booleancheckIfRequestIsSecureFlag indicating whether a check to see if the request is secure is required before adding Pragma and Cache-Control headers when proxy caching has been disabledprotected Map<String,Container>childrenThe child Containers belonging to this Container, keyed by name.protected ObjectNamecontrollerprotected intdebugThe debugging detail level for this component.protected Stringdomainprotected booleanhasCustomPipelineprotected booleaninitializedprotected LifecycleSupportlifecycleThe lifecycle event support for this component.protected ArrayList<ContainerListener>listenersThe container event listeners for this Container.protected LoaderloaderThe Loader implementation with which this Container is associated.protected static Loggerlogprotected LoggerloggerThe Logger implementation with which this Container is associated.protected ManagermanagerThe Manager implementation with which this Container is associated.protected StringnameThe human-readable name of this Container.protected booleannotifyContainerListenersIndicates whether ContainerListener instances need to be notified of a particular configuration event.protected ObjectNameonameprotected ContainerparentThe parent Container to which this Container is a child.protected ClassLoaderparentClassLoaderThe parent class loader to be configured when we install a Loader.protected PipelinepipelineThe Pipeline object with which this Container is associated.protected static ResourceBundlerbprotected LockreadLockprotected RealmrealmThe Realm with which this Container is associated.protected DirContextresourcesThe resources DirContext object with which this Container is associated.protected booleanstartedHas this component been started?protected PropertyChangeSupportsupportThe property change support for this component.protected LockwriteLock-
Fields inherited from interface org.apache.catalina.Container
ADD_CHILD_EVENT, ADD_MAPPER_EVENT, ADD_VALVE_EVENT, REMOVE_CHILD_EVENT, REMOVE_MAPPER_EVENT, REMOVE_VALVE_EVENT
-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
-
-
Constructor Summary
Constructors Constructor Description ContainerBase()
-
Method Summary
All 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.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 Tomcat-style valve.voidaddValve(GlassFishValve 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()Stops the component and any children and removes all listenersContainerfindChild(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.List<LifecycleListener>findLifecycleListeners()Gets the (possibly empty) list of lifecycle listeners associated with this Container.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.GlassFishValvegetBasic()Return the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).ObjectName[]getChildren()StringgetContainerSuffix()intgetDebug()Return the debugging detail level for this component.StringgetDomain()StringgetInfo()Return descriptive information about this Container implementation and the corresponding version number, in the format<description>/<version>.ObjectNamegetJmxName()LoadergetLoader()Return the Loader with which this Container is associated.LoggergetLogger()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()Gets the name of the parent containerPipelinegetPipeline()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.ObjectName[]getValveObjectNames()Gets the name of all Tomcat valvesGlassFishValve[]getValves()Return the set of Valves in the pipeline associated with this Container, including the basic Valve (if any).booleanhasCustomPipeline()booleanhasNonBasicValves()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.booleanisCheckIfRequestIsSecure()Indicates whether the request will be checked to see if it is secure before adding Pragma and Cache-control headers when proxy caching has been disabled.protected voidlog(String message)Log the specified message to our current Logger (if any).protected voidlog(String message, Throwable throwable)Log the specified message and exception to our current Logger (if any).protected StringlogName()Return the abbreviated name of this container for logging messagesvoidremoveChild(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)Removes the given lifecycle event listener from this Container.voidremoveLifecycleListeners()Removes any lifecycle event listeners from this Container.voidremovePropertyChangeListener(PropertyChangeListener listener)Remove a property change listener from this component.voidremoveValve(GlassFishValve 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(GlassFishValve valve)Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).voidsetCheckIfRequestIsSecure(boolean checkIfRequestIsSecure)Sets the checkIfRequestIsSecure property of this Container.voidsetDebug(int debug)Set the debugging detail level for this component.voidsetDomain(String domain)voidsetLoader(Loader loader)Set the Loader with which this Container is associated.voidsetLogger(Logger logger)Set the Logger 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.voidstart()Prepare for active use of the public methods of this Component.protected voidstartChildren()Starts the children of this container.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
-
log
protected static final Logger log
-
rb
protected static final ResourceBundle rb
-
children
protected Map<String,Container> children
The child Containers belonging to this Container, keyed by name.
-
debug
protected int debug
The debugging detail level for this component.
-
backgroundProcessorDelay
protected int backgroundProcessorDelay
The processor delay for this component.
-
checkIfRequestIsSecure
protected boolean checkIfRequestIsSecure
Flag indicating whether a check to see if the request is secure is required before adding Pragma and Cache-Control headers when proxy caching has been disabled
-
lifecycle
protected LifecycleSupport lifecycle
The lifecycle event support for this component.
-
listeners
protected ArrayList<ContainerListener> listeners
The container event listeners for this Container.
-
loader
protected Loader loader
The Loader implementation with which this Container is associated.
-
readLock
protected Lock readLock
-
writeLock
protected Lock writeLock
-
logger
protected Logger logger
The Logger implementation with which this Container is associated.
-
manager
protected Manager manager
The Manager implementation with which this Container is associated.
-
name
protected String name
The human-readable name of this Container.
-
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.
-
hasCustomPipeline
protected boolean hasCustomPipeline
-
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.
-
started
protected volatile boolean started
Has this component been started?
-
initialized
protected boolean initialized
-
support
protected PropertyChangeSupport support
The property change support for this component.
-
notifyContainerListeners
protected boolean notifyContainerListeners
Indicates whether ContainerListener instances need to be notified of a particular configuration event.
-
domain
protected String domain
-
oname
protected ObjectName oname
-
controller
protected ObjectName controller
-
-
Method Detail
-
getDebug
public int getDebug()
Return the debugging detail level for this component.- Returns:
-
setDebug
public void setDebug(int debug)
Set the debugging detail level for this component.- Parameters:
debug- The new debugging detail level
-
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.- Specified by:
getBackgroundProcessorDelayin interfaceContainer- Returns:
-
setBackgroundProcessorDelay
public void setBackgroundProcessorDelay(int delay)
Set the delay between the invocation of the execute method on this container and its children.- Specified by:
setBackgroundProcessorDelayin interfaceContainer- Parameters:
delay- The delay in seconds between the invocation of backgroundProcess methods
-
getInfo
public String getInfo()
Return descriptive information about this Container implementation and the corresponding version number, in the format<description>/<version>.
-
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, returnnull.
-
setLoader
public void setLoader(Loader loader)
Set the Loader with which this Container is associated.
-
getLogger
public Logger 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 returnnull.
-
setLogger
public void setLogger(Logger logger)
Set the Logger with which this Container is associated.
-
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 returnnull.- Specified by:
getManagerin interfaceContainer- Returns:
-
setManager
public void setManager(Manager manager)
Set the Manager with which this Container is associated.- Specified by:
setManagerin interfaceContainer- Parameters:
manager- The newly associated Manager
-
getMappingObject
public Object getMappingObject()
Return an object which may be utilized for mapping to this component.- Specified by:
getMappingObjectin interfaceContainer- Returns:
-
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.
-
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.- Specified by:
setNamein interfaceContainer- 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)
-
getParent
public Container getParent()
Return the Container for which this Container is a child, if there is one. If there is no defined parent, returnnull.
-
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.- Specified by:
setParentin interfaceContainer- 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
-
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.- Specified by:
getParentClassLoaderin interfaceContainer- Returns:
-
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.- Specified by:
setParentClassLoaderin interfaceContainer- Parameters:
parent- The new parent class loader
-
getPipeline
public Pipeline getPipeline()
Return the Pipeline object that manages the Valves associated with this Container.- Specified by:
getPipelinein interfaceContainer- Returns:
-
hasCustomPipeline
public boolean hasCustomPipeline()
- Specified by:
hasCustomPipelinein interfaceContainer- Returns:
- true if this container was configured with a custom pipeline, false otherwise
-
isCheckIfRequestIsSecure
public boolean isCheckIfRequestIsSecure()
Indicates whether the request will be checked to see if it is secure before adding Pragma and Cache-control headers when proxy caching has been disabled.- Specified by:
isCheckIfRequestIsSecurein interfaceContainer- Returns:
- true if the check is required; false otherwise.
-
setCheckIfRequestIsSecure
public void setCheckIfRequestIsSecure(boolean checkIfRequestIsSecure)
Sets the checkIfRequestIsSecure property of this Container. Setting this property to true will check if the request is secure before adding Pragma and Cache-Control headers when proxy caching has been disabled.- Specified by:
setCheckIfRequestIsSecurein interfaceContainer- Parameters:
checkIfRequestIsSecure- true if check is required, false otherwise
-
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 returnnull.
-
setRealm
public void setRealm(Realm realm)
Set the Realm with which this Container is associated.
-
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 returnnull.- Specified by:
getResourcesin interfaceContainer- Returns:
-
setResources
public void setResources(DirContext resources) throws Exception
Set the resources DirContext object with which this Container is associated.- Specified by:
setResourcesin interfaceContainer- Parameters:
resources- The newly associated DirContext- Throws:
Exception
-
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'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 interfaceContainer- Parameters:
child- New child Container to be added- Throws:
IllegalArgumentException- if this exception is thrown by thesetParent()method of the child ContainerIllegalArgumentException- if the new child does not have a name unique from that of existing children of this ContainerIllegalStateException- if this Container does not support child Containers
-
addContainerListener
public void addContainerListener(ContainerListener listener)
Add a container event listener to this component.- Specified by:
addContainerListenerin interfaceContainer- Parameters:
listener- The listener to add
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.- Specified by:
addPropertyChangeListenerin interfaceContainer- Parameters:
listener- The listener to add
-
findChild
public Container findChild(String name)
Return the child Container, associated with this Container, with the specified name (if any); otherwise, returnnull
-
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.- Specified by:
findChildrenin interfaceContainer- Returns:
-
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.- Specified by:
findContainerListenersin interfaceContainer- Returns:
-
invoke
public void invoke(Request request, Response response) throws IOException, jakarta.servlet.ServletException
Process the specified Request, to produce the corresponding Response, by invoking the first Valve in our pipeline (if any), or the basic Valve otherwise.- Specified by:
invokein interfaceContainer- Specified by:
invokein interfacePipeline- Parameters:
request- Request to be processedresponse- Response to be produced- Throws:
IllegalStateException- if neither a pipeline or a basic Valve have been configured for this ContainerIOException- if an input/output error occurred while processingjakarta.servlet.ServletException- if a ServletException was thrown while processing this request
-
removeChild
public void removeChild(Container child)
Remove an existing child Container from association with this parent Container.This will also stop the child container.
- Specified by:
removeChildin interfaceContainer- Parameters:
child- Existing child Container to be removed
-
removeContainerListener
public void removeContainerListener(ContainerListener listener)
Remove a container event listener from this component.- Specified by:
removeContainerListenerin interfaceContainer- Parameters:
listener- The listener to remove
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.- Specified by:
removePropertyChangeListenerin interfaceContainer- Parameters:
listener- The listener to remove
-
addLifecycleListener
public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.- Specified by:
addLifecycleListenerin interfaceLifecycle- Parameters:
listener- The listener to add
-
findLifecycleListeners
public List<LifecycleListener> findLifecycleListeners()
Gets the (possibly empty) list of lifecycle listeners associated with this Container.- Specified by:
findLifecycleListenersin interfaceLifecycle- Returns:
-
removeLifecycleListener
public void removeLifecycleListener(LifecycleListener listener)
Removes the given lifecycle event listener from this Container.- Specified by:
removeLifecycleListenerin interfaceLifecycle- Parameters:
listener- The listener to remove
-
removeLifecycleListeners
public void removeLifecycleListeners()
Removes any lifecycle event listeners from this Container.
-
start
public void start() throws LifecycleExceptionPrepare for active use of the public methods of this Component.- Specified by:
startin interfaceLifecycle- Throws:
LifecycleException- if this component detects a fatal error that prevents it from being started
-
stop
public void stop() throws LifecycleExceptionGracefully shut down active use of the public methods of this Component.- Specified by:
stopin interfaceLifecycle- Throws:
LifecycleException- if this component detects a fatal error that needs to be reported
-
init
public void init() throws ExceptionInit 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
-
getParentName
public ObjectName getParentName() throws MalformedObjectNameException
Gets the name of the parent container- Returns:
- null if no parent
- Throws:
MalformedObjectNameException
-
destroy
public void destroy() throws ExceptionStops the component and any children and removes all listeners- Throws:
Exception
-
addValve
public void addValve(GlassFishValve valve)
Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the Valve, the Valve'ssetContainermethod must be called, with this Container as an argument. The method may throw anIllegalArgumentExceptionif this Valve chooses not to be associated with this Container, orIllegalStateExceptionif it is already associated with a different Container.- Specified by:
addValvein interfacePipeline- Parameters:
valve- Valve to be added- Throws:
IllegalArgumentException- if this Container refused to accept the specified ValveIllegalArgumentException- if the specified Valve refuses to be associated with this ContainerIllegalStateException- if the specified Valve is already associated with a different Container
-
addValve
public void addValve(Valve valve)
Add Tomcat-style valve.
-
getValveObjectNames
public ObjectName[] getValveObjectNames()
Gets the name of all Tomcat valves- Returns:
- See Also:
ValveBase
-
getBasic
public GlassFishValve getBasic()
Return the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).
-
getValves
public GlassFishValve[] 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.
-
hasNonBasicValves
public boolean hasNonBasicValves()
- Specified by:
hasNonBasicValvesin interfacePipeline- Returns:
- true if this pipeline has any non basic valves, false otherwise
-
removeValve
public void removeValve(GlassFishValve valve)
Remove the specified Valve from the pipeline associated with this Container, if it is found; otherwise, do nothing.- Specified by:
removeValvein interfacePipeline- Parameters:
valve- Valve to be removed
-
setBasic
public void setBasic(GlassFishValve valve)
Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any). Prior to setting the basic Valve, the Valve's
setContainer()will be called, if it implementsContained, with the owning Container as an argument. The method may throw anIllegalArgumentExceptionif this Valve chooses not to be associated with this Container, orIllegalStateExceptionif it 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.- Specified by:
backgroundProcessin interfaceContainer
-
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.- Specified by:
fireContainerEventin interfaceContainer- Parameters:
type- Event typedata- Event data
-
startChildren
protected void startChildren()
Starts the children of this container.
-
log
protected void log(String message)
Log the specified message to our current Logger (if any).- Parameters:
message- Message to be logged
-
log
protected void log(String message, Throwable throwable)
Log the specified message and exception to our current Logger (if any).- Parameters:
message- Message to be loggedthrowable- Related exception
-
logName
protected String logName()
Return the abbreviated name of this container for logging messages- Returns:
-
getJmxName
public ObjectName getJmxName()
-
getObjectName
public String getObjectName()
-
getDomain
public String getDomain()
-
setDomain
public void setDomain(String domain)
-
getChildren
public ObjectName[] getChildren()
-
createObjectName
public ObjectName createObjectName(String domain, ObjectName parent) throws Exception
- Throws:
Exception
-
getContainerSuffix
public String getContainerSuffix()
-
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.
-
-