📄 standardwrapper.java
字号:
if (swallowOutput) {
SystemLogHandler.startCapture();
}
// Call the servlet destroy() method
try {
instanceSupport.fireInstanceEvent
(InstanceEvent.BEFORE_DESTROY_EVENT, instance);
Thread.currentThread().setContextClassLoader(classLoader);
if( System.getSecurityManager() != null) {
SecurityUtil.doAsPrivilege("destroy",
instance);
SecurityUtil.remove(instance);
} else {
instance.destroy();
}
instanceSupport.fireInstanceEvent
(InstanceEvent.AFTER_DESTROY_EVENT, instance);
} catch (Throwable t) {
instanceSupport.fireInstanceEvent
(InstanceEvent.AFTER_DESTROY_EVENT, instance, t);
instance = null;
instancePool = null;
nInstances = 0;
fireContainerEvent("unload", this);
unloading = false;
throw new ServletException
(sm.getString("standardWrapper.destroyException", getName()),
t);
} finally {
// restore the context ClassLoader
Thread.currentThread().setContextClassLoader(oldCtxClassLoader);
// Write captured output
if (swallowOutput) {
String log = SystemLogHandler.stopCapture();
if (log != null && log.length() > 0) {
if (getServletContext() != null) {
getServletContext().log(log);
} else {
out.println(log);
}
}
}
}
// Deregister the destroyed instance
instance = null;
if (singleThreadModel && (instancePool != null)) {
try {
Thread.currentThread().setContextClassLoader(classLoader);
while (!instancePool.isEmpty()) {
if( System.getSecurityManager() != null) {
SecurityUtil.doAsPrivilege("destroy",
((Servlet) instancePool.pop()));
SecurityUtil.remove(instance);
} else {
((Servlet) instancePool.pop()).destroy();
}
}
} catch (Throwable t) {
instancePool = null;
nInstances = 0;
unloading = false;
fireContainerEvent("unload", this);
throw new ServletException
(sm.getString("standardWrapper.destroyException",
getName()), t);
} finally {
// restore the context ClassLoader
Thread.currentThread().setContextClassLoader
(oldCtxClassLoader);
}
instancePool = null;
nInstances = 0;
}
singleThreadModel = false;
unloading = false;
fireContainerEvent("unload", this);
}
// -------------------------------------------------- ServletConfig Methods
/**
* Return the initialization parameter value for the specified name,
* if any; otherwise return <code>null</code>.
*
* @param name Name of the initialization parameter to retrieve
*/
public String getInitParameter(String name) {
return (findInitParameter(name));
}
/**
* Return the set of initialization parameter names defined for this
* servlet. If none are defined, an empty Enumeration is returned.
*/
public Enumeration getInitParameterNames() {
synchronized (parameters) {
return (new Enumerator(parameters.keySet()));
}
}
/**
* Return the servlet context with which this servlet is associated.
*/
public ServletContext getServletContext() {
if (parent == null)
return (null);
else if (!(parent instanceof Context))
return (null);
else
return (((Context) parent).getServletContext());
}
/**
* Return the name of this servlet.
*/
public String getServletName() {
return (getName());
}
public long getProcessingTime() {
return swValve.getProcessingTime();
}
public void setProcessingTime(long processingTime) {
swValve.setProcessingTime(processingTime);
}
public long getMaxTime() {
return swValve.getMaxTime();
}
public void setMaxTime(long maxTime) {
swValve.setMaxTime(maxTime);
}
public long getMinTime() {
return swValve.getMinTime();
}
public void setMinTime(long minTime) {
swValve.setMinTime(minTime);
}
public int getRequestCount() {
return swValve.getRequestCount();
}
public void setRequestCount(int requestCount) {
swValve.setRequestCount(requestCount);
}
public int getErrorCount() {
return swValve.getErrorCount();
}
public void setErrorCount(int errorCount) {
swValve.setErrorCount(errorCount);
}
/**
* Increment the error count used for monitoring.
*/
public void incrementErrorCount(){
swValve.setErrorCount(swValve.getErrorCount() + 1);
}
public long getLoadTime() {
return loadTime;
}
public void setLoadTime(long loadTime) {
this.loadTime = loadTime;
}
public int getClassLoadTime() {
return classLoadTime;
}
// -------------------------------------------------------- Package Methods
// -------------------------------------------------------- Private Methods
/**
* Add a default Mapper implementation if none have been configured
* explicitly.
*
* @param mapperClass Java class name of the default Mapper
*/
protected void addDefaultMapper(String mapperClass) {
; // No need for a default Mapper on a Wrapper
}
/**
* Return <code>true</code> if the specified class name represents a
* container provided servlet class that should be loaded by the
* server class loader.
*
* @param classname Name of the class to be checked
*/
private boolean isContainerProvidedServlet(String classname) {
if (classname.startsWith("org.apache.catalina.")) {
return (true);
}
try {
Class clazz =
this.getClass().getClassLoader().loadClass(classname);
return (ContainerServlet.class.isAssignableFrom(clazz));
} catch (Throwable t) {
return (false);
}
}
/**
* Return <code>true</code> if loading this servlet is allowed.
*/
private boolean isServletAllowed(Object servlet) {
if (servlet instanceof ContainerServlet) {
if (((Context) getParent()).getPrivileged()
|| (servlet.getClass().getName().equals
("org.apache.catalina.servlets.InvokerServlet"))) {
return (true);
} else {
return (false);
}
}
return (true);
}
/**
* Log the abbreviated name of this Container for logging messages.
*/
protected String logName() {
StringBuffer sb = new StringBuffer("StandardWrapper[");
if (getParent() != null)
sb.append(getParent().getName());
else
sb.append("null");
sb.append(':');
sb.append(getName());
sb.append(']');
return (sb.toString());
}
// ------------------------------------------------------ Lifecycle Methods
/**
* Start this component, pre-loading the servlet if the load-on-startup
* value is set appropriately.
*
* @exception LifecycleException if a fatal error occurs during startup
*/
public void start() throws LifecycleException {
// Send j2ee.state.starting notification
if (this.getObjectName() != null) {
Notification notification = new Notification("j2ee.state.starting",
this.getObjectName(),
sequenceNumber++);
broadcaster.sendNotification(notification);
}
// Start up this component
super.start();
if( oname != null )
registerJMX((StandardContext)getParent());
// Load and initialize an instance of this servlet if requested
// MOVED TO StandardContext START() METHOD
setAvailable(0L);
// Send j2ee.state.running notification
if (this.getObjectName() != null) {
Notification notification =
new Notification("j2ee.state.running", this.getObjectName(),
sequenceNumber++);
broadcaster.sendNotification(notification);
}
}
/**
* Stop this component, gracefully shutting down the servlet if it has
* been initialized.
*
* @exception LifecycleException if a fatal error occurs during shutdown
*/
public void stop() throws LifecycleException {
setAvailable(Long.MAX_VALUE);
// Send j2ee.state.stopping notification
if (this.getObjectName() != null) {
Notification notification =
new Notification("j2ee.state.stopping", this.getObjectName(),
sequenceNumber++);
broadcaster.sendNotification(notification);
}
// Shut down our servlet instance (if it has been initialized)
try {
unload();
} catch (ServletException e) {
getServletContext().log(sm.getString
("standardWrapper.unloadException", getName()), e);
}
// Shut down this component
super.stop();
// Send j2ee.state.stoppped notification
if (this.getObjectName() != null) {
Notification notification =
new Notification("j2ee.state.stopped", this.getObjectName(),
sequenceNumber++);
broadcaster.sendNotification(notification);
}
if( oname != null ) {
Registry.getRegistry(null, null).unregisterComponent(oname);
// Send j2ee.object.deleted notification
Notification notification =
new Notification("j2ee.object.deleted", this.getObjectName(),
sequenceNumber++);
broadcaster.sendNotification(notification);
}
}
protected void registerJMX(StandardContext ctx) {
try {
// it should be full name
String parentName=ctx.getName();
String hostName=ctx.getParent().getName();
String webMod= "//" + ((hostName==null)? "DEFAULT" :hostName ) +
(("".equals(parentName) ) ? "/" : parentName );
String onameStr=ctx.getDomain() +
":j2eeType=Servlet,name=" + getName() + ",WebModule=" +
webMod + ",J2EEApplication=" +
ctx.getJ2EEApplication() + ",J2EEServer=" +
ctx.getJ2EEServer();
oname=new ObjectName(onameStr);
controller=oname;
Registry.getRegistry(null, null)
.registerComponent(this, oname, null );
// Send j2ee.object.created notification
if (this.getObjectName() != null) {
Notification notification = new Notification(
"j2ee.object.created",
this.getObjectName(),
sequenceNumber++);
broadcaster.sendNotification(notification);
}
} catch( Exception ex ) {
log.info("Error registering servlet with jmx " + this);
}
}
// ------------------------------------------------------------- Attributes
public boolean isEventProvider() {
return false;
}
public boolean isStateManageable() {
return false;
}
public boolean isStatisticsProvider() {
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -