craigmcc 01/06/23 12:50:31
Modified: catalina/src/share/org/apache/catalina/core
StandardContext.java
Log:
When reloading an application, call the init() method of all
load-on-startup servlets so that they can restore any required application
specific state that is required. These servlets will be called in the
same order as when the application was first started, based on the
<load-on-startup> values.
Revision Changes Path
1.65 +59 -48
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java
Index: StandardContext.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- StandardContext.java 2001/06/23 19:25:24 1.64
+++ StandardContext.java 2001/06/23 19:50:30 1.65
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
1.64 2001/06/23 19:25:24 craigmcc Exp $
- * $Revision: 1.64 $
- * $Date: 2001/06/23 19:25:24 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
1.65 2001/06/23 19:50:30 craigmcc Exp $
+ * $Revision: 1.65 $
+ * $Date: 2001/06/23 19:50:30 $
*
* ====================================================================
*
@@ -141,7 +141,7 @@
*
* @author Craig R. McClanahan
* @author Remy Maucherat
- * @version $Revision: 1.64 $ $Date: 2001/06/23 19:25:24 $
+ * @version $Revision: 1.65 $ $Date: 2001/06/23 19:50:30 $
*/
public class StandardContext
@@ -2392,6 +2392,9 @@
}
}
+ // Reinitialize all load on startup servlets
+ loadOnStartup(children);
+
// Unbinding thread
unbindThread();
@@ -3133,6 +3136,56 @@
/**
+ * Load and initialize all servlets marked "load on startup" in the
+ * web application deployment descriptor.
+ *
+ * @param children Array of wrappers for all currently defined
+ * servlets (including those not declared load on startup)
+ */
+ public void loadOnStartup(Container children[]) {
+
+ // Collect "load on startup" servlets that need to be initialized
+ TreeMap map = new TreeMap();
+ for (int i = 0; i < children.length; i++) {
+ Wrapper wrapper = (Wrapper) children[i];
+ int loadOnStartup = wrapper.getLoadOnStartup();
+ if (loadOnStartup < 0)
+ continue;
+ if (loadOnStartup == 0) // Arbitrarily put them last
+ loadOnStartup = Integer.MAX_VALUE;
+ Integer key = new Integer(loadOnStartup);
+ ArrayList list = (ArrayList) map.get(key);
+ if (list == null) {
+ list = new ArrayList();
+ map.put(key, list);
+ }
+ list.add(wrapper);
+ }
+
+ // Load the collected "load on startup" servlets
+ Iterator keys = map.keySet().iterator();
+ while (keys.hasNext()) {
+ Integer key = (Integer) keys.next();
+ ArrayList list = (ArrayList) map.get(key);
+ Iterator wrappers = list.iterator();
+ while (wrappers.hasNext()) {
+ Wrapper wrapper = (Wrapper) wrappers.next();
+ try {
+ wrapper.load();
+ } catch (ServletException e) {
+ log(sm.getString("standardWrapper.loadException",
+ getName()), e);
+ // NOTE: load errors (including a servlet that throws
+ // UnavailableException from tht init() method) are NOT
+ // fatal to application startup
+ }
+ }
+ }
+
+ }
+
+
+ /**
* Start this Context component.
*
* @exception LifecycleException if a startup error occurs
@@ -3219,51 +3272,9 @@
log("Posting standard context attributes");
postWelcomeFiles();
}
-
- // Collect "load on startup" servlets that need to be initialized
- if (debug >= 1)
- log("Identifying load-on-startup servlets");
- TreeMap map = new TreeMap();
- Container children[] = findChildren();
- for (int i = 0; i < children.length; i++) {
- Wrapper wrapper = (Wrapper) children[i];
- int loadOnStartup = wrapper.getLoadOnStartup();
- if (loadOnStartup < 0)
- continue;
- if (loadOnStartup == 0) // Arbitrarily put them last
- loadOnStartup = Integer.MAX_VALUE;
- Integer key = new Integer(loadOnStartup);
- ArrayList list = (ArrayList) map.get(key);
- if (list == null) {
- list = new ArrayList();
- map.put(key, list);
- }
- list.add(wrapper);
- }
- // Load the collected "load on startup" servlets
- if (debug >= 1)
- log("Loading " + map.size() + " load-on-startup servlets");
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- Integer key = (Integer) keys.next();
- ArrayList list = (ArrayList) map.get(key);
- Iterator wrappers = list.iterator();
- while (wrappers.hasNext()) {
- if (!ok)
- break;
- Wrapper wrapper = (Wrapper) wrappers.next();
- try {
- wrapper.load();
- } catch (ServletException e) {
- log(sm.getString("standardWrapper.loadException",
- getName()), e);
- // NOTE: load errors (including a servlet that throws
- // UnavailableException from tht init() method) are NOT
- // fatal to application startup
- }
- }
- }
+ // Load and initialize all "load on startup" servlets
+ loadOnStartup(findChildren());
// Unbinding thread
unbindThread();