You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/02/05 11:42:13 UTC
[tomcat] 02/08: Switch to the thread-safe method of serviced
application tracking
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 dcfa8ca4678080a472b698073f25441ad61b0ec8
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 fd74bd2..1e21d20 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 14fb4bf..1ff15fa 100644
--- a/java/org/apache/catalina/manager/HTMLManagerServlet.java
+++ b/java/org/apache/catalina/manager/HTMLManagerServlet.java
@@ -279,10 +279,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
@@ -290,6 +287,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 d5b3723..f157da7 100644
--- a/java/org/apache/catalina/manager/ManagerServlet.java
+++ b/java/org/apache/catalina/manager/ManagerServlet.java
@@ -792,10 +792,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 {
// Upload WAR
uploadWar(writer, request, uploadedWar, smClient);
@@ -821,6 +818,8 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet {
} finally {
removeServiced(name);
}
+ } else {
+ writer.println(smClient.getString("managerServlet.inService", displayPath));
}
} catch (Exception e) {
log("managerServlet.check[" + displayPath + "]", e);
@@ -863,10 +862,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",
@@ -879,6 +875,8 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet {
} finally {
removeServiced(name);
}
+ } else {
+ writer.println(smClient.getString("managerServlet.inService", displayPath));
}
} catch (Exception e) {
log("managerServlet.check[" + displayPath + "]", e);
@@ -956,10 +954,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()) {
@@ -994,6 +989,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) {
@@ -1489,10 +1486,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();
@@ -1521,6 +1515,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));
@@ -1574,7 +1570,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 };
@@ -1590,7 +1588,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 };
@@ -1600,6 +1601,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org