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 2019/09/27 16:35:17 UTC
[tomcat] 04/13: Align with 8.5.x. Mostly Javadoc and spacing. A
little code refactoring
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 9f5d7765491994753672eb0b33ba756e3053bbbd
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Sep 27 14:34:21 2019 +0100
Align with 8.5.x. Mostly Javadoc and spacing. A little code refactoring
---
java/org/apache/catalina/core/StandardHost.java | 190 +++++++++++-------------
1 file changed, 84 insertions(+), 106 deletions(-)
diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java
index a4e0dcd..99df7ad 100644
--- a/java/org/apache/catalina/core/StandardHost.java
+++ b/java/org/apache/catalina/core/StandardHost.java
@@ -16,8 +16,8 @@
*/
package org.apache.catalina.core;
-
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -25,10 +25,13 @@ import java.util.WeakHashMap;
import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;
+import javax.management.ObjectName;
+
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.Host;
+import org.apache.catalina.JmxEnabled;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleException;
@@ -37,10 +40,10 @@ import org.apache.catalina.Valve;
import org.apache.catalina.loader.WebappClassLoaderBase;
import org.apache.catalina.mbeans.MBeanUtils;
import org.apache.catalina.util.ContextName;
-import org.apache.catalina.valves.ValveBase;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
-
/**
* Standard implementation of the <b>Host</b> interface. Each
* child container must be a Context implementation to process the
@@ -51,8 +54,7 @@ import org.apache.tomcat.util.ExceptionUtils;
*/
public class StandardHost extends ContainerBase implements Host {
- private static final org.apache.juli.logging.Log log=
- org.apache.juli.logging.LogFactory.getLog( StandardHost.class );
+ private static final Log log = LogFactory.getLog(StandardHost.class);
// ----------------------------------------------------------- Constructors
@@ -160,23 +162,23 @@ public class StandardHost extends ContainerBase implements Host {
/**
* Should we create directories upon startup for appBase and xmlBase
*/
- private boolean createDirs = true;
+ private boolean createDirs = true;
- /**
- * Track the class loaders for the child web applications so memory leaks
- * can be detected.
- */
- private Map<ClassLoader, String> childClassLoaders =
- new WeakHashMap<ClassLoader, String>();
+ /**
+ * Track the class loaders for the child web applications so memory leaks
+ * can be detected.
+ */
+ private final Map<ClassLoader, String> childClassLoaders =
+ new WeakHashMap<ClassLoader, String>();
- /**
- * Any file or directory in {@link #appBase} that this pattern matches will
- * be ignored by the automatic deployment process (both
- * {@link #deployOnStartup} and {@link #autoDeploy}).
- */
- private Pattern deployIgnore = null;
+ /**
+ * Any file or directory in {@link #appBase} that this pattern matches will
+ * be ignored by the automatic deployment process (both
+ * {@link #deployOnStartup} and {@link #autoDeploy}).
+ */
+ private Pattern deployIgnore = null;
private boolean undeployOldVersions = false;
@@ -210,7 +212,7 @@ public class StandardHost extends ContainerBase implements Host {
*/
@Override
public String getAppBase() {
- return (this.appBase);
+ return this.appBase;
}
@@ -229,44 +231,31 @@ public class StandardHost extends ContainerBase implements Host {
String oldAppBase = this.appBase;
this.appBase = appBase;
support.firePropertyChange("appBase", oldAppBase, this.appBase);
-
}
/**
- * Return the XML root for this Host. This can be an absolute
- * pathname, a relative pathname, or a URL.
- * If null, defaults to
- * ${catalina.base}/conf/<engine name>/<host name> directory
+ * ({@inheritDoc}
*/
@Override
public String getXmlBase() {
-
- return (this.xmlBase);
-
+ return this.xmlBase;
}
/**
- * Set the Xml root for this Host. This can be an absolute
- * pathname, a relative pathname, or a URL.
- * If null, defaults to
- * ${catalina.base}/conf/<engine name>/<host name> directory
- *
- * @param xmlBase The new XML root
+ * ({@inheritDoc}
*/
@Override
public void setXmlBase(String xmlBase) {
-
String oldXmlBase = this.xmlBase;
this.xmlBase = xmlBase;
support.firePropertyChange("xmlBase", oldXmlBase, this.xmlBase);
-
}
/**
- * Returns true if the Host will attempt to create directories for appBase and xmlBase
+ * @return <code>true</code> if the Host will attempt to create directories for appBase and xmlBase
* unless they already exist.
*/
@Override
@@ -275,8 +264,8 @@ public class StandardHost extends ContainerBase implements Host {
}
/**
- * Set to true if the Host should attempt to create directories for xmlBase and appBase upon startup
- * @param createDirs
+ * Set to <code>true</code> if the Host should attempt to create directories for xmlBase and appBase upon startup
+ * @param createDirs the new flag value
*/
@Override
public void setCreateDirs(boolean createDirs) {
@@ -284,14 +273,12 @@ public class StandardHost extends ContainerBase implements Host {
}
/**
- * Return the value of the auto deploy flag. If true, it indicates that
+ * @return the value of the auto deploy flag. If true, it indicates that
* this host's child webapps will be dynamically deployed.
*/
@Override
public boolean getAutoDeploy() {
-
- return (this.autoDeploy);
-
+ return this.autoDeploy;
}
@@ -312,14 +299,12 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Return the Java class name of the context configuration class
+ * @return the Java class name of the context configuration class
* for new web applications.
*/
@Override
public String getConfigClass() {
-
- return (this.configClass);
-
+ return this.configClass;
}
@@ -341,13 +326,11 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Return the Java class name of the Context implementation class
+ * @return the Java class name of the Context implementation class
* for new web applications.
*/
public String getContextClass() {
-
- return (this.contextClass);
-
+ return this.contextClass;
}
@@ -368,15 +351,13 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Return the value of the deploy on startup flag. If true, it indicates
+ * @return the value of the deploy on startup flag. If <code>true</code>, it indicates
* that this host's child webapps should be discovered and automatically
* deployed at startup time.
*/
@Override
public boolean getDeployOnStartup() {
-
- return (this.deployOnStartup);
-
+ return this.deployOnStartup;
}
@@ -397,32 +378,28 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Deploy XML Context config files flag accessor.
+ * @return <code>true</code> if XML context descriptors should be deployed.
*/
public boolean isDeployXML() {
-
- return (deployXML);
-
+ return deployXML;
}
/**
* Deploy XML Context config files flag mutator.
+ *
+ * @param deployXML <code>true</code> if context descriptors should be deployed
*/
public void setDeployXML(boolean deployXML) {
-
this.deployXML = deployXML;
-
}
/**
- * Return the copy XML config file flag for this component.
+ * @return the copy XML config file flag for this component.
*/
public boolean isCopyXML() {
-
- return (this.copyXML);
-
+ return this.copyXML;
}
@@ -432,20 +409,16 @@ public class StandardHost extends ContainerBase implements Host {
* @param copyXML The new copy XML flag
*/
public void setCopyXML(boolean copyXML) {
-
- this.copyXML= copyXML;
-
+ this.copyXML = copyXML;
}
/**
- * Return the Java class name of the error report valve class
+ * @return the Java class name of the error report valve class
* for new web applications.
*/
public String getErrorReportValveClass() {
-
- return (this.errorReportValveClass);
-
+ return this.errorReportValveClass;
}
@@ -467,14 +440,12 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Return the canonical, fully qualified, name of the virtual host
+ * @return the canonical, fully qualified, name of the virtual host
* this Container represents.
*/
@Override
public String getName() {
-
- return (name);
-
+ return name;
}
@@ -503,46 +474,44 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Unpack WARs flag accessor.
+ * @return <code>true</code> if WARs should be unpacked on deployment.
*/
public boolean isUnpackWARs() {
-
- return (unpackWARs);
-
+ return unpackWARs;
}
/**
* Unpack WARs flag mutator.
+ *
+ * @param unpackWARs <code>true</code> to unpack WARs on deployment
*/
public void setUnpackWARs(boolean unpackWARs) {
-
this.unpackWARs = unpackWARs;
-
}
/**
- * Host work directory base.
+ * @return host work directory base.
*/
public String getWorkDir() {
-
- return (workDir);
+ return workDir;
}
/**
- * Host work directory base.
+ * Set host work directory base.
+ *
+ * @param workDir the new base work folder for this host
*/
public void setWorkDir(String workDir) {
-
this.workDir = workDir;
}
/**
- * Return the regular expression that defines the files and directories in
- * the host's {@link #appBase} that will be ignored by the automatic
+ * @return the regular expression that defines the files and directories in
+ * the host's {@link #getAppBase} that will be ignored by the automatic
* deployment process.
*/
@Override
@@ -555,8 +524,8 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Return the compiled regular expression that defines the files and
- * directories in the host's {@link #appBase} that will be ignored by the
+ * @return the compiled regular expression that defines the files and
+ * directories in the host's {@link #getAppBase} that will be ignored by the
* automatic deployment process.
*/
@Override
@@ -567,8 +536,10 @@ public class StandardHost extends ContainerBase implements Host {
/**
* Set the regular expression that defines the files and directories in
- * the host's {@link #appBase} that will be ignored by the automatic
+ * the host's {@link #getAppBase} that will be ignored by the automatic
* deployment process.
+ *
+ * @param deployIgnore the regexp
*/
@Override
public void setDeployIgnore(String deployIgnore) {
@@ -589,11 +560,19 @@ public class StandardHost extends ContainerBase implements Host {
}
+ /**
+ * @return <code>true</code> if a webapp start should fail if a Servlet startup fails
+ */
public boolean isFailCtxIfServletStartFails() {
return failCtxIfServletStartFails;
}
+ /**
+ * Change the behavior of Servlet startup errors on web application starts.
+ * @param failCtxIfServletStartFails <code>false</code> to ignore errors on Servlets which
+ * are stated when the web application starts
+ */
public void setFailCtxIfServletStartFails(
boolean failCtxIfServletStartFails) {
boolean oldFailCtxIfServletStartFails = this.failCtxIfServletStartFails;
@@ -624,9 +603,7 @@ public class StandardHost extends ContainerBase implements Host {
return;
}
// Add this alias to the list
- String newAliases[] = new String[aliases.length + 1];
- for (int i = 0; i < aliases.length; i++)
- newAliases[i] = aliases[i];
+ String newAliases[] = Arrays.copyOf(aliases, aliases.length + 1);
newAliases[aliases.length] = alias;
aliases = newAliases;
}
@@ -687,6 +664,8 @@ public class StandardHost extends ContainerBase implements Host {
* This is usually triggered on context reload. Note: This method attempts
* to force a full garbage collection. This should be used with extreme
* caution on a production system.
+ *
+ * @return a list of possibly leaking contexts
*/
public String[] findReloadedContextMemoryLeaks() {
@@ -708,16 +687,14 @@ public class StandardHost extends ContainerBase implements Host {
}
/**
- * Return the set of alias names for this Host. If none are defined,
+ * @return the set of alias names for this Host. If none are defined,
* a zero length array is returned.
*/
@Override
public String[] findAliases() {
-
synchronized (aliasesLock) {
- return (this.aliases);
+ return this.aliases;
}
-
}
@@ -728,9 +705,7 @@ public class StandardHost extends ContainerBase implements Host {
*/
@Override
public String getInfo() {
-
- return (info);
-
+ return info;
}
@@ -816,7 +791,7 @@ public class StandardHost extends ContainerBase implements Host {
}
if(!found) {
Valve valve =
- (Valve) Class.forName(errorValve).getDeclaredConstructor().newInstance();
+ (Valve) Class.forName(errorValve).getConstructor().newInstance();
getPipeline().addValve(valve);
}
} catch (Throwable t) {
@@ -832,7 +807,7 @@ public class StandardHost extends ContainerBase implements Host {
// -------------------- JMX --------------------
/**
- * Return the MBean Names of the Valves associated with this Host
+ * @return the MBean Names of the Valves associated with this Host
*
* @exception Exception if an MBean cannot be created or registered
*/
@@ -840,9 +815,12 @@ public class StandardHost extends ContainerBase implements Host {
Valve [] valves = this.getPipeline().getValves();
String [] mbeanNames = new String[valves.length];
for (int i = 0; i < valves.length; i++) {
- if( valves[i] == null ) continue;
- if( ((ValveBase)valves[i]).getObjectName() == null ) continue;
- mbeanNames[i] = ((ValveBase)valves[i]).getObjectName().toString();
+ if (valves[i] instanceof JmxEnabled) {
+ ObjectName oname = ((JmxEnabled) valves[i]).getObjectName();
+ if (oname != null) {
+ mbeanNames[i] = oname.toString();
+ }
+ }
}
return mbeanNames;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org