Extend Lifecycle state machine so global listeners can start before everything else...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jul 2010 16:32:11 +0000 (16:32 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jul 2010 16:32:11 +0000 (16:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@966735 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/Lifecycle.java
java/org/apache/catalina/LifecycleState.java
java/org/apache/catalina/core/AprLifecycleListener.java
java/org/apache/catalina/core/JasperListener.java
java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
java/org/apache/catalina/startup/ContextConfig.java
java/org/apache/catalina/startup/TldConfig.java
java/org/apache/catalina/util/LifecycleBase.java

index 6bd2681..f58d285 100644 (file)
@@ -27,10 +27,12 @@ package org.apache.catalina;
  * <br>
  * The valid state transitions for components that support Lifecycle are:
  * <pre>
- *                                  --------------------<-----------------------
- *                                  |                                          |
- *    init()           start()      |        auto          auto         stop() |
- * NEW ->-- INITIALIZED -->-- STARTING_PREP -->- STARTING -->- STARTED -->---  |
+ *    init()
+ * NEW ->-- INITIALIZING
+ * |||           |                  --------------------<-----------------------
+ * |||           |auto              |                                          |
+ * |||           |     start()      |        auto          auto         stop() |
+ * |||      INITIALIZED -->-- STARTING_PREP -->- STARTING -->- STARTED -->---  |
  * |||                              ^                             |         |  |
  * |||        start()               |                             |         |  |
  * ||----------->--------------------                             |         |  |
@@ -99,9 +101,15 @@ public interface Lifecycle {
 
 
     /**
-     * The LifecycleEvent type for the "component init" event.
+     * The LifecycleEvent type for the "component after init" event.
      */
-    public static final String INIT_EVENT = "init";
+    public static final String BEFORE_INIT_EVENT = "before_init";
+
+
+    /**
+     * The LifecycleEvent type for the "component after init" event.
+     */
+    public static final String AFTER_INIT_EVENT = "after_init";
 
 
     /**
index c108cae..5f2e3b7 100644 (file)
@@ -23,7 +23,8 @@ package org.apache.catalina;
  */
 public enum LifecycleState {
     NEW(false, null),
-    INITIALIZED(false, Lifecycle.INIT_EVENT),
+    INITIALIZING(false, Lifecycle.BEFORE_INIT_EVENT),
+    INITIALIZED(false, Lifecycle.AFTER_INIT_EVENT),
     STARTING_PREP(false, Lifecycle.BEFORE_START_EVENT),
     STARTING(true, Lifecycle.START_EVENT),
     STARTED(true, Lifecycle.AFTER_START_EVENT),
index 41dda35..a3158c2 100644 (file)
@@ -97,7 +97,7 @@ public class AprLifecycleListener
      */
     public void lifecycleEvent(LifecycleEvent event) {
 
-        if (Lifecycle.INIT_EVENT.equals(event.getType())) {
+        if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
             synchronized (lock) {
                 init();
                 if (aprAvailable) {
index 4486b1f..e2e3428 100644 (file)
@@ -57,7 +57,7 @@ public class JasperListener
      */
     public void lifecycleEvent(LifecycleEvent event) {
 
-        if (Lifecycle.INIT_EVENT.equals(event.getType())) {
+        if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
             try {
                 // Set JSP factory
                 Class.forName("org.apache.jasper.compiler.JspRuntimeContext",
index 5a26ee4..e3619cd 100644 (file)
@@ -136,7 +136,7 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener {
     @Override
     public void lifecycleEvent(LifecycleEvent event) {
         // Initialise these classes when Tomcat starts
-        if (Lifecycle.INIT_EVENT.equals(event.getType())) {
+        if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
             /*
              * Several components end up calling:
              * sun.awt.AppContext.getAppContext()
index 2dc6270..76560f5 100644 (file)
@@ -327,7 +327,7 @@ public class ContextConfig
                 originalDocBase = docBase;
             }
             configureStop();
-        } else if (event.getType().equals(Lifecycle.INIT_EVENT)) {
+        } else if (event.getType().equals(Lifecycle.AFTER_INIT_EVENT)) {
             init();
         } else if (event.getType().equals(Lifecycle.DESTROY_EVENT)) {
             destroy();
index ebfd0f9..0f8bffd 100644 (file)
@@ -577,7 +577,7 @@ public final class TldConfig  implements LifecycleListener {
             return;
         }
         
-        if (event.getType().equals(Lifecycle.INIT_EVENT)) {
+        if (event.getType().equals(Lifecycle.AFTER_INIT_EVENT)) {
             init();
         } else if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
             try {
index e33959d..ab9ecc8 100644 (file)
@@ -92,11 +92,12 @@ public abstract class LifecycleBase implements Lifecycle {
     
     public synchronized final void init() throws LifecycleException {
         if (!state.equals(LifecycleState.NEW)) {
-            invalidTransition(Lifecycle.INIT_EVENT);
+            invalidTransition(Lifecycle.BEFORE_INIT_EVENT);
         }
+        setState(LifecycleState.INITIALIZING);
 
         initInternal();
-        
+
         setState(LifecycleState.INITIALIZED);
     }