Handle component failure without throwing a whole stack of exceptions
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Mar 2010 12:39:57 +0000 (12:39 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Mar 2010 12:39:57 +0000 (12:39 +0000)
Adds a new permitted transition from NEW to STOPPED that does not fire any events

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@920297 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/Lifecycle.java
java/org/apache/catalina/util/LifecycleBase.java

index d92cfb4..7fac3c2 100644 (file)
@@ -27,23 +27,25 @@ package org.apache.catalina;
  * <br>
  * The valid state transitions for components that support Lifecycle are:
  * <pre>
- *                  --------------------<--------------------------
- *                  |                                             |
- *     start()      |        auto          auto         stop()    |       
- * NEW --->--- STARTING_PREP -->- STARTING -->- STARTED -->---    |
- *                                                 |         |    |
- *                                     auto        |         |    |
- *      ---------<----- MUST_STOP --<---------------         |    |
- *      |                                                    |    |
- *      ---------------------------<--------------------------    ^
- *      |                                                         |
- *      |        auto          auto                start()        |
- * STOPPING_PREP -->- STOPPING -->- STOPPED -------------->--------
- *      ^
- *      |stop()
- *      |
- *   FAILED
- * 
+ *                            --------------------<--------------------------
+ *                            |                                             |
+ *               start()      |        auto          auto         stop()    |       
+ * NEW ------------->--- STARTING_PREP -->- STARTING -->- STARTED -->---    |
+ *  |                                                        |         |    |
+ *  |                                            auto        |         |    |
+ *  |stop()       ---------<----- MUST_STOP --<---------------         |    |
+ *  |             |                                                    |    |
+ *  |             ---------------------------<--------------------------    ^
+ *  |             |                                                         |
+ *  |             |        auto          auto                start()        |
+ *  |        STOPPING_PREP -->- STOPPING -->- STOPPED -------------->--------
+ *  |             ^                              ^
+ *  |             |stop()                        |
+ *  |             |                              |
+ *  |          FAILED                            |
+ *  |                                            |
+ *  --->------------------------------>-----------
+ *   
  * Any state can transition to FAILED.
  * 
  * Calling start() while a component is in states STARTING_PREP, STARTING or
@@ -52,6 +54,11 @@ package org.apache.catalina;
  * Calling stop() while a component is in states STOPPING_PREP, STOPPING or
  * STOPPED has no effect.
  * 
+ * Calling stop() while a component is in state NEW transitions the component
+ * to STOPPED. This is typically encountered when a component fails to start and
+ * does not start all its sub-components. When the component is stopped, it will
+ * try to stop all sub-components - even those it didn't start.
+ * 
  * MUST_STOP is used to indicate that the {@link #stop()} should be called on
  * the component as soon as {@link start()} exits.
  * 
index b32620a..5f270be 100644 (file)
@@ -185,6 +185,11 @@ public abstract class LifecycleBase implements Lifecycle {
                 return;
             }
             
+            if (state.equals(LifecycleState.NEW)) {
+                state = LifecycleState.STOPPED;
+                return;
+            }
+
             if (!state.equals(LifecycleState.STARTED) &&
                     !state.equals(LifecycleState.FAILED)) {
                 invalidTransition(Lifecycle.BEFORE_STOP_EVENT);