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 802588a672037138cd65c1c4fc3cc4f74598b3a0 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 e318c23..b6ea0d3 100644 --- a/java/org/apache/catalina/mbeans/LocalStrings.properties +++ b/java/org/apache/catalina/mbeans/LocalStrings.properties @@ -21,4 +21,6 @@ jmxRemoteLifecycleListener.invalidRmiBindAddress=Invalid RMI bind address [{0}] jmxRemoteLifecycleListener.invalidURL=The JMX Service URL requested for the [{0}] server, [{1}], was invalid jmxRemoteLifecycleListener.start=The JMX Remote Listener has configured the registry on port [{0}] and the server on port [{1}] for the [{2}] server +mBeanFactory.contextCreate.addServicedFail=Unable to create context [{0}] as another component is currently servicing a context with that name +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. diff --git a/java/org/apache/catalina/mbeans/MBeanFactory.java b/java/org/apache/catalina/mbeans/MBeanFactory.java index 70fee81..1826eba 100644 --- a/java/org/apache/catalina/mbeans/MBeanFactory.java +++ b/java/org/apache/catalina/mbeans/MBeanFactory.java @@ -469,22 +469,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("Deployer not found for "+pname.getKeyProperty("host")); Service service = getService(pname); @@ -781,15 +787,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("Deployer not found for "+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