Package org.apache.catalina
Interface Container
- All Superinterfaces:
- Lifecycle
- All Known Implementing Classes:
- ContainerBase,- FailedContext,- ReplicatedContext,- StandardContext,- StandardEngine,- StandardHost,- StandardWrapper,- Tomcat.ExistingStandardWrapper
A Container is an object that can execute requests received from
 a client, and return responses based on those requests.  A Container may
 optionally support a pipeline of Valves that process the request in an
 order configured at runtime, by implementing the Pipeline interface
 as well.
 
Containers will exist at several conceptual levels within Catalina. The following examples represent common cases:
- Engine - Representation of the entire Catalina servlet engine, most likely containing one or more subcontainers that are either Host or Context implementations, or other custom groups.
- Host - Representation of a virtual host containing a number of Contexts.
- Context - Representation of a single ServletContext, which will typically contain one or more Wrappers for the supported servlets.
- Wrapper - Representation of an individual servlet definition.
A Container may also be associated with a number of support components that provide functionality which might be shared (by attaching it to a parent Container) or individually customized. The following support components are currently recognized:
- Loader - Class loader to use for integrating new Java classes for this Container into the JVM in which Catalina is running.
- Logger - Implementation of the log()method signatures of theServletContextinterface.
- Manager - Manager for the pool of Sessions associated with this Container.
- Realm - Read-only interface to a security domain, for authenticating user identities and their corresponding roles.
- Resources - JNDI directory context enabling access to static resources, enabling custom linkages to existing server components when Catalina is embedded in a larger server.
- Author:
- Craig R. McClanahan, Remy Maucherat
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.apache.catalina.LifecycleLifecycle.SingleUse
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe ContainerEvent event type sent when a child container is added byaddChild().static final StringThe ContainerEvent event type sent when a valve is added byaddValve(), if this Container supports pipelines.static final StringThe ContainerEvent event type sent when a child container is removed byremoveChild().static final StringThe ContainerEvent event type sent when a valve is removed byremoveValve(), if this Container supports pipelines.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
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdd a new child Container to those associated with this Container, if supported.voidaddContainerListener(ContainerListener listener) Add a container event listener to this component.voidAdd a property change listener to this component.voidExecute a periodic task, such as reloading, etc.Obtain a child Container by name.Obtain the child Containers associated with this Container.Obtain the container listeners associated with this Container.voidfireContainerEvent(String type, Object data) Notify all container event listeners that a particular event has occurred for this Container.Obtain the AccessLog to use to log a request/response that is destined for this container.intGet the delay between the invocation of the backgroundProcess method on this container and its children.Obtain the location of CATALINA_BASE.Obtain the location of CATALINA_HOME.Get the Cluster for this container.static StringgetConfigPath(Container container, String resourceName) Find the configuration path where a configuration resource is located.Obtain the JMX domain under which this container will be / has been registered.Obtain the log to which events for this container should be logged.Return the logger name that the container will use.Calculate the key properties string to be added to an object'sObjectNameto indicate that it is associated with this container.getName()Return a name string (suitable for use by humans) that describes this Container.Obtain the JMX name for this container.Get the parent container.Get the parent class loader.Return the Pipeline object that manages the Valves associated with this Container.getRealm()Obtain the Realm with which this Container is associated.static ServicegetService(Container container) Return the Service to which this container belongs.intObtain the number of threads available for starting and stopping any children associated with this container.voidLog a request/response that was destined for this container but has been handled earlier in the processing chain so that the request/response still appears in the correct access logs.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.voidRemove 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.voidSet a name string (suitable for use by humans) that describes this Container.voidSet the parent Container to which this Container is being added as a child.voidsetParentClassLoader(ClassLoader parent) Set the parent class loader for this component.voidSet the Realm with which this Container is associated.voidsetStartStopThreads(int startStopThreads) Sets the number of threads available for starting and stopping any children associated with this container.Methods inherited from interface org.apache.catalina.LifecycleaddLifecycleListener, destroy, findLifecycleListeners, getState, getStateName, init, removeLifecycleListener, start, stop
- 
Field Details- 
ADD_CHILD_EVENTThe ContainerEvent event type sent when a child container is added byaddChild().- See Also:
 
- 
ADD_VALVE_EVENTThe ContainerEvent event type sent when a valve is added byaddValve(), if this Container supports pipelines.- See Also:
 
- 
REMOVE_CHILD_EVENTThe ContainerEvent event type sent when a child container is removed byremoveChild().- See Also:
 
- 
REMOVE_VALVE_EVENTThe ContainerEvent event type sent when a valve is removed byremoveValve(), if this Container supports pipelines.- See Also:
 
 
- 
- 
Method Details- 
getLoggerLog getLogger()Obtain the log to which events for this container should be logged.- Returns:
- The Logger with which this Container is associated.  If there is
         no associated Logger, return the Logger associated with the
         parent Container (if any); otherwise return null.
 
- 
getLogNameString getLogName()Return the logger name that the container will use.- Returns:
- the abbreviated name of this container for logging messages
 
- 
getObjectNameObjectName getObjectName()Obtain the JMX name for this container.- Returns:
- the JMX name associated with this container.
 
- 
getDomainString getDomain()Obtain the JMX domain under which this container will be / has been registered.- Returns:
- The JMX domain name
 
- 
getMBeanKeyPropertiesString getMBeanKeyProperties()Calculate the key properties string to be added to an object'sObjectNameto indicate that it is associated with this container.- Returns:
- A string suitable for appending to the ObjectName
 
- 
getPipelinePipeline getPipeline()Return the Pipeline object that manages the Valves associated with this Container.- Returns:
- The Pipeline
 
- 
getClusterCluster getCluster()Get the Cluster for this 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.
 
- 
setClusterSet the Cluster with which this Container is associated.- Parameters:
- cluster- the Cluster with which this Container is associated.
 
- 
getBackgroundProcessorDelayint 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 positive (which would mean they are using their own thread). Setting this to a positive value will cause a thread to be spawned. After waiting the specified amount of time, the thread will invoke thebackgroundProcess()method on this container and all children with non-positive delay values.- 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.
 
- 
setBackgroundProcessorDelayvoid 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
 
- 
getNameString 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.- Returns:
- The human readable name of this container.
 
- 
setNameSet 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)
 
- 
getParentContainer getParent()Get the parent container.- Returns:
- Return the Container for which this Container is a child, if
         there is one. If there is no defined parent, return
         null.
 
- 
setParentSet 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
 
- 
getParentClassLoaderClassLoader getParentClassLoader()Get the parent class loader.- Returns:
- the parent class loader for this component. If not set, return
         getParent().getParentClassLoader(). If no parent has been set, return the system class loader.
 
- 
setParentClassLoaderSet the parent class loader for this component. ForContexts 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
 
- 
getRealmRealm getRealm()Obtain the Realm with which this Container is associated.- Returns:
- The associated Realm; if there is no associated Realm, the
         Realm associated with the parent Container (if any); otherwise
         return null.
 
- 
setRealmSet the Realm with which this Container is associated.- Parameters:
- realm- The newly associated Realm
 
- 
getConfigPathFind the configuration path where a configuration resource is located.- Parameters:
- container- The container
- resourceName- The resource file name
- Returns:
- the configuration path
 
- 
getServiceReturn the Service to which this container belongs.- Parameters:
- container- The container to start from
- Returns:
- the Service, or null if not found
 
- 
backgroundProcessvoid 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.
- 
addChildAdd 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- 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
 
- 
addContainerListenerAdd a container event listener to this component.- Parameters:
- listener- The listener to add
 
- 
addPropertyChangeListenerAdd a property change listener to this component.- Parameters:
- listener- The listener to add
 
- 
findChildObtain a child Container by name.- Parameters:
- name- Name of the child Container to be retrieved
- Returns:
- The child Container with the given name or nullif no such child exists.
 
- 
findChildrenContainer[] findChildren()Obtain the child Containers associated with this Container.- Returns:
- An array containing all children of this container. If this Container has no children, a zero-length array is returned.
 
- 
findContainerListenersContainerListener[] findContainerListeners()Obtain the container listeners associated with this 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.
 
- 
removeChildRemove an existing child Container from association with this parent Container.- Parameters:
- child- Existing child Container to be removed
 
- 
removeContainerListenerRemove a container event listener from this component.- Parameters:
- listener- The listener to remove
 
- 
removePropertyChangeListenerRemove a property change listener from this component.- Parameters:
- listener- The listener to remove
 
- 
fireContainerEventNotify 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
 
- 
logAccessLog a request/response that was destined for this container but has been handled earlier in the processing chain so that the request/response still appears in the correct access logs.- 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
 
- 
getAccessLogAccessLog getAccessLog()Obtain 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.- Returns:
- The AccessLog to use for a request/response destined for this container
 
- 
getStartStopThreadsint getStartStopThreads()Obtain 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.- Returns:
- The currently configured number of threads used to start/stop children associated with this container
 
- 
setStartStopThreadsvoid setStartStopThreads(int startStopThreads) Sets 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.- Parameters:
- startStopThreads- The new number of threads to be used
 
- 
getCatalinaBaseFile getCatalinaBase()Obtain the location of CATALINA_BASE.- Returns:
- The location of CATALINA_BASE.
 
- 
getCatalinaHomeFile getCatalinaHome()Obtain the location of CATALINA_HOME.- Returns:
- The location of CATALINA_HOME.
 
 
-