This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch serviced in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 79e00bdcb5bbabc39d73730c7948a2cb7d358c4f Author: Mark Thomas <[email protected]> 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 b139f3d..0063c37 100644 --- a/java/org/apache/catalina/mbeans/LocalStrings.properties +++ b/java/org/apache/catalina/mbeans/LocalStrings.properties @@ -29,7 +29,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 2858615..ea963d1 100644 --- a/java/org/apache/catalina/mbeans/MBeanFactory.java +++ b/java/org/apache/catalina/mbeans/MBeanFactory.java @@ -414,22 +414,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); @@ -712,15 +718,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: [email protected] For additional commands, e-mail: [email protected]
