Author: remy.maucherat(a)jboss.com
Date: 2014-10-09 09:28:38 -0400 (Thu, 09 Oct 2014)
New Revision: 2525
Modified:
branches/7.5.x/src/main/java/org/apache/catalina/Lifecycle.java
branches/7.5.x/src/main/java/org/apache/catalina/core/StandardContext.java
branches/7.5.x/src/main/java/org/apache/catalina/startup/ContextConfig.java
Log:
JBWEB-304: Add load on startup hack hooks. Submitted by Chao Wang.
Modified: branches/7.5.x/src/main/java/org/apache/catalina/Lifecycle.java
===================================================================
--- branches/7.5.x/src/main/java/org/apache/catalina/Lifecycle.java 2014-10-09 12:05:29
UTC (rev 2524)
+++ branches/7.5.x/src/main/java/org/apache/catalina/Lifecycle.java 2014-10-09 13:28:38
UTC (rev 2525)
@@ -89,6 +89,24 @@
public static final String PERIODIC_EVENT = "periodic";
+ /**
+ * The LifecycleEvent type for the "component before load on startup"
event.
+ */
+ public static final String BEFORE_LOAD_ON_STARTUP_EVENT =
"before_load_on_startup";
+
+
+ /**
+ * The LifecycleEvent type for the "component after load on startup"
event.
+ */
+ public static final String AFTER_LOAD_ON_STARTUP_EVENT =
"after_load_on_startup";
+
+
+ /**
+ * The LifecycleEvent type for the "component load on startup" event.
+ */
+ public static final String LOAD_ON_STARTUP_EVENT = "load_on_startup";
+
+
// --------------------------------------------------------- Public Methods
Modified: branches/7.5.x/src/main/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- branches/7.5.x/src/main/java/org/apache/catalina/core/StandardContext.java 2014-10-09
12:05:29 UTC (rev 2524)
+++ branches/7.5.x/src/main/java/org/apache/catalina/core/StandardContext.java 2014-10-09
13:28:38 UTC (rev 2525)
@@ -3588,7 +3588,10 @@
for (ArrayList<Wrapper> list : map.values()) {
for (Wrapper wrapper : list) {
try {
+ String servletClass = wrapper.getServletClass();
+ lifecycle.fireLifecycleEvent(Lifecycle.BEFORE_LOAD_ON_STARTUP_EVENT,
servletClass);
wrapper.load();
+ lifecycle.fireLifecycleEvent(Lifecycle.AFTER_LOAD_ON_STARTUP_EVENT,
servletClass);
} catch (ServletException e) {
getLogger().error(MESSAGES.errorLoadingServlet(wrapper.getName()),
StandardWrapper.getRootCause(e));
// NOTE: load errors (including a servlet that throws
@@ -3795,6 +3798,7 @@
// Load and initialize all "load on startup" servlets
if (ok) {
+ lifecycle.fireLifecycleEvent(LOAD_ON_STARTUP_EVENT, null);
loadOnStartup(findChildren());
}
Modified: branches/7.5.x/src/main/java/org/apache/catalina/startup/ContextConfig.java
===================================================================
--- branches/7.5.x/src/main/java/org/apache/catalina/startup/ContextConfig.java 2014-10-09
12:05:29 UTC (rev 2524)
+++ branches/7.5.x/src/main/java/org/apache/catalina/startup/ContextConfig.java 2014-10-09
13:28:38 UTC (rev 2525)
@@ -172,6 +172,12 @@
init();
} else if (event.getType().equals(Lifecycle.DESTROY_EVENT)) {
destroy();
+ } else if (event.getType().equals(Lifecycle.LOAD_ON_STARTUP_EVENT)) {
+ loadOnStartup();
+ } else if (event.getType().equals(Lifecycle.BEFORE_LOAD_ON_STARTUP_EVENT)) {
+ beforeLoadOnStartup(event.getData());
+ } else if (event.getType().equals(Lifecycle.AFTER_LOAD_ON_STARTUP_EVENT)) {
+ afterLoadOnStartup(event.getData());
}
}
@@ -411,6 +417,18 @@
}
+ protected void loadOnStartup() {
+
+ }
+
+ protected void beforeLoadOnStartup(Object data) {
+
+ }
+
+ protected void afterLoadOnStartup(Object data) {
+
+ }
+
/**
* Process a "stop" event for this Context.
*/
Show replies by date