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:44:25 UTC

[tomcat] branch 7.0.x updated (5c32af4 -> d0685f9)

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

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


    from 5c32af4  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63766
     new 06e83a4  Fix Javadoc warnings
     new 2767d56  Align with 8.5.x (and fix Javadoc warnings)
     new 247c8c3  Back-port refactoring to remove use of LifecycleSupport
     new d0685f9  Add throwOnFailure to LifecycleBase.

The 4 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/Lifecycle.java            |  17 ++-
 java/org/apache/catalina/Valve.java                |   3 +-
 java/org/apache/catalina/util/LifecycleBase.java   | 133 ++++++++++++++-------
 .../org/apache/catalina/util/LifecycleSupport.java |   3 +
 4 files changed, 109 insertions(+), 47 deletions(-)


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


[tomcat] 01/04: Fix Javadoc warnings

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

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

commit 06e83a498c213c36323c17d3c0c93d6a2cdfc0fd
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Sep 26 22:25:35 2019 +0100

    Fix Javadoc warnings
---
 java/org/apache/catalina/Valve.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/Valve.java b/java/org/apache/catalina/Valve.java
index 89a17a2..911ac74 100644
--- a/java/org/apache/catalina/Valve.java
+++ b/java/org/apache/catalina/Valve.java
@@ -44,7 +44,7 @@ public interface Valve {
     //-------------------------------------------------------------- Properties
 
     /**
-     * Return descriptive information about this Valve implementation.
+     * @return descriptive information about this Valve implementation.
      */
     public String getInfo();
 
@@ -130,6 +130,7 @@ public interface Valve {
      *
      * @param request The servlet request to be processed
      * @param response The servlet response to be created
+     * @param event The Comet event to be processed
      *
      * @exception IOException if an input/output error occurs, or is thrown
      *  by a subsequently invoked Valve, Filter, or Servlet


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


[tomcat] 02/04: Align with 8.5.x (and fix Javadoc warnings)

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

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

commit 2767d569970ce4b9b8eab52040451bc878285683
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Sep 26 22:25:50 2019 +0100

    Align with 8.5.x (and fix Javadoc warnings)
---
 java/org/apache/catalina/Lifecycle.java          | 17 ++++++---
 java/org/apache/catalina/util/LifecycleBase.java | 44 +++++++++++++++---------
 2 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/java/org/apache/catalina/Lifecycle.java b/java/org/apache/catalina/Lifecycle.java
index a2b7f99..3dfd7ea 100644
--- a/java/org/apache/catalina/Lifecycle.java
+++ b/java/org/apache/catalina/Lifecycle.java
@@ -53,7 +53,7 @@ package org.apache.catalina;
  * |                                 DESTROYED                     |
  * |                                                               |
  * |                            stop()                             |
- * ---»------------------------------»------------------------------
+ * ----»-----------------------------»------------------------------
  *
  * Any state can transition to FAILED.
  *
@@ -87,7 +87,7 @@ public interface Lifecycle {
 
 
     /**
-     * The LifecycleEvent type for the "component after init" event.
+     * The LifecycleEvent type for the "component before init" event.
      */
     public static final String BEFORE_INIT_EVENT = "before_init";
 
@@ -182,8 +182,11 @@ public interface Lifecycle {
 
 
     /**
-     * Get the life cycle listeners associated with this life cycle. If this
-     * component has no listeners registered, a zero-length array is returned.
+     * Get the life cycle listeners associated with this life cycle.
+     *
+     * @return An array containing the life cycle listeners associated with this
+     *         life cycle. If this component has no listeners registered, a
+     *         zero-length array is returned.
      */
     public LifecycleListener[] findLifecycleListeners();
 
@@ -296,7 +299,11 @@ public interface Lifecycle {
 
     /**
      * Obtain a textual representation of the current component state. Useful
-     * for JMX.
+     * for JMX. The format of this string may vary between point releases and
+     * should not be relied upon to determine component state. To determine
+     * component state, use {@link #getState()}.
+     *
+     * @return The name of the current component state.
      */
     public String getStateName();
 
diff --git a/java/org/apache/catalina/util/LifecycleBase.java b/java/org/apache/catalina/util/LifecycleBase.java
index faba205..c9739ca 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 org.apache.catalina.Lifecycle;
@@ -26,7 +25,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
@@ -110,8 +108,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}
      */
@@ -175,7 +180,7 @@ public abstract class LifecycleBase implements Lifecycle {
      * will be called on the failed component but the parent component will
      * continue to start normally.
      *
-     * @throws LifecycleException
+     * @throws LifecycleException Start error occurred
      */
     protected abstract void startInternal() throws LifecycleException;
 
@@ -246,7 +251,7 @@ public abstract class LifecycleBase implements Lifecycle {
      * {@link LifecycleState#STOPPING} during the execution of this method.
      * Changing state will trigger the {@link Lifecycle#STOP_EVENT} event.
      *
-     * @throws LifecycleException
+     * @throws LifecycleException Stop error occurred
      */
     protected abstract void stopInternal() throws LifecycleException;
 
@@ -263,9 +268,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);
@@ -279,10 +282,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);
         }
 
@@ -299,8 +300,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}
      */
@@ -326,9 +334,9 @@ public abstract class LifecycleBase implements Lifecycle {
      * transition is valid for a sub-class.
      *
      * @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);
     }
 
@@ -341,14 +349,16 @@ public abstract class LifecycleBase implements Lifecycle {
      *
      * @param state The new state for this component
      * @param data  The data to pass to the associated {@link Lifecycle} event
+     * @throws LifecycleException when attempting to set an invalid state
      */
     protected synchronized void setState(LifecycleState state, Object data)
             throws LifecycleException {
         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));
@@ -388,9 +398,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


[tomcat] 03/04: Back-port refactoring to remove use of LifecycleSupport

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

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

commit 247c8c32c44f65ce7bf3035541eedb8ffc97d5d0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Sep 26 22:41:12 2019 +0100

    Back-port refactoring to remove use of LifecycleSupport
---
 java/org/apache/catalina/util/LifecycleBase.java   | 25 +++++++++++++---------
 .../org/apache/catalina/util/LifecycleSupport.java |  3 +++
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/catalina/util/LifecycleBase.java b/java/org/apache/catalina/util/LifecycleBase.java
index c9739ca..6195768 100644
--- a/java/org/apache/catalina/util/LifecycleBase.java
+++ b/java/org/apache/catalina/util/LifecycleBase.java
@@ -16,7 +16,11 @@
  */
 package org.apache.catalina.util;
 
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
 import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.LifecycleState;
@@ -32,17 +36,15 @@ import org.apache.tomcat.util.res.StringManager;
  */
 public abstract class LifecycleBase implements Lifecycle {
 
-    private static Log log = LogFactory.getLog(LifecycleBase.class);
+    private static final Log log = LogFactory.getLog(LifecycleBase.class);
 
-    private static StringManager sm =
-        StringManager.getManager("org.apache.catalina.util");
+    private static final StringManager sm = StringManager.getManager(LifecycleBase.class);
 
 
     /**
-     * Used to handle firing lifecycle events.
-     * TODO: Consider merging LifecycleSupport into this class.
+     * The list of registered LifecycleListeners for event notifications.
      */
-    private LifecycleSupport lifecycle = new LifecycleSupport(this);
+    private final List<LifecycleListener> lifecycleListeners = new CopyOnWriteArrayList<LifecycleListener>();
 
 
     /**
@@ -56,7 +58,7 @@ public abstract class LifecycleBase implements Lifecycle {
      */
     @Override
     public void addLifecycleListener(LifecycleListener listener) {
-        lifecycle.addLifecycleListener(listener);
+        lifecycleListeners.add(listener);
     }
 
 
@@ -65,7 +67,7 @@ public abstract class LifecycleBase implements Lifecycle {
      */
     @Override
     public LifecycleListener[] findLifecycleListeners() {
-        return lifecycle.findLifecycleListeners();
+        return lifecycleListeners.toArray(new LifecycleListener[0]);
     }
 
 
@@ -74,7 +76,7 @@ public abstract class LifecycleBase implements Lifecycle {
      */
     @Override
     public void removeLifecycleListener(LifecycleListener listener) {
-        lifecycle.removeLifecycleListener(listener);
+        lifecycleListeners.remove(listener);
     }
 
 
@@ -85,7 +87,10 @@ public abstract class LifecycleBase implements Lifecycle {
      * @param data  Data associated with event.
      */
     protected void fireLifecycleEvent(String type, Object data) {
-        lifecycle.fireLifecycleEvent(type, data);
+        LifecycleEvent event = new LifecycleEvent(this, type, data);
+        for (LifecycleListener listener : lifecycleListeners) {
+            listener.lifecycleEvent(event);
+        }
     }
 
 
diff --git a/java/org/apache/catalina/util/LifecycleSupport.java b/java/org/apache/catalina/util/LifecycleSupport.java
index 8dd7409..737c07e 100644
--- a/java/org/apache/catalina/util/LifecycleSupport.java
+++ b/java/org/apache/catalina/util/LifecycleSupport.java
@@ -29,7 +29,10 @@ import org.apache.catalina.LifecycleListener;
  * registered LifecycleListeners.
  *
  * @author Craig R. McClanahan
+ *
+ * @deprecated Unused. This class will be removed in Tomcat 8.5.x.
  */
+@Deprecated
 public final class LifecycleSupport {
 
 


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


[tomcat] 04/04: 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 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit d0685f927186da2e0be56c28371e5207ee09ed20
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 6195768..4b9bc2a 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