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 485a74b029520b18e3e5ccb8a64948a0ae61ecdb
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jan 20 19:35:10 2021 +0000

    Avoid servicing conflicts between MBeanFactory and other channels
    
    Third 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.
    Prior to this patch MBeanFactory did not check whether the app to be
    deployed was already listed as being serviced. This is now checked
    (using the new thread safe tryAddServiced) before trying to add or
    remove an app via MBeanFactory
---
 .../apache/catalina/mbeans/LocalStrings.properties |  2 +
 java/org/apache/catalina/mbeans/MBeanFactory.java  | 61 +++++++++++++---------
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/java/org/apache/catalina/mbeans/LocalStrings.properties 
b/java/org/apache/catalina/mbeans/LocalStrings.properties
index 7cc32e2..88ecbc6 100644
--- a/java/org/apache/catalina/mbeans/LocalStrings.properties
+++ b/java/org/apache/catalina/mbeans/LocalStrings.properties
@@ -38,7 +38,9 @@ mBean.nullName=Attribute name is null
 
 mBeanDumper.getAttributeError=Error getting attribute [{0}] for object name 
[{1}]
 
+mBeanFactory.contextCreate.addServicedFail=Unable to create context [{0}] as 
another component is currently servicing a context with that name
 mBeanFactory.contextDestroyError=Error during context [{0}] destroy
+mBeanFactory.contextRemove.addServicedFail=Unable to remove context [{0}] as 
another component is currently servicing that context
 mBeanFactory.managerContext=Manager components may only be added to Contexts.
 mBeanFactory.noDeployer=Deployer not found for host [{0}]
 mBeanFactory.noService=Service with the domain [{0}] was not found
diff --git a/java/org/apache/catalina/mbeans/MBeanFactory.java 
b/java/org/apache/catalina/mbeans/MBeanFactory.java
index 4f81571..f4d0bd0 100644
--- a/java/org/apache/catalina/mbeans/MBeanFactory.java
+++ b/java/org/apache/catalina/mbeans/MBeanFactory.java
@@ -446,22 +446,28 @@ public class MBeanFactory {
                                              pname.getKeyProperty("host"));
         if(mserver.isRegistered(deployer)) {
             String contextName = context.getName();
-            mserver.invoke(deployer, "addServiced",
-                           new Object [] {contextName},
-                           new String [] {"java.lang.String"});
-            String configPath = (String)mserver.getAttribute(deployer,
-                                                             "configBaseName");
-            String baseName = context.getBaseName();
-            File configFile = new File(new File(configPath), baseName+".xml");
-            if (configFile.isFile()) {
-                context.setConfigFile(configFile.toURI().toURL());
+            Boolean result = (Boolean) mserver.invoke(deployer, 
"tryAddServiced",
+                    new Object [] {contextName},
+                    new String [] {"java.lang.String"});
+            if (result.booleanValue()) {
+                try {
+                    String configPath = (String)mserver.getAttribute(deployer, 
"configBaseName");
+                    String baseName = context.getBaseName();
+                    File configFile = new File(new File(configPath), 
baseName+".xml");
+                    if (configFile.isFile()) {
+                        context.setConfigFile(configFile.toURI().toURL());
+                    }
+                    mserver.invoke(deployer, "manageApp",
+                            new Object[] {context},
+                            new String[] {"org.apache.catalina.Context"});
+                } finally {
+                    mserver.invoke(deployer, "removeServiced",
+                            new Object [] {contextName},
+                            new String [] {"java.lang.String"});
+                }
+            } else {
+                throw new 
IllegalStateException(sm.getString("mBeanFactory.contextRemove.addServicedFail",
 contextName));
             }
-            mserver.invoke(deployer, "manageApp",
-                           new Object[] {context},
-                           new String[] {"org.apache.catalina.Context"});
-            mserver.invoke(deployer, "removeServiced",
-                           new Object [] {contextName},
-                           new String [] {"java.lang.String"});
         } else {
             log.warn(sm.getString("mBeanFactory.noDeployer", 
pname.getKeyProperty("host")));
             Service service = getService(pname);
@@ -744,15 +750,22 @@ public class MBeanFactory {
                                              hostName);
         String pathStr = getPathStr(path);
         if(mserver.isRegistered(deployer)) {
-            mserver.invoke(deployer,"addServiced",
-                           new Object[]{pathStr},
-                           new String[] {"java.lang.String"});
-            mserver.invoke(deployer,"unmanageApp",
-                           new Object[] {pathStr},
-                           new String[] {"java.lang.String"});
-            mserver.invoke(deployer,"removeServiced",
-                           new Object[] {pathStr},
-                           new String[] {"java.lang.String"});
+            Boolean result = (Boolean) 
mserver.invoke(deployer,"tryAddServiced",
+                       new Object[]{pathStr},
+                       new String[] {"java.lang.String"});
+            if (result.booleanValue()) {
+                try {
+                    mserver.invoke(deployer,"unmanageApp",
+                            new Object[] {pathStr},
+                            new String[] {"java.lang.String"});
+                } finally {
+                    mserver.invoke(deployer,"removeServiced",
+                            new Object[] {pathStr},
+                            new String[] {"java.lang.String"});
+                }
+            } else {
+                throw new 
IllegalStateException(sm.getString("mBeanFactory.removeCreate.addServicedFail", 
pathStr));
+            }
         } else {
             log.warn(sm.getString("mBeanFactory.noDeployer", hostName));
             Host host = (Host) engine.findChild(hostName);


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

Reply via email to