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 05debfd8c58f208dc7bb33b3b6db5083018fbc37
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jan 20 17:33:53 2021 +0000

    Switch to the thread-safe method of serviced application tracking
    
    Second 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.
---
 .../apache/catalina/ha/deploy/FarmWarDeployer.java | 31 ++++++++++----
 .../catalina/manager/HTMLManagerServlet.java       |  7 ++--
 .../apache/catalina/manager/ManagerServlet.java    | 48 ++++++++++++++--------
 3 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java 
b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
index 940f581..09f075b 100644
--- a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
+++ b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
@@ -228,8 +228,7 @@ public class FarmWarDeployer extends ClusterListener
                     File deployable = new File(getDeployDirFile(), name);
                     try {
                         String contextName = fmsg.getContextName();
-                        if (!isServiced(contextName)) {
-                            addServiced(contextName);
+                        if (tryAddServiced(contextName)) {
                             try {
                                 remove(contextName);
                                 if (!factory.getFile().renameTo(deployable)) {
@@ -262,8 +261,7 @@ public class FarmWarDeployer extends ClusterListener
                     if (log.isDebugEnabled())
                         log.debug(sm.getString("farmWarDeployer.msgRxUndeploy",
                                 contextName));
-                    if (!isServiced(contextName)) {
-                        addServiced(contextName);
+                    if (tryAddServiced(contextName)) {
                         try {
                             remove(contextName);
                         } finally {
@@ -420,8 +418,7 @@ public class FarmWarDeployer extends ClusterListener
         // remove locally
         if (undeploy) {
             try {
-                if (!isServiced(contextName)) {
-                    addServiced(contextName);
+                if (tryAddServiced(contextName)) {
                     try {
                         remove(contextName);
                     } finally {
@@ -458,8 +455,7 @@ public class FarmWarDeployer extends ClusterListener
                 log.info(sm.getString("farmWarDeployer.modInstall",
                         cn.getName(), deployWar.getAbsolutePath()));
             // install local
-            if (!isServiced(cn.getName())) {
-                addServiced(cn.getName());
+            if (tryAddServiced(cn.getName())) {
                 try {
                     copy(newWar, deployWar);
                     check(cn.getName());
@@ -594,7 +590,9 @@ public class FarmWarDeployer extends ClusterListener
      * @param name The context name
      * @return <code>true</code> if the context is being serviced
      * @throws Exception Error invoking the deployer
+     * @deprecated Unused. Will be removed in Tomcat 10.1.x onwards.
      */
+    @Deprecated
     protected boolean isServiced(String name) throws Exception {
         String[] params = { name };
         String[] signature = { "java.lang.String" };
@@ -607,7 +605,10 @@ public class FarmWarDeployer extends ClusterListener
      * Mark a context as being services.
      * @param name The context name
      * @throws Exception Error invoking the deployer
+     * @deprecated Unused. Will be removed in Tomcat 10.1.x onwards.
+     *             Use {@link #tryAddServiced}
      */
+    @Deprecated
     protected void addServiced(String name) throws Exception {
         String[] params = { name };
         String[] signature = { "java.lang.String" };
@@ -615,6 +616,20 @@ public class FarmWarDeployer extends ClusterListener
     }
 
     /**
+     * Attempt to mark a context as being serviced
+     * @param name The context name
+     * @return {@code true} if the application was marked as being serviced and
+     *         {@code false} if the application was already marked as being 
serviced
+     * @throws Exception Error invoking the deployer
+     */
+    protected boolean tryAddServiced(String name) throws Exception {
+        String[] params = { name };
+        String[] signature = { "java.lang.String" };
+        Boolean result = (Boolean) mBeanServer.invoke(oname, "tryAddServiced", 
params, signature);
+        return result.booleanValue();
+    }
+
+    /**
      * Mark a context as no longer being serviced.
      * @param name The context name
      * @throws Exception Error invoking the deployer
diff --git a/java/org/apache/catalina/manager/HTMLManagerServlet.java 
b/java/org/apache/catalina/manager/HTMLManagerServlet.java
index 15dae0b..b0aea34 100644
--- a/java/org/apache/catalina/manager/HTMLManagerServlet.java
+++ b/java/org/apache/catalina/manager/HTMLManagerServlet.java
@@ -284,10 +284,7 @@ public final class HTMLManagerServlet extends 
ManagerServlet {
                     break;
                 }
 
-                if (isServiced(name)) {
-                    message = smClient.getString("managerServlet.inService", 
name);
-                } else {
-                    addServiced(name);
+                if (tryAddServiced(name)) {
                     try {
                         warPart.write(file.getAbsolutePath());
                         // Perform new deployment
@@ -295,6 +292,8 @@ public final class HTMLManagerServlet extends 
ManagerServlet {
                     } finally {
                         removeServiced(name);
                     }
+                } else {
+                    message = smClient.getString("managerServlet.inService", 
name);
                 }
                 break;
             }
diff --git a/java/org/apache/catalina/manager/ManagerServlet.java 
b/java/org/apache/catalina/manager/ManagerServlet.java
index 6b742fa..ca028b1 100644
--- a/java/org/apache/catalina/manager/ManagerServlet.java
+++ b/java/org/apache/catalina/manager/ManagerServlet.java
@@ -813,10 +813,7 @@ public class ManagerServlet extends HttpServlet implements 
ContainerServlet {
         }
 
         try {
-            if (isServiced(name)) {
-                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
-            } else {
-                addServiced(name);
+            if (tryAddServiced(name)) {
                 try {
                     if (config != null) {
                         if (!configBase.mkdirs() && !configBase.isDirectory()) 
{
@@ -853,6 +850,8 @@ public class ManagerServlet extends HttpServlet implements 
ContainerServlet {
                 } finally {
                     removeServiced(name);
                 }
+            } else {
+                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
             }
         } catch (Exception e) {
             log(sm.getString("managerServlet.error.deploy", displayPath), e);
@@ -895,10 +894,7 @@ public class ManagerServlet extends HttpServlet implements 
ContainerServlet {
 
         // Copy WAR to appBase
         try {
-            if (isServiced(name)) {
-                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
-            } else {
-                addServiced(name);
+            if (tryAddServiced(name)) {
                 try {
                     if (!deployedWar.delete()) {
                         
writer.println(smClient.getString("managerServlet.deleteFail",
@@ -911,6 +907,8 @@ public class ManagerServlet extends HttpServlet implements 
ContainerServlet {
                 } finally {
                     removeServiced(name);
                 }
+            } else {
+                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
             }
         } catch (Exception e) {
             log(sm.getString("managerServlet.error.deploy", displayPath), e);
@@ -988,10 +986,7 @@ public class ManagerServlet extends HttpServlet implements 
ContainerServlet {
         }
 
         try {
-            if (isServiced(name)) {
-                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
-            } else {
-                addServiced(name);
+            if (tryAddServiced(name)) {
                 try {
                     if (config != null) {
                         if (!configBase.mkdirs() && !configBase.isDirectory()) 
{
@@ -1026,6 +1021,8 @@ public class ManagerServlet extends HttpServlet 
implements ContainerServlet {
                 } finally {
                     removeServiced(name);
                 }
+            } else {
+                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
             }
             writeDeployResult(writer, smClient, name, displayPath);
         } catch (Throwable t) {
@@ -1520,10 +1517,7 @@ public class ManagerServlet extends HttpServlet 
implements ContainerServlet {
                 return;
             }
 
-            if (isServiced(name)) {
-                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
-            } else {
-                addServiced(name);
+            if (tryAddServiced(name)) {
                 try {
                     // Try to stop the context first to be nicer
                     context.stop();
@@ -1552,6 +1546,8 @@ public class ManagerServlet extends HttpServlet 
implements ContainerServlet {
                 } finally {
                     removeServiced(name);
                 }
+            } else {
+                writer.println(smClient.getString("managerServlet.inService", 
displayPath));
             }
             writer.println(smClient.getString("managerServlet.undeployed",
                     displayPath));
@@ -1605,7 +1601,9 @@ public class ManagerServlet extends HttpServlet 
implements ContainerServlet {
      * @param name The webapp name
      * @return <code>true</code> if a webapp with that name is being serviced
      * @throws Exception Propagate JMX invocation error
+     * @deprecated Unused. Will be removed in Tomcat 10.1.x onwards.
      */
+    @Deprecated
     protected boolean isServiced(String name)
         throws Exception {
         String[] params = { name };
@@ -1621,7 +1619,10 @@ public class ManagerServlet extends HttpServlet 
implements ContainerServlet {
      *
      * @param name The webapp name
      * @throws Exception Propagate JMX invocation error
+     * @deprecated Unused. Will be removed in Tomcat 10.1.x onwards.
+     *             Use {@link #tryAddServiced}
      */
+    @Deprecated
     protected void addServiced(String name)
         throws Exception {
         String[] params = { name };
@@ -1631,6 +1632,21 @@ public class ManagerServlet extends HttpServlet 
implements ContainerServlet {
 
 
     /**
+     * Attempt to mark a context as being serviced
+     * @param name The context name
+     * @return {@code true} if the application was marked as being serviced and
+     *         {@code false} if the application was already marked as being 
serviced
+     * @throws Exception Error invoking the deployer
+     */
+    protected boolean tryAddServiced(String name) throws Exception {
+        String[] params = { name };
+        String[] signature = { "java.lang.String" };
+        Boolean result = (Boolean) mBeanServer.invoke(oname, "tryAddServiced", 
params, signature);
+        return result.booleanValue();
+    }
+
+
+    /**
      * Invoke the removeServiced method on the deployer.
      *
      * @param name The webapp name


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

Reply via email to