📄 containerbase.java
字号:
/**
* <p>Return the Valve instance that has been distinguished as the basic
* Valve for this Pipeline (if any).
*/
public Valve getBasic() {
return (pipeline.getBasic());
}
/**
* Return the first valve in the pipeline.
*/
public Valve getFirst() {
return (pipeline.getFirst());
}
/**
* 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.
*/
public Valve[] getValves() {
return (pipeline.getValves());
}
/**
* Remove the specified Valve from the pipeline associated with this
* Container, if it is found; otherwise, do nothing.
*
* @param valve Valve to be removed
*/
public synchronized void removeValve(Valve valve) {
pipeline.removeValve(valve);
fireContainerEvent(REMOVE_VALVE_EVENT, valve);
}
/**
* <p>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 <code>setContainer()</code> will be called, if it
* implements <code>Contained</code>, with the owning Container as an
* argument. The method may throw an <code>IllegalArgumentException</code>
* if this Valve chooses not to be associated with this Container, or
* <code>IllegalStateException</code> if it is already associated with
* a different Container.</p>
*
* @param valve Valve to be distinguished as the basic Valve
*/
public void setBasic(Valve valve) {
pipeline.setBasic(valve);
}
/**
* 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.
*/
public void backgroundProcess() {
if (!started)
return;
if (cluster != null) {
try {
cluster.backgroundProcess();
} catch (Exception e) {
log.warn(sm.getString("containerBase.backgroundProcess.cluster", cluster), e);
}
}
if (loader != null) {
try {
loader.backgroundProcess();
} catch (Exception e) {
log.warn(sm.getString("containerBase.backgroundProcess.loader", loader), e);
}
}
if (manager != null) {
try {
manager.backgroundProcess();
} catch (Exception e) {
log.warn(sm.getString("containerBase.backgroundProcess.manager", manager), e);
}
}
if (realm != null) {
try {
realm.backgroundProcess();
} catch (Exception e) {
log.warn(sm.getString("containerBase.backgroundProcess.realm", realm), e);
}
}
Valve current = pipeline.getFirst();
while (current != null) {
try {
current.backgroundProcess();
} catch (Exception e) {
log.warn(sm.getString("containerBase.backgroundProcess.valve", current), e);
}
current = current.getNext();
}
lifecycle.fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null);
}
// ------------------------------------------------------ Protected Methods
/**
* 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.
*
* @param type Event type
* @param data Event data
*/
public void fireContainerEvent(String type, Object data) {
if (listeners.size() < 1)
return;
ContainerEvent event = new ContainerEvent(this, type, data);
ContainerListener list[] = new ContainerListener[0];
synchronized (listeners) {
list = (ContainerListener[]) listeners.toArray(list);
}
for (int i = 0; i < list.length; i++)
((ContainerListener) list[i]).containerEvent(event);
}
/**
* Return the abbreviated name of this container for logging messsages
*/
protected String logName() {
if (logName != null) {
return logName;
}
String loggerName = null;
Container current = this;
while (current != null) {
String name = current.getName();
if ((name == null) || (name.equals(""))) {
name = "/";
}
loggerName = "[" + name + "]"
+ ((loggerName != null) ? ("." + loggerName) : "");
current = current.getParent();
}
logName = ContainerBase.class.getName() + "." + loggerName;
return logName;
}
// -------------------- JMX and Registration --------------------
protected String type;
protected String domain;
protected String suffix;
protected ObjectName oname;
protected ObjectName controller;
protected transient MBeanServer mserver;
public ObjectName getJmxName() {
return oname;
}
public String getObjectName() {
if (oname != null) {
return oname.toString();
} else return null;
}
public String getDomain() {
if( domain==null ) {
Container parent=this;
while( parent != null &&
!( parent instanceof StandardEngine) ) {
parent=parent.getParent();
}
if( parent instanceof StandardEngine ) {
domain=((StandardEngine)parent).getDomain();
}
}
return domain;
}
public void setDomain(String domain) {
this.domain=domain;
}
public String getType() {
return type;
}
protected String getJSR77Suffix() {
return suffix;
}
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
oname=name;
mserver=server;
if (name == null ){
return null;
}
domain=name.getDomain();
type=name.getKeyProperty("type");
if( type==null ) {
type=name.getKeyProperty("j2eeType");
}
String j2eeApp=name.getKeyProperty("J2EEApplication");
String j2eeServer=name.getKeyProperty("J2EEServer");
if( j2eeApp==null ) {
j2eeApp="none";
}
if( j2eeServer==null ) {
j2eeServer="none";
}
suffix=",J2EEApplication=" + j2eeApp + ",J2EEServer=" + j2eeServer;
return name;
}
public void postRegister(Boolean registrationDone) {
}
public void preDeregister() throws Exception {
}
public void postDeregister() {
}
public ObjectName[] getChildren() {
ObjectName result[]=new ObjectName[children.size()];
Iterator it=children.values().iterator();
int i=0;
while( it.hasNext() ) {
Object next=it.next();
if( next instanceof ContainerBase ) {
result[i++]=((ContainerBase)next).getJmxName();
}
}
return result;
}
public ObjectName createObjectName(String domain, ObjectName parent)
throws Exception
{
if( log.isDebugEnabled())
log.debug("Create ObjectName " + domain + " " + parent );
return null;
}
public String getContainerSuffix() {
Container container=this;
Container context=null;
Container host=null;
Container servlet=null;
StringBuffer suffix=new StringBuffer();
if( container instanceof StandardHost ) {
host=container;
} else if( container instanceof StandardContext ) {
host=container.getParent();
context=container;
} else if( container instanceof StandardWrapper ) {
context=container.getParent();
host=context.getParent();
servlet=container;
}
if( context!=null ) {
String path=((StandardContext)context).getPath();
suffix.append(",path=").append((path.equals("")) ? "/" : path);
}
if( host!=null ) suffix.append(",host=").append( host.getName() );
if( servlet != null ) {
String name=container.getName();
suffix.append(",servlet=");
suffix.append((name=="") ? "/" : name);
}
return suffix.toString();
}
/**
* Start the background thread that will periodically check for
* session timeouts.
*/
protected void threadStart() {
if (thread != null)
return;
if (backgroundProcessorDelay <= 0)
return;
threadDone = false;
String threadName = "ContainerBackgroundProcessor[" + toString() + "]";
thread = new Thread(new ContainerBackgroundProcessor(), threadName);
thread.setDaemon(true);
thread.start();
}
/**
* Stop the background thread that is periodically checking for
* session timeouts.
*/
protected void threadStop() {
if (thread == null)
return;
threadDone = true;
thread.interrupt();
try {
thread.join();
} catch (InterruptedException e) {
;
}
thread = null;
}
// -------------------------------------- ContainerExecuteDelay Inner Class
/**
* Private thread class to invoke the backgroundProcess method
* of this container and its children after a fixed delay.
*/
protected class ContainerBackgroundProcessor implements Runnable {
public void run() {
while (!threadDone) {
try {
Thread.sleep(backgroundProcessorDelay * 1000L);
} catch (InterruptedException e) {
;
}
if (!threadDone) {
Container parent = (Container) getMappingObject();
ClassLoader cl =
Thread.currentThread().getContextClassLoader();
if (parent.getLoader() != null) {
cl = parent.getLoader().getClassLoader();
}
processChildren(parent, cl);
}
}
}
protected void processChildren(Container container, ClassLoader cl) {
try {
if (container.getLoader() != null) {
Thread.currentThread().setContextClassLoader
(container.getLoader().getClassLoader());
}
container.backgroundProcess();
} catch (Throwable t) {
log.error("Exception invoking periodic operation: ", t);
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
Container[] children = container.findChildren();
for (int i = 0; i < children.length; i++) {
if (children[i].getBackgroundProcessorDelay() <= 0) {
processChildren(children[i], cl);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -