You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/09/26 21:43:43 UTC

[tomcat] branch 8.5.x updated (8c2f067 -> 2a26382)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 8c2f067  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63766
     new d817d1e  Align with 9.0.x. Spacing, Javadoc
     new 2a26382  Add throwOnFailure to LifecycleBase.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/catalina/util/LifecycleBase.java | 102 ++++++++++++++++-------
 1 file changed, 73 insertions(+), 29 deletions(-)


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


[tomcat] 02/02: Add throwOnFailure to LifecycleBase.

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 2a263824b95000e331ddc1cdf2694b472dddfc87
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Oct 7 08:54:34 2016 +0000

    Add throwOnFailure to LifecycleBase.
    
    Defaults to no change to current behaviour.
---
 java/org/apache/catalina/util/LifecycleBase.java | 64 ++++++++++++++++++------
 1 file changed, 50 insertions(+), 14 deletions(-)

diff --git a/java/org/apache/catalina/util/LifecycleBase.java b/java/org/apache/catalina/util/LifecycleBase.java
index 88e18dd..8ea4d65 100644
--- a/java/org/apache/catalina/util/LifecycleBase.java
+++ b/java/org/apache/catalina/util/LifecycleBase.java
@@ -53,6 +53,37 @@ public abstract class LifecycleBase implements Lifecycle {
     private volatile LifecycleState state = LifecycleState.NEW;
 
 
+    private boolean throwOnFailure = true;
+
+
+    /**
+     * Will a {@link LifecycleException} thrown by a sub-class during
+     * {@link #initInternal()}, {@link #startInternal()},
+     * {@link #stopInternal()} or {@link #destroyInternal()} be re-thrown for
+     * the caller to handle or will it be logged instead?
+     *
+     * @return {@code true} if the exception will be re-thrown, otherwise
+     *         {@code false}
+     */
+    public boolean getThrowOnFailure() {
+        return throwOnFailure;
+    }
+
+
+    /**
+     * Configure if a {@link LifecycleException} thrown by a sub-class during
+     * {@link #initInternal()}, {@link #startInternal()},
+     * {@link #stopInternal()} or {@link #destroyInternal()} will be re-thrown
+     * for the caller to handle or if it will be logged instead.
+     *
+     * @param throwOnFailure {@code true} if the exception should be re-thrown,
+     *                       otherwise {@code false}
+     */
+    public void setThrowOnFailure(boolean throwOnFailure) {
+        this.throwOnFailure = throwOnFailure;
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -105,10 +136,7 @@ public abstract class LifecycleBase implements Lifecycle {
             initInternal();
             setStateInternal(LifecycleState.INITIALIZED, null, false);
         } catch (Throwable t) {
-            ExceptionUtils.handleThrowable(t);
-            setStateInternal(LifecycleState.FAILED, null, false);
-            throw new LifecycleException(
-                    sm.getString("lifecycleBase.initFail",toString()), t);
+            handleSubClassException(t, "lifecycleBase.initFail", toString());
         }
     }
 
@@ -167,9 +195,7 @@ public abstract class LifecycleBase implements Lifecycle {
         } catch (Throwable t) {
             // This is an 'uncontrolled' failure so put the component into the
             // FAILED state and throw an exception.
-            ExceptionUtils.handleThrowable(t);
-            setStateInternal(LifecycleState.FAILED, null, false);
-            throw new LifecycleException(sm.getString("lifecycleBase.startFail", toString()), t);
+            handleSubClassException(t, "lifecycleBase.startFail", toString());
         }
     }
 
@@ -238,9 +264,7 @@ public abstract class LifecycleBase implements Lifecycle {
 
             setStateInternal(LifecycleState.STOPPED, null, false);
         } catch (Throwable t) {
-            ExceptionUtils.handleThrowable(t);
-            setStateInternal(LifecycleState.FAILED, null, false);
-            throw new LifecycleException(sm.getString("lifecycleBase.stopFail",toString()), t);
+            handleSubClassException(t, "lifecycleBase.stopFail", toString());
         } finally {
             if (this instanceof Lifecycle.SingleUse) {
                 // Complete stop process first
@@ -297,10 +321,7 @@ public abstract class LifecycleBase implements Lifecycle {
             destroyInternal();
             setStateInternal(LifecycleState.DESTROYED, null, false);
         } catch (Throwable t) {
-            ExceptionUtils.handleThrowable(t);
-            setStateInternal(LifecycleState.FAILED, null, false);
-            throw new LifecycleException(
-                    sm.getString("lifecycleBase.destroyFail",toString()), t);
+            handleSubClassException(t, "lifecycleBase.destroyFail", toString());
         }
     }
 
@@ -408,4 +429,19 @@ public abstract class LifecycleBase implements Lifecycle {
         String msg = sm.getString("lifecycleBase.invalidTransition", type, toString(), state);
         throw new LifecycleException(msg);
     }
+
+
+    private void handleSubClassException(Throwable t, String key, Object... args) throws LifecycleException {
+        ExceptionUtils.handleThrowable(t);
+        setStateInternal(LifecycleState.FAILED, null, false);
+        String msg = sm.getString(key, args);
+        if (getThrowOnFailure()) {
+            if (!(t instanceof LifecycleException)) {
+                t = new LifecycleException(msg, t);
+            }
+            throw (LifecycleException) t;
+        } else {
+            log.error(msg, t);
+        }
+    }
 }


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


[tomcat] 01/02: Align with 9.0.x. Spacing, Javadoc

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit d817d1e72afc4a90e916dbf7ffd58a736077a653
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Sep 26 22:31:49 2019 +0100

    Align with 9.0.x. Spacing, Javadoc
---
 java/org/apache/catalina/util/LifecycleBase.java | 38 ++++++++++++++----------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/catalina/util/LifecycleBase.java b/java/org/apache/catalina/util/LifecycleBase.java
index 6ccbdb4..88e18dd 100644
--- a/java/org/apache/catalina/util/LifecycleBase.java
+++ b/java/org/apache/catalina/util/LifecycleBase.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.catalina.util;
 
 import java.util.List;
@@ -30,7 +29,6 @@ import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.res.StringManager;
 
-
 /**
  * Base implementation of the {@link Lifecycle} interface that implements the
  * state transition rules for {@link Lifecycle#start()} and
@@ -115,8 +113,15 @@ public abstract class LifecycleBase implements Lifecycle {
     }
 
 
+    /**
+     * Sub-classes implement this method to perform any instance initialisation
+     * required.
+     *
+     * @throws LifecycleException If the initialisation fails
+     */
     protected abstract void initInternal() throws LifecycleException;
 
+
     /**
      * {@inheritDoc}
      */
@@ -268,9 +273,7 @@ public abstract class LifecycleBase implements Lifecycle {
             }
         }
 
-        if (LifecycleState.DESTROYING.equals(state) ||
-                LifecycleState.DESTROYED.equals(state)) {
-
+        if (LifecycleState.DESTROYING.equals(state) || LifecycleState.DESTROYED.equals(state)) {
             if (log.isDebugEnabled()) {
                 Exception e = new LifecycleException();
                 log.debug(sm.getString("lifecycleBase.alreadyDestroyed", toString()), e);
@@ -284,10 +287,8 @@ public abstract class LifecycleBase implements Lifecycle {
             return;
         }
 
-        if (!state.equals(LifecycleState.STOPPED) &&
-                !state.equals(LifecycleState.FAILED) &&
-                !state.equals(LifecycleState.NEW) &&
-                !state.equals(LifecycleState.INITIALIZED)) {
+        if (!state.equals(LifecycleState.STOPPED) && !state.equals(LifecycleState.FAILED) &&
+                !state.equals(LifecycleState.NEW) && !state.equals(LifecycleState.INITIALIZED)) {
             invalidTransition(Lifecycle.BEFORE_DESTROY_EVENT);
         }
 
@@ -304,8 +305,15 @@ public abstract class LifecycleBase implements Lifecycle {
     }
 
 
+    /**
+     * Sub-classes implement this method to perform any instance destruction
+     * required.
+     *
+     * @throws LifecycleException If the destruction fails
+     */
     protected abstract void destroyInternal() throws LifecycleException;
 
+
     /**
      * {@inheritDoc}
      */
@@ -333,8 +341,7 @@ public abstract class LifecycleBase implements Lifecycle {
      * @param state The new state for this component
      * @throws LifecycleException when attempting to set an invalid state
      */
-    protected synchronized void setState(LifecycleState state)
-            throws LifecycleException {
+    protected synchronized void setState(LifecycleState state) throws LifecycleException {
         setStateInternal(state, null, true);
     }
 
@@ -354,8 +361,9 @@ public abstract class LifecycleBase implements Lifecycle {
         setStateInternal(state, data, true);
     }
 
-    private synchronized void setStateInternal(LifecycleState state,
-            Object data, boolean check) throws LifecycleException {
+
+    private synchronized void setStateInternal(LifecycleState state, Object data, boolean check)
+            throws LifecycleException {
 
         if (log.isDebugEnabled()) {
             log.debug(sm.getString("lifecycleBase.setState", this, state));
@@ -395,9 +403,9 @@ public abstract class LifecycleBase implements Lifecycle {
         }
     }
 
+
     private void invalidTransition(String type) throws LifecycleException {
-        String msg = sm.getString("lifecycleBase.invalidTransition", type,
-                toString(), state);
+        String msg = sm.getString("lifecycleBase.invalidTransition", type, toString(), state);
         throw new LifecycleException(msg);
     }
 }


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