From a4ac6303e2aaaeebda5a889cb7eee899c5ebdb8e Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 26 Jul 2011 08:25:46 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51555 Permit an additional lifecycle transition. Allow destroy() to be called on components that are initialized. This can occur in some start failure scenarios. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1151016 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/Lifecycle.java | 66 ++++++++++++------------ java/org/apache/catalina/util/LifecycleBase.java | 3 +- webapps/docs/changelog.xml | 4 ++ 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/java/org/apache/catalina/Lifecycle.java b/java/org/apache/catalina/Lifecycle.java index d1e3cde2c..eb2551fc9 100644 --- a/java/org/apache/catalina/Lifecycle.java +++ b/java/org/apache/catalina/Lifecycle.java @@ -14,8 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - package org.apache.catalina; @@ -28,35 +26,38 @@ package org.apache.catalina; * The valid state transitions for components that support {@link Lifecycle} * are: *
- *    init()
- * NEW ->-- INITIALIZING
- * |||           |                  --------------------<-----------------------
- * |||           |auto              |                                          |
- * |||          \|/    start()     \|/       auto          auto         stop() |
- * |||      INITIALIZED -->-- STARTING_PREP -->- STARTING -->- STARTED -->---  |
- * |||                              ^                             |         |  |
- * |||        start()               |                             |         |  |
- * ||----------->--------------------                             |         |  |
- * ||                                                             |         |  |
- * |---                auto                    auto               |         |  |
- * |  |          ---------<----- MUST_STOP ---------------------<--         |  |
- * |  |          |                                                          |  |
- * |  |          ---------------------------<--------------------------------  ^
- * |  |          |                                                             |
- * |  |         \|/            auto                 auto              start()  |
- * |  |     STOPPING_PREP ------>----- STOPPING ------>----- STOPPED ---->------
- * |  |                                   ^                  |  |  ^
- * |  |                  stop()           |                  |  |  |
- * |  |          --------------------------                  |  |  |
- * |  |          |                                  auto     |  |  |
- * |  |          |                  MUST_DESTROY------<-------  |  |
- * |  |          |                    |                         |  |
- * |  |          |                    |auto                     |  |
- * |  |          |    destroy()      \|/              destroy() |  |
- * |  |       FAILED ---->------ DESTROYING ---<-----------------  |
- * |  |                           ^     |                          |
- * |  |        destroy()          |     |auto                      |
- * |  -----------------------------    \|/                         |
+ *            start()
+ *  -----------------------------
+ *  |                           |
+ *  | init()                    |
+ * NEW ->-- INITIALIZING        |
+ * | |           |              |     ------------------<-----------------------
+ * | |           |auto          |     |                                        |
+ * | |          \|/    start() \|/   \|/     auto          auto         stop() |
+ * | |      INITIALIZED -->-- STARTING_PREP -->- STARTING -->- STARTED -->---  |
+ * | |         |                                                  |         |  |
+ * | |         |                                                  |         |  |
+ * | |         |                                                  |         |  |
+ * | |destroy()|                                                  |         |  |
+ * | -->-----<--       auto                    auto               |         |  |
+ * |     |       ---------<----- MUST_STOP ---------------------<--         |  |
+ * |     |       |                                                          |  |
+ * |    \|/      ---------------------------<--------------------------------  ^
+ * |     |       |                                                             |
+ * |     |      \|/            auto                 auto              start()  |
+ * |     |  STOPPING_PREP ------>----- STOPPING ------>----- STOPPED ---->------
+ * |     |                                ^                  |  |  ^
+ * |     |               stop()           |                  |  |  |
+ * |     |       --------------------------                  |  |  |
+ * |     |       |                                  auto     |  |  |
+ * |     |       |                  MUST_DESTROY------<-------  |  |
+ * |     |       |                    |                         |  |
+ * |     |       |                    |auto                     |  |
+ * |     |       |    destroy()      \|/              destroy() |  |
+ * |     |    FAILED ---->------ DESTROYING ---<-----------------  |
+ * |     |                        ^     |                          |
+ * |     |     destroy()          |     |auto                      |
+ * |     -------->-----------------    \|/                         |
  * |                                 DESTROYED                     |
  * |                                                               |
  * |                            stop()                             |
@@ -93,7 +94,8 @@ package org.apache.catalina;
  * methods that trigger the changed. No {@link LifecycleEvent}s are fired if the
  * attempted transition is not valid.
  * 
- * TODO: Not all components may transition from STOPPED to STARTING_PREP
+ * TODO: Not all components may transition from STOPPED to STARTING_PREP. These
+ *       components should use MUST_DESTROY to signal this.
  *
  * @author Craig R. McClanahan
  * @version $Id$
diff --git a/java/org/apache/catalina/util/LifecycleBase.java b/java/org/apache/catalina/util/LifecycleBase.java
index 66b6be268..72ed847ae 100644
--- a/java/org/apache/catalina/util/LifecycleBase.java
+++ b/java/org/apache/catalina/util/LifecycleBase.java
@@ -274,7 +274,8 @@ public abstract class LifecycleBase implements Lifecycle {
         
         if (!state.equals(LifecycleState.STOPPED) &&
                 !state.equals(LifecycleState.FAILED) &&
-                !state.equals(LifecycleState.NEW)) {
+                !state.equals(LifecycleState.NEW) &&
+                !state.equals(LifecycleState.INITIALIZED)) {
             invalidTransition(Lifecycle.BEFORE_DESTROY_EVENT);
         }
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index baf8fd9e7..442e8e50e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -86,6 +86,10 @@
         Authenticators, now return a 500 response rather than a 200 response.
         (markt)
       
+      
+        51555: Allow destroy() to be called on Lifecycle components
+        that are in the initialized state. (markt)
+      
     
   
   
-- 
2.11.0