📄 containerbase.java
字号:
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.catalina.core;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.naming.directory.DirContext;
import javax.servlet.ServletException;
import org.apache.catalina.Cluster;
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Loader;
import org.apache.catalina.Logger;
import org.apache.catalina.Manager;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Realm;
import org.apache.catalina.Request;
import org.apache.catalina.Response;
import org.apache.catalina.Valve;
import org.apache.catalina.logger.LoggerBase;
import org.apache.catalina.util.LifecycleSupport;
import org.apache.catalina.util.StringManager;
import org.apache.commons.modeler.Registry;
import org.apache.naming.resources.ProxyDirContext;
/**
* Abstract implementation of the <b>Container</b> interface, providing common
* functionality required by nearly every implementation. Classes extending
* this base class must implement <code>getInfo()</code>, and may implement
* a replacement for <code>invoke()</code>.
* <p>
* 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 <code>invoke()</code> method of this class, utilizing the
* "Chain of Responsibility" design pattern. A subclass should encapsulate its
* own processing functionality as a <code>Valve</code>, and configure this
* Valve into the pipeline by calling <code>setBasic()</code>.
* <p>
* This implementation fires property change events, per the JavaBeans design
* pattern, for changes in singleton properties. In addition, it fires the
* following <code>ContainerEvent</code> events to listeners who register
* themselves with <code>addContainerListener()</code>:
* <table border=1>
* <tr>
* <th>Type</th>
* <th>Data</th>
* <th>Description</th>
* </tr>
* <tr>
* <td align=center><code>addChild</code></td>
* <td align=center><code>Container</code></td>
* <td>Child container added to this Container.</td>
* </tr>
* <tr>
* <td align=center><code>addValve</code></td>
* <td align=center><code>Valve</code></td>
* <td>Valve added to this Container.</td>
* </tr>
* <tr>
* <td align=center><code>removeChild</code></td>
* <td align=center><code>Container</code></td>
* <td>Child container removed from this Container.</td>
* </tr>
* <tr>
* <td align=center><code>removeValve</code></td>
* <td align=center><code>Valve</code></td>
* <td>Valve removed from this Container.</td>
* </tr>
* <tr>
* <td align=center><code>start</code></td>
* <td align=center><code>null</code></td>
* <td>Container was started.</td>
* </tr>
* <tr>
* <td align=center><code>stop</code></td>
* <td align=center><code>null</code></td>
* <td>Container was stopped.</td>
* </tr>
* </table>
* Subclasses that fire additional events should document them in the
* class comments of the implementation class.
*
* @author Craig R. McClanahan
*/
public abstract class ContainerBase
implements Container, Lifecycle, Pipeline, MBeanRegistration, Serializable {
private static org.apache.commons.logging.Log log=
org.apache.commons.logging.LogFactory.getLog( ContainerBase.class );
/**
* 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.
*/
protected class PrivilegedAddChild
implements PrivilegedAction {
private Container child;
PrivilegedAddChild(Container child) {
this.child = child;
}
public Object run() {
addChildInternal(child);
return null;
}
}
// ----------------------------------------------------- Instance Variables
/**
* The child Containers belonging to this Container, keyed by name.
*/
protected HashMap children = new HashMap();
/**
* The debugging detail level for this component.
*/
protected int debug = 0;
/**
* The processor delay for this component.
*/
protected int backgroundProcessorDelay = -1;
/**
* The lifecycle event support for this component.
*/
protected LifecycleSupport lifecycle = new LifecycleSupport(this);
/**
* The container event listeners for this Container.
*/
protected ArrayList listeners = new ArrayList();
/**
* The Loader implementation with which this Container is associated.
*/
protected Loader loader = null;
/**
* The Logger implementation with which this Container is associated.
*/
protected Logger logger = null;
/**
* The Manager implementation with which this Container is associated.
*/
protected Manager manager = null;
/**
* The cluster with which this Container is associated.
*/
protected Cluster cluster = null;
/**
* The human-readable name of this Container.
*/
protected String name = null;
/**
* The parent Container to which this Container is a child.
*/
protected Container parent = null;
/**
* The parent class loader to be configured when we install a Loader.
*/
protected ClassLoader parentClassLoader = null;
/**
* The Pipeline object with which this Container is associated.
*/
protected Pipeline pipeline = new StandardPipeline(this);
/**
* The Realm with which this Container is associated.
*/
protected Realm realm = null;
/**
* The resources DirContext object with which this Container is associated.
*/
protected DirContext resources = null;
/**
* The string manager for this package.
*/
protected static StringManager sm =
StringManager.getManager(Constants.Package);
/**
* Has this component been started?
*/
protected boolean started = false;
protected boolean initialized=false;
/**
* The property change support for this component.
*/
protected PropertyChangeSupport support = new PropertyChangeSupport(this);
/**
* The background thread.
*/
private Thread thread = null;
/**
* The background thread completion semaphore.
*/
private boolean threadDone = false;
// ------------------------------------------------------------- Properties
/**
* Return the debugging detail level for this component.
*/
public int getDebug() {
return (this.debug);
}
/**
* Set the debugging detail level for this component.
*
* @param debug The new debugging detail level
*/
public void setDebug(int debug) {
int oldDebug = this.debug;
this.debug = debug;
support.firePropertyChange("debug", new Integer(oldDebug),
new Integer(this.debug));
}
/**
* 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.
*/
public int getBackgroundProcessorDelay() {
return backgroundProcessorDelay;
}
/**
* Set the delay between the invocation of the execute method on this
* container and its children.
*
* @param delay The delay in seconds between the invocation of
* backgroundProcess methods
*/
public void setBackgroundProcessorDelay(int delay) {
backgroundProcessorDelay = delay;
}
/**
* Return descriptive information about this Container implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo() {
return this.getClass().getName();
}
/**
* 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 <code>null</code>.
*/
public Loader getLoader() {
if (loader != null)
return (loader);
if (parent != null)
return (parent.getLoader());
return (null);
}
/**
* Set the Loader with which this Container is associated.
*
* @param loader The newly associated loader
*/
public synchronized void setLoader(Loader loader) {
// Change components if necessary
Loader oldLoader = this.loader;
if (oldLoader == loader)
return;
this.loader = loader;
// Stop the old component if necessary
if (started && (oldLoader != null) &&
(oldLoader instanceof Lifecycle)) {
try {
((Lifecycle) oldLoader).stop();
} catch (LifecycleException e) {
log.error("ContainerBase.setLoader: stop: ", e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -