Author: markt
Date: Tue Jan 19 19:34:04 2016
New Revision: 1725599

URL: http://svn.apache.org/viewvc?rev=1725599&view=rev
Log:
Deprecate lifecycle states that were never used and could never be used.
Add new Lifecycle.SingleUse marker interface as a replacement for
MUST_DESTROY
Document how to use FAILED as a work-around for MUST_STOP
Code clean-up

Modified:
    tomcat/trunk/java/org/apache/catalina/Lifecycle.java
    tomcat/trunk/java/org/apache/catalina/LifecycleState.java
    tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java

Modified: tomcat/trunk/java/org/apache/catalina/Lifecycle.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Lifecycle.java?rev=1725599&r1=1725598&r2=1725599&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Lifecycle.java [UTF-8] (original)
+++ tomcat/trunk/java/org/apache/catalina/Lifecycle.java [UTF-8] Tue Jan 19 
19:34:04 2016
@@ -35,25 +35,17 @@ package org.apache.catalina;
  * | |           |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() |  |
+ * | |         |                                                            |  
|
+ * | |destroy()|                                                            |  
|
+ * | --»-----«--    ------------------------«--------------------------------  
^
+ * |     |          |                                                          
|
+ * |     |         \|/          auto                 auto              start() 
|
+ * |     |     STOPPING_PREP ----»---- STOPPING ------»----- STOPPED 
-----»-----
+ * |    \|/                               ^                     |  ^
+ * |     |               stop()           |                     |  |
+ * |     |       --------------------------                     |  |
+ * |     |       |                                              |  |
+ * |     |       |    destroy()                       destroy() |  |
  * |     |    FAILED ----»------ DESTROYING ---«-----------------  |
  * |     |                        ^     |                          |
  * |     |     destroy()          |     |auto                      |
@@ -79,14 +71,6 @@ package org.apache.catalina;
  * 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. It is typically used when a
- * component has failed to start.
- *
- * MUST_DESTROY is used to indicate that the {@link #destroy()} should be 
called on
- * the component as soon as {@link #stop()} exits. It is typically used when a
- * component is not designed to be restarted.
- *
  * Attempting any other transition will throw {@link LifecycleException}.
  *
  * </pre>
@@ -94,9 +78,6 @@ 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. These
- *       components should use MUST_DESTROY to signal this.
- *
  * @author Craig R. McClanahan
  */
 public interface Lifecycle {
@@ -325,4 +306,14 @@ public interface Lifecycle {
      * @return The name of the current component state.
      */
     public String getStateName();
+
+
+    /**
+     * Marker interface used to indicate that the instance should only be used
+     * once. Calling {@link #stop()} on an instance that supports this 
interface
+     * will automatically call {@link #destroy()} after {@link #stop()}
+     * completes.
+     */
+    public interface SingleUse {
+    }
 }

Modified: tomcat/trunk/java/org/apache/catalina/LifecycleState.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/LifecycleState.java?rev=1725599&r1=1725598&r2=1725599&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/LifecycleState.java (original)
+++ tomcat/trunk/java/org/apache/catalina/LifecycleState.java Tue Jan 19 
19:34:04 2016
@@ -33,7 +33,23 @@ public enum LifecycleState {
     DESTROYING(false, Lifecycle.BEFORE_DESTROY_EVENT),
     DESTROYED(false, Lifecycle.AFTER_DESTROY_EVENT),
     FAILED(false, null),
+    /**
+     * @deprecated Unused. Will be removed in Tomcat 9.0.x. The state 
transition
+     *             checking in {@link org.apache.catalina.util.LifecycleBase}
+     *             makes it impossible to use this state. The intended 
behaviour
+     *             can be obtained by setting the state to
+     *             {@link LifecycleState#FAILED} in
+     *             <code>LifecycleBase.startInternal()</code>
+     */
+    @Deprecated
     MUST_STOP(true, null),
+    /**
+     * @deprecated Unused. Will be removed in Tomcat 9.0.x. The state 
transition
+     *             checking in {@link org.apache.catalina.util.LifecycleBase}
+     *             makes it impossible to use this state. The intended 
behaviour
+     *             can be obtained by implementing {@link Lifecycle.SingleUse}.
+     */
+    @Deprecated
     MUST_DESTROY(false, null);
 
     private final boolean available;

Modified: tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java?rev=1725599&r1=1725598&r2=1725599&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java Tue Jan 19 
19:34:04 2016
@@ -124,17 +124,14 @@ public abstract class LifecycleBase impl
     @Override
     public final synchronized void start() throws LifecycleException {
 
-        if (LifecycleState.STARTING_PREP.equals(state) ||
-                LifecycleState.STARTING.equals(state) ||
+        if (LifecycleState.STARTING_PREP.equals(state) || 
LifecycleState.STARTING.equals(state) ||
                 LifecycleState.STARTED.equals(state)) {
 
             if (log.isDebugEnabled()) {
                 Exception e = new LifecycleException();
-                log.debug(sm.getString("lifecycleBase.alreadyStarted",
-                        toString()), e);
+                log.debug(sm.getString("lifecycleBase.alreadyStarted", 
toString()), e);
             } else if (log.isInfoEnabled()) {
-                log.info(sm.getString("lifecycleBase.alreadyStarted",
-                        toString()));
+                log.info(sm.getString("lifecycleBase.alreadyStarted", 
toString()));
             }
 
             return;
@@ -142,7 +139,7 @@ public abstract class LifecycleBase impl
 
         if (state.equals(LifecycleState.NEW)) {
             init();
-        } else if (state.equals(LifecycleState.FAILED)){
+        } else if (state.equals(LifecycleState.FAILED)) {
             stop();
         } else if (!state.equals(LifecycleState.INITIALIZED) &&
                 !state.equals(LifecycleState.STOPPED)) {
@@ -156,22 +153,21 @@ public abstract class LifecycleBase impl
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             setStateInternal(LifecycleState.FAILED, null, false);
-            throw new LifecycleException(
-                    sm.getString("lifecycleBase.startFail",toString()), t);
-        }
-
-        if (state.equals(LifecycleState.FAILED) ||
-                state.equals(LifecycleState.MUST_STOP)) {
-            stop();
-        } else {
-            // Shouldn't be necessary but acts as a check that sub-classes are
-            // doing what they are supposed to.
-            if (!state.equals(LifecycleState.STARTING)) {
-                invalidTransition(Lifecycle.AFTER_START_EVENT);
+            throw new 
LifecycleException(sm.getString("lifecycleBase.startFail", toString()), t);
+        } finally {
+            if (state.equals(LifecycleState.FAILED)) {
+                stop();
+                return;
             }
+        }
 
-            setStateInternal(LifecycleState.STARTED, null, false);
+        // Shouldn't be necessary but acts as a check that sub-classes are
+        // doing what they are supposed to.
+        if (!state.equals(LifecycleState.STARTING)) {
+            invalidTransition(Lifecycle.AFTER_START_EVENT);
         }
+
+        setStateInternal(LifecycleState.STARTED, null, false);
     }
 
 
@@ -197,17 +193,14 @@ public abstract class LifecycleBase impl
     @Override
     public final synchronized void stop() throws LifecycleException {
 
-        if (LifecycleState.STOPPING_PREP.equals(state) ||
-                LifecycleState.STOPPING.equals(state) ||
+        if (LifecycleState.STOPPING_PREP.equals(state) || 
LifecycleState.STOPPING.equals(state) ||
                 LifecycleState.STOPPED.equals(state)) {
 
             if (log.isDebugEnabled()) {
                 Exception e = new LifecycleException();
-                log.debug(sm.getString("lifecycleBase.alreadyStopped",
-                        toString()), e);
+                log.debug(sm.getString("lifecycleBase.alreadyStopped", 
toString()), e);
             } else if (log.isInfoEnabled()) {
-                log.info(sm.getString("lifecycleBase.alreadyStopped",
-                        toString()));
+                log.info(sm.getString("lifecycleBase.alreadyStopped", 
toString()));
             }
 
             return;
@@ -218,9 +211,7 @@ public abstract class LifecycleBase impl
             return;
         }
 
-        if (!state.equals(LifecycleState.STARTED) &&
-                !state.equals(LifecycleState.FAILED) &&
-                !state.equals(LifecycleState.MUST_STOP)) {
+        if (!state.equals(LifecycleState.STARTED) && 
!state.equals(LifecycleState.FAILED)) {
             invalidTransition(Lifecycle.BEFORE_STOP_EVENT);
         }
 
@@ -238,24 +229,23 @@ public abstract class LifecycleBase impl
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             setStateInternal(LifecycleState.FAILED, null, false);
-            throw new LifecycleException(
-                    sm.getString("lifecycleBase.stopFail",toString()), t);
-        }
-
-        if (state.equals(LifecycleState.MUST_DESTROY)) {
-            // Complete stop process first
-            setStateInternal(LifecycleState.STOPPED, null, false);
-
-            destroy();
-        } else if (!state.equals(LifecycleState.FAILED)){
-            // Shouldn't be necessary but acts as a check that sub-classes are
-            // doing what they are supposed to.
-            if (!state.equals(LifecycleState.STOPPING)) {
-                invalidTransition(Lifecycle.AFTER_STOP_EVENT);
+            throw new 
LifecycleException(sm.getString("lifecycleBase.stopFail",toString()), t);
+        } finally {
+            if (this instanceof Lifecycle.SingleUse) {
+                // Complete stop process first
+                setStateInternal(LifecycleState.STOPPED, null, false);
+                destroy();
+                return;
             }
+        }
 
-            setStateInternal(LifecycleState.STOPPED, null, false);
+        // Shouldn't be necessary but acts as a check that sub-classes are
+        // doing what they are supposed to.
+        if (!state.equals(LifecycleState.STOPPING) && 
!state.equals(LifecycleState.FAILED)) {
+            invalidTransition(Lifecycle.AFTER_STOP_EVENT);
         }
+
+        setStateInternal(LifecycleState.STOPPED, null, false);
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to