📄 standardwrapper.java
字号:
}
classLoadTime=(int) (System.currentTimeMillis() -t1);
// Call the initialization method of this servlet
try {
instanceSupport.fireInstanceEvent(InstanceEvent.BEFORE_INIT_EVENT,
servlet);
if( Globals.IS_SECURITY_ENABLED) {
Object[] args = new Object[]{((ServletConfig)facade)};
SecurityUtil.doAsPrivilege("init",
servlet,
classType,
args);
args = null;
} else {
servlet.init(facade);
}
// Invoke jspInit on JSP pages
if ((loadOnStartup >= 0) && (jspFile != null)) {
// Invoking jspInit
DummyRequest req = new DummyRequest();
req.setServletPath(jspFile);
req.setQueryString("jsp_precompile=true");
DummyResponse res = new DummyResponse();
if( Globals.IS_SECURITY_ENABLED) {
Object[] args = new Object[]{req, res};
SecurityUtil.doAsPrivilege("service",
servlet,
classTypeUsedInService,
args);
args = null;
} else {
servlet.service(req, res);
}
}
instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT,
servlet);
} catch (UnavailableException f) {
instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT,
servlet, f);
unavailable(f);
throw f;
} catch (ServletException f) {
instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT,
servlet, f);
// If the servlet wanted to be unavailable it would have
// said so, so do not call unavailable(null).
throw f;
} catch (Throwable f) {
getServletContext().log("StandardWrapper.Throwable", f );
instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT,
servlet, f);
// If the servlet wanted to be unavailable it would have
// said so, so do not call unavailable(null).
throw new ServletException
(sm.getString("standardWrapper.initException", getName()), f);
}
// Register our newly initialized instance
singleThreadModel = servlet instanceof SingleThreadModel;
if (singleThreadModel) {
if (instancePool == null)
instancePool = new Stack();
}
fireContainerEvent("load", this);
loadTime=System.currentTimeMillis() -t1;
} finally {
if (swallowOutput) {
String log = SystemLogHandler.stopCapture();
if (log != null && log.length() > 0) {
if (getServletContext() != null) {
getServletContext().log(log);
} else {
out.println(log);
}
}
}
}
return servlet;
}
/**
* Remove the specified initialization parameter from this servlet.
*
* @param name Name of the initialization parameter to remove
*/
public void removeInitParameter(String name) {
synchronized (parameters) {
parameters.remove(name);
}
fireContainerEvent("removeInitParameter", name);
}
/**
* Remove a listener no longer interested in InstanceEvents.
*
* @param listener The listener to remove
*/
public void removeInstanceListener(InstanceListener listener) {
instanceSupport.removeInstanceListener(listener);
}
/**
* Remove a mapping associated with the wrapper.
*
* @param mapping The pattern to remove
*/
public void removeMapping(String mapping) {
synchronized (mappings) {
mappings.remove(mapping);
}
fireContainerEvent("removeMapping", mapping);
}
/**
* Remove any security role reference for the specified role name.
*
* @param name Security role used within this servlet to be removed
*/
public void removeSecurityReference(String name) {
synchronized (references) {
references.remove(name);
}
fireContainerEvent("removeSecurityReference", name);
}
/**
* Return a String representation of this component.
*/
public String toString() {
StringBuffer sb = new StringBuffer();
if (getParent() != null) {
sb.append(getParent().toString());
sb.append(".");
}
sb.append("StandardWrapper[");
sb.append(getName());
sb.append("]");
return (sb.toString());
}
/**
* Process an UnavailableException, marking this servlet as unavailable
* for the specified amount of time.
*
* @param unavailable The exception that occurred, or <code>null</code>
* to mark this servlet as permanently unavailable
*/
public void unavailable(UnavailableException unavailable) {
getServletContext().log(sm.getString("standardWrapper.unavailable", getName()));
if (unavailable == null)
setAvailable(Long.MAX_VALUE);
else if (unavailable.isPermanent())
setAvailable(Long.MAX_VALUE);
else {
int unavailableSeconds = unavailable.getUnavailableSeconds();
if (unavailableSeconds <= 0)
unavailableSeconds = 60; // Arbitrary default
setAvailable(System.currentTimeMillis() +
(unavailableSeconds * 1000L));
}
}
/**
* Unload all initialized instances of this servlet, after calling the
* <code>destroy()</code> method for each instance. This can be used,
* for example, prior to shutting down the entire servlet engine, or
* prior to reloading all of the classes from the Loader associated with
* our Loader's repository.
*
* @exception ServletException if an exception is thrown by the
* destroy() method
*/
public synchronized void unload() throws ServletException {
// Nothing to do if we have never loaded the instance
if (!singleThreadModel && (instance == null))
return;
unloading = true;
// Loaf a while if the current instance is allocated
// (possibly more than once if non-STM)
if (countAllocated > 0) {
int nRetries = 0;
long delay = unloadDelay / 20;
while ((nRetries < 21) && (countAllocated > 0)) {
if ((nRetries % 10) == 0) {
log.info(sm.getString("standardWrapper.waiting",
new Integer(countAllocated)));
}
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
;
}
nRetries++;
}
}
PrintStream out = System.out;
if (swallowOutput) {
SystemLogHandler.startCapture();
}
// Call the servlet destroy() method
try {
instanceSupport.fireInstanceEvent
(InstanceEvent.BEFORE_DESTROY_EVENT, instance);
if( Globals.IS_SECURITY_ENABLED) {
SecurityUtil.doAsPrivilege("destroy",
instance);
SecurityUtil.remove(instance);
} else {
instance.destroy();
}
instanceSupport.fireInstanceEvent
(InstanceEvent.AFTER_DESTROY_EVENT, instance);
// Annotation processing
if (!((Context) getParent()).getIgnoreAnnotations()) {
((StandardContext)getParent()).getAnnotationProcessor().preDestroy(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 {
// 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 {
while (!instancePool.isEmpty()) {
Servlet s = (Servlet) instancePool.pop();
if (Globals.IS_SECURITY_ENABLED) {
SecurityUtil.doAsPrivilege("destroy", s);
SecurityUtil.remove(instance);
} else {
s.destroy();
}
// Annotation processing
if (!((Context) getParent()).getIgnoreAnnotations()) {
((StandardContext)getParent()).getAnnotationProcessor().preDestroy(s);
}
}
} catch (Throwable t) {
instancePool = null;
nInstances = 0;
unloading = false;
fireContainerEvent("unload", this);
throw new ServletException
(sm.getString("standardWrapper.destroyException",
getName()), t);
}
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -