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

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

commit 391255fa448e2003fdbfac98d5581f95490307ae
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jan 20 17:32:28 2021 +0000

    Refactor tracking of serviced applications to use a concurrent Set
    
    First in a series of patches aimed at allowing parallel requests to the
    Manager application to deploy different applications in parallel rather
    than using a sync block to deploy them serially.
    Using a List was problematic as it allowed duplicates. This has been
    addressed by switching to a Set.
    Synchronized blocks have been replaced by using a concurrent Set.
    A new method (tryAddServiced) has been added to the process of
    checking if an app is being serviced, and registering it as such if
    not, so that this can be performed atomically.
    serviced has been retained in case it is used by custom sub-classes.
---
 java/org/apache/catalina/startup/HostConfig.java   | 58 +++++++++++++++++++---
 .../apache/catalina/startup/mbeans-descriptors.xml | 11 +++-
 2 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/catalina/startup/HostConfig.java 
b/java/org/apache/catalina/startup/HostConfig.java
index 89d002a..3ffc360 100644
--- a/java/org/apache/catalina/startup/HostConfig.java
+++ b/java/org/apache/catalina/startup/HostConfig.java
@@ -31,6 +31,7 @@ import java.security.PermissionCollection;
 import java.security.Policy;
 import java.security.cert.Certificate;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -147,11 +148,20 @@ public class HostConfig implements LifecycleListener {
     /**
      * List of applications which are being serviced, and shouldn't be
      * deployed/undeployed/redeployed at the moment.
+     * @deprecated Unused. Will be removed in Tomcat 10.1.x onwards. Replaced
+     *             by the private <code>servicedSet</code> field.
      */
+    @Deprecated
     protected final ArrayList<String> serviced = new ArrayList<>();
 
 
     /**
+     * Set of applications which are being serviced, and shouldn't be
+     * deployed/undeployed/redeployed at the moment.
+     */
+    private Set<String> servicedSet = Collections.newSetFromMap(new 
ConcurrentHashMap<String,Boolean>());
+
+    /**
      * The <code>Digester</code> instance used to parse context descriptors.
      */
     protected Digester digester = createDigester(contextClass);
@@ -314,21 +324,52 @@ public class HostConfig implements LifecycleListener {
 
 
     /**
-     * Add a serviced application to the list.
+     * Add a serviced application to the list and indicates if the application
+     * was already present in the list.
+     *
+     * @param name the context name
+     *
+     * @return {@code true} if the application was not already in the list
+     */
+    public boolean tryAddServiced(String name) {
+        if (servicedSet.add(name)) {
+            synchronized (this) {
+                serviced.add(name);
+            }
+            return true;
+        }
+        return false;
+    }
+
+
+    /**
+     * Add a serviced application to the list if it is not already present. If
+     * the application is already in the list of serviced applications this
+     * method is a NO-OP.
+     *
      * @param name the context name
+     *
+     * @deprecated Unused. This method will be removed in Tomcat 10.1.x 
onwards.
+     *             Use {@link #tryAddServiced} instead.
      */
-    public synchronized void addServiced(String name) {
-        serviced.add(name);
+    @Deprecated
+    public void addServiced(String name) {
+        servicedSet.add(name);
+        synchronized (this) {
+            serviced.add(name);
+        }
     }
 
 
     /**
      * Is application serviced ?
+     *
      * @param name the context name
+     *
      * @return state of the application
      */
-    public synchronized boolean isServiced(String name) {
-        return serviced.contains(name);
+    public boolean isServiced(String name) {
+        return servicedSet.contains(name);
     }
 
 
@@ -336,8 +377,11 @@ public class HostConfig implements LifecycleListener {
      * Removed a serviced application from the list.
      * @param name the context name
      */
-    public synchronized void removeServiced(String name) {
-        serviced.remove(name);
+    public void removeServiced(String name) {
+        servicedSet.remove(name);
+        synchronized (this) {
+            serviced.remove(name);
+        }
     }
 
 
diff --git a/java/org/apache/catalina/startup/mbeans-descriptors.xml 
b/java/org/apache/catalina/startup/mbeans-descriptors.xml
index 303d628..c66647a 100644
--- a/java/org/apache/catalina/startup/mbeans-descriptors.xml
+++ b/java/org/apache/catalina/startup/mbeans-descriptors.xml
@@ -90,8 +90,17 @@
                is="true"
                type="boolean"/>
 
+    <operation name="tryAddServiced"
+               description="Add a web application to the serviced list to show 
it is being serviced by another component returning true if the application was 
added and false if the application was already being serviced"
+               impact="ACTION"
+               returnType="boolean">
+      <parameter name="name"
+                 description="Application name"
+                 type="java.lang.String"/>
+    </operation>
+
     <operation name="addServiced"
-               description="Add a web application to the serviced list to show 
it gets serviced by another component"
+               description="DEPRECATED: Add a web application to the serviced 
list to show it is being serviced by another component"
                impact="ACTION"
                returnType="void">
       <parameter name="name"


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

Reply via email to