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/07 21:34:41 UTC

[tomcat] branch 7.0.x updated (4c5f5bb -> 98c9bd7)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 4c5f5bb  Back-port svn->git updates
     new a35cb87  Refactor to reduce code duplication identified by Simian.
     new 98c9bd7  Fix various Javadoc warnings/errors with Java 9 by aligning with 8.5.x

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../catalina/ant/jmx/JMXAccessorCondition.java     | 187 ++-------------------
 ...ondition.java => JMXAccessorConditionBase.java} |  90 ++--------
 .../catalina/ant/jmx/JMXAccessorCreateTask.java    |  12 +-
 .../ant/jmx/JMXAccessorEqualsCondition.java        | 182 ++------------------
 .../catalina/ant/jmx/JMXAccessorGetTask.java       |  24 +--
 .../catalina/ant/jmx/JMXAccessorInvokeTask.java    |  16 +-
 .../catalina/ant/jmx/JMXAccessorQueryTask.java     |  29 ++--
 .../catalina/ant/jmx/JMXAccessorSetTask.java       |  30 ++--
 .../apache/catalina/ant/jmx/JMXAccessorTask.java   |  75 ++++++---
 .../ant/jmx/JMXAccessorUnregisterTask.java         |  23 +--
 java/org/apache/catalina/ant/jmx/package.html      |  17 +-
 11 files changed, 145 insertions(+), 540 deletions(-)
 copy java/org/apache/catalina/ant/jmx/{JMXAccessorEqualsCondition.java => JMXAccessorConditionBase.java} (61%)


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


[tomcat] 02/02: Fix various Javadoc warnings/errors with Java 9 by aligning with 8.5.x

Posted by ma...@apache.org.
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 98c9bd729236f1f3c96a7789c9c983c006824c3a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Sat Sep 7 22:32:30 2019 +0100

    Fix various Javadoc warnings/errors with Java 9 by aligning with 8.5.x
---
 .../catalina/ant/jmx/JMXAccessorCondition.java     | 19 +++---
 .../catalina/ant/jmx/JMXAccessorCreateTask.java    | 12 +---
 .../ant/jmx/JMXAccessorEqualsCondition.java        | 12 ++--
 .../catalina/ant/jmx/JMXAccessorGetTask.java       | 24 +++----
 .../catalina/ant/jmx/JMXAccessorInvokeTask.java    | 16 ++---
 .../catalina/ant/jmx/JMXAccessorQueryTask.java     | 29 +++------
 .../catalina/ant/jmx/JMXAccessorSetTask.java       | 30 ++++-----
 .../apache/catalina/ant/jmx/JMXAccessorTask.java   | 75 ++++++++++++++--------
 .../ant/jmx/JMXAccessorUnregisterTask.java         | 23 +++----
 java/org/apache/catalina/ant/jmx/package.html      | 17 ++---
 10 files changed, 119 insertions(+), 138 deletions(-)

diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java b/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
index ca41ffb..e85327e 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
@@ -19,23 +19,22 @@ package org.apache.catalina.ant.jmx;
 import org.apache.tools.ant.BuildException;
 
 /**
- *
  * <b>Definition</b>:
  * <pre>
- *   &lt;path id="catalina_ant">
- *       &lt;fileset dir="${catalina.home}/server/lib">
- *           &lt;include name="catalina-ant.jar"/>
- *       &lt;/fileset>
- *   &lt;/path>
+ *   &lt;path id="catalina_ant"&gt;
+ *       &lt;fileset dir="${catalina.home}/server/lib"&gt;
+ *           &lt;include name="catalina-ant.jar"/&gt;
+ *       &lt;/fileset&gt;
+ *   &lt;/path&gt;
  *
  *   &lt;typedef
  *       name="jmxCondition"
  *       classname="org.apache.catalina.ant.jmx.JMXAccessorCondition"
- *       classpathref="catalina_ant"/>
+ *       classpathref="catalina_ant"/&gt;
  *   &lt;taskdef
  *       name="jmxOpen"
  *       classname="org.apache.catalina.ant.jmx.JMXAccessorTask"
- *       classpathref="catalina_ant"/>
+ *       classpathref="catalina_ant"/&gt;
  * </pre>
  *
  * <b>Usage</b>: Wait for start backup node
@@ -73,7 +72,7 @@ import org.apache.tools.ant.BuildException;
  * <li>&lt; lesser than (&amp;lt;)</li>
  * <li>&lt;= lesser than or equals (&amp;lt;=)</li>
  * </ul>
- * <b>NOTE</b>:  For numeric expressions the type must be set and use xml entities as operations.<br/>
+ * <b>NOTE</b>:  For numeric expressions the type must be set and use xml entities as operations.<br>
  * As type we currently support <em>long</em> and <em>double</em>.
  * @author Peter Rossbach
  * @since 5.5.10
@@ -185,7 +184,7 @@ public class JMXAccessorCondition extends JMXAccessorConditionBase {
 
     /**
      * This method evaluates the condition
-     * It support for operation ">,>=,<,<=" the types <code>long</code> and <code>double</code>.
+     * It support for operation "&gt;,&gt;=,&lt;,&lt;=" the types <code>long</code> and <code>double</code>.
      * @return expression <em>jmxValue</em> <em>operation</em> <em>value</em>
      */
     @Override
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorCreateTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorCreateTask.java
index 709f4ae..f2da8b9 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorCreateTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorCreateTask.java
@@ -33,8 +33,9 @@ import org.apache.tools.ant.BuildException;
  * </ul>
  * <p>
  * Examples:
- * <br/>
+ * <br>
  * create a new Mbean at jmx.server connection
+ * </p>
  * <pre>
  *   &lt;jmx:create
  *           ref="jmx.server"
@@ -44,7 +45,6 @@ import org.apache.tools.ant.BuildException;
  *            &lt;Arg value="org.apache.catalina.mbeans.MBeanFactory" /&gt;
  *   &lt;/jmxCreate/&gt;
  * </pre>
- * </p>
  * <p>
  * <b>WARNING</b>Not all Tomcat MBeans can create remotely and autoregister by its parents!
  * Please, use the MBeanFactory operation to generate valves and realms.
@@ -133,14 +133,6 @@ public class JMXAccessorCreateTask extends JMXAccessorTask {
 
     // ------------------------------------------------------ protected Methods
 
-    /**
-     * Execute the specified command, based on the configured properties. The
-     * input stream will be closed upon completion of this task, whether it was
-     * executed successfully or not.
-     *
-     * @exception Exception
-     *                if an error occurs
-     */
     @Override
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
         throws Exception {
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java b/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
index 16a9ae1..f8327e2 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
@@ -22,16 +22,16 @@ import org.apache.tools.ant.BuildException;
  *
  * Definition
  * <pre>
- *   &lt;path id="catalina_ant">
- *       &lt;fileset dir="${catalina.home}/server/lib">
- *           &lt;include name="catalina-ant.jar"/>
- *       &lt;/fileset>
- *   &lt;/path>
+ *   &lt;path id="catalina_ant"&gt;
+ *       &lt;fileset dir="${catalina.home}/server/lib"&gt;
+ *           &lt;include name="catalina-ant.jar"/&gt;
+ *       &lt;/fileset&gt;
+ *   &lt;/path&gt;
  *
  *   &lt;typedef
  *       name="jmxEquals"
  *       classname="org.apache.catalina.ant.jmx.JMXAccessorEqualsCondition"
- *       classpathref="catalina_ant"/>
+ *       classpathref="catalina_ant"/&gt;
  * </pre>
  *
  * usage: Wait for start backup node
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorGetTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorGetTask.java
index dea12a3..93b51a0 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorGetTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorGetTask.java
@@ -34,8 +34,9 @@ import org.apache.tools.ant.BuildException;
  * </ul>
  * <p>
  * Examples:
- * <br/>
+ * <br>
  * Get a Mbean IDataSender attribute nrOfRequests and create a new ant property <em>IDataSender.9025.nrOfRequests</em>
+ * </p>
  * <pre>
  *   &lt;jmx:get
  *           ref="jmx.server"
@@ -45,7 +46,6 @@ import org.apache.tools.ant.BuildException;
  *           echo="false"&gt;
  *       /&gt;
  * </pre>
- * </p>
  * <p>
  * First call to a remote MBeanserver save the JMXConnection a referenz <em>jmx.server</em>
  * </p>
@@ -99,14 +99,6 @@ public class JMXAccessorGetTask extends JMXAccessorTask {
 
     // ------------------------------------------------------ protected Methods
 
-    /**
-     * Execute the specified command, based on the configured properties. The
-     * input stream will be closed upon completion of this task, whether it was
-     * executed successfully or not.
-     *
-     * @exception BuildException
-     *                if an error occurs
-     */
     @Override
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
         throws Exception {
@@ -123,12 +115,14 @@ public class JMXAccessorGetTask extends JMXAccessorTask {
 
 
     /**
-     * @param jmxServerConnection
-     * @param name
-     * @return The value of the given named attribute
-     * @throws Exception
+     * Get property value.
+     *
+     * @param jmxServerConnection Connection to the JMX server
+     * @param name The MBean name
+     * @return The error message if any
+     * @throws Exception An error occurred
      */
-    protected String jmxGet(MBeanServerConnection jmxServerConnection,String name) throws Exception {
+    protected String jmxGet(MBeanServerConnection jmxServerConnection, String name) throws Exception {
         String error = null;
         if(isEcho()) {
             handleOutput("MBean " + name + " get attribute " + attribute );
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorInvokeTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorInvokeTask.java
index bc8d977..b4ae638 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorInvokeTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorInvokeTask.java
@@ -150,14 +150,6 @@ public class JMXAccessorInvokeTask extends JMXAccessorTask {
 
     // ------------------------------------------------------ protected Methods
 
-    /**
-     * Execute the specified command, based on the configured properties. The
-     * input stream will be closed upon completion of this task, whether it was
-     * executed successfully or not.
-     *
-     * @exception BuildException
-     *                if an error occurs
-     */
     @Override
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
         throws Exception {
@@ -173,8 +165,12 @@ public class JMXAccessorInvokeTask extends JMXAccessorTask {
      }
 
     /**
-     * @param jmxServerConnection
-     * @throws Exception
+     * Invoke specified operation.
+     *
+     * @param jmxServerConnection Connection to the JMX server
+     * @param name The MBean name
+     * @return null (no error message to report other than exception)
+     * @throws Exception An error occurred
      */
     protected String jmxInvoke(MBeanServerConnection jmxServerConnection, String name) throws Exception {
         Object result ;
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java
index 125ba07..cf7a5a0 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java
@@ -49,7 +49,7 @@ import org.apache.tools.ant.BuildException;
  *           resultproperty="manager" /&gt;
  * </pre>
  * with attribute <em>attributebinding="true"</em> you can get
- * all attributes also from result objects.<br/>
+ * all attributes also from result objects.<br>
  * The property manager.length show the size of the result
  * and with manager.[0..length].name the
  * resulted ObjectNames are saved.
@@ -101,14 +101,6 @@ public class JMXAccessorQueryTask extends JMXAccessorTask {
     // ------------------------------------------------------ protected Methods
 
 
-    /**
-     * Execute the specified command, based on the configured properties. The
-     * input stream will be closed upon completion of this task, whether it was
-     * executed successfully or not.
-     *
-     * @exception Exception
-     *                if an error occurs
-     */
     @Override
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
         throws Exception {
@@ -124,10 +116,10 @@ public class JMXAccessorQueryTask extends JMXAccessorTask {
     /**
      * Call Mbean server for some mbeans with same domain, attributes.
      *  with <em>attributebinding=true</em> you can save all attributes from all found objects
-     * as your ant properties
-     * @param jmxServerConnection
-     * @param qry
-     * @return The query result
+     *
+     * @param jmxServerConnection Connection to the JMX server
+     * @param qry The query
+     * @return null (no error message to report other than exception)
      */
     protected String jmxQuery(MBeanServerConnection jmxServerConnection,
             String qry) {
@@ -153,12 +145,11 @@ public class JMXAccessorQueryTask extends JMXAccessorTask {
                 ObjectName oname = it.next();
                 pname = resultproperty + "." + Integer.toString(oindex) + ".";
                 oindex++;
-                    setProperty(pname + "Name", oname.toString());
-                    if (isAttributebinding()) {
-                        bindAttributes(jmxServerConnection, resultproperty, pname, oname);
-
-                    }
+                setProperty(pname + "Name", oname.toString());
+                if (isAttributebinding()) {
+                    bindAttributes(jmxServerConnection, resultproperty, pname, oname);
                 }
+            }
         }
         return isError;
     }
@@ -171,7 +162,7 @@ public class JMXAccessorQueryTask extends JMXAccessorTask {
      */
     protected void bindAttributes(MBeanServerConnection jmxServerConnection, String resultproperty, String pname, ObjectName oname) {
         if (jmxServerConnection != null  && resultproperty != null
-            && pname != null && oname != null ) {
+                && pname != null && oname != null ) {
             try {
                 MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
                 MBeanAttributeInfo attrs[] = minfo.getAttributes();
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
index 1cc0cd9..c5b9a97 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
@@ -39,6 +39,7 @@ import org.apache.tools.ant.BuildException;
  * Examples:
  * Set a Mbean Manager attribute maxActiveSessions.
  * Set this attribute with fresh jmx connection without save reference
+ * </p>
  * <pre>
  *   &lt;jmx:set
  *           host="127.0.0.1"
@@ -51,7 +52,6 @@ import org.apache.tools.ant.BuildException;
  *           echo="false"&gt;
  *       /&gt;
  * </pre>
- * </p>
  * <p>
  * First call to a remote MBeanserver save the JMXConnection a referenz <em>jmx.server</em>
  * </p>
@@ -147,14 +147,6 @@ public class JMXAccessorSetTask extends JMXAccessorTask {
     }
     // ------------------------------------------------------ protected Methods
 
-    /**
-     * Execute the specified command, based on the configured properties. The
-     * input stream will be closed upon completion of this task, whether it was
-     * executed successfully or not.
-     *
-     * @exception Exception
-     *                if an error occurs
-     */
     @Override
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
         throws Exception {
@@ -170,9 +162,12 @@ public class JMXAccessorSetTask extends JMXAccessorTask {
      }
 
     /**
-     * @param jmxServerConnection
-     * @param name
-     * @throws Exception
+     * Set property value.
+     *
+     * @param jmxServerConnection Connection to the JMX server
+     * @param name The MBean name
+     * @return null (no error message to report other than exception)
+     * @throws Exception An error occurred
      */
     protected String jmxSet(MBeanServerConnection jmxServerConnection,
             String name) throws Exception {
@@ -195,11 +190,12 @@ public class JMXAccessorSetTask extends JMXAccessorTask {
 
     /**
      * Get MBean Attribute from Mbean Server
-     * @param jmxServerConnection
-     * @param name
-     * @param attribute
-     * @return The type
-     * @throws Exception
+     *
+     * @param jmxServerConnection The JMX connection name
+     * @param name The MBean name
+     * @param attribute The attribute name
+     * @return The type of the attribute
+     * @throws Exception An error occurred
      */
     protected String getMBeanAttributeType(
             MBeanServerConnection jmxServerConnection,
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
index ef63f3c..efc5247 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
@@ -144,11 +144,12 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     // ------------------------------------------------------------- Properties
 
     /**
-     * The name used at remote MbeanServer
+     * Get the name used at remote MbeanServer.
+     *
+     * @return the name used at remote MbeanServer
      */
-
     public String getName() {
-        return (this.name);
+        return this.name;
     }
 
     public void setName(String objectName) {
@@ -214,10 +215,10 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     }
 
     /**
-     * The login password for the <code>Manager</code> application.
+     * @return The login password for the <code>Manager</code> application.
      */
     public String getPassword() {
-        return (this.password);
+        return this.password;
     }
 
     public void setPassword(String password) {
@@ -225,10 +226,10 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     }
 
     /**
-     * The login username for the <code>JMX</code> MBeanServer.
+     * @return The login username for the <code>JMX</code> MBeanServer.
      */
     public String getUsername() {
-        return (this.username);
+        return this.username;
     }
 
     public void setUsername(String username) {
@@ -236,11 +237,10 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     }
 
     /**
-     * The URL of the <code>JMX JSR 160</code> MBeanServer to be used.
+     * @return The URL of the <code>JMX JSR 160</code> MBeanServer to be used.
      */
-
     public String getUrl() {
-        return (this.url);
+        return this.url;
     }
 
     public void setUrl(String url) {
@@ -248,11 +248,10 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     }
 
     /**
-     * The Host of the <code>JMX JSR 160</code> MBeanServer to be used.
+     * @return The Host of the <code>JMX JSR 160</code> MBeanServer to be used.
      */
-
     public String getHost() {
-        return (this.host);
+        return this.host;
     }
 
     public void setHost(String host) {
@@ -260,11 +259,10 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     }
 
     /**
-     * The Port of the <code>JMX JSR 160</code> MBeanServer to be used.
+     * @return The Port of the <code>JMX JSR 160</code> MBeanServer to be used.
      */
-
     public String getPort() {
-        return (this.port);
+        return this.port;
     }
 
     public void setPort(String port) {
@@ -362,7 +360,18 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     }
 
     /**
-     * create a new JMX Connection with auth when username and password is set.
+     * Create a new JMX Connection with auth when username and password is set.
+     *
+     * @param url URL to be used for the JMX connection
+     *        (if specified, it is a complete URL so host and port will not
+     *        be used)
+     * @param host Host name of the JMX server
+     * @param port Port number for the JMX server
+     * @param username User name for the connection
+     * @param password Credentials corresponding to the specified user
+     * @throws MalformedURLException Invalid URL specified
+     * @throws IOException Other connection error
+     * @return the JMX connection
      */
     public static MBeanServerConnection createJMXConnection(String url,
             String host, String port, String username, String password)
@@ -414,9 +423,18 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     /**
      * Get Current Connection from <em>ref</em> parameter or create a new one!
      *
-     * @return The server connection
-     * @throws MalformedURLException
-     * @throws IOException
+     * @param project The Ant project
+     * @param url URL to be used for the JMX connection
+     *        (if specified, it is a complete URL so host and port will not
+     *        be used)
+     * @param host Host name of the JMX server
+     * @param port Port number for the JMX server
+     * @param username User name for the connection
+     * @param password Credentials corresponding to the specified user
+     * @param refId The Id of the reference to retrieve in the project
+     * @throws MalformedURLException Invalid URL specified
+     * @throws IOException Other connection error
+     * @return the JMX connection
      */
     @SuppressWarnings("null")
     public static MBeanServerConnection accessJMXConnection(Project project,
@@ -450,9 +468,9 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
     /**
      * get JMXConnection
      *
-     * @return The connection
-     * @throws MalformedURLException
-     * @throws IOException
+     * @throws MalformedURLException Invalid URL specified
+     * @throws IOException Other connection error
+     * @return the JMX connection
      */
     protected MBeanServerConnection getJMXConnection()
             throws MalformedURLException, IOException {
@@ -490,8 +508,9 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
      * input stream will be closed upon completion of this task, whether it was
      * executed successfully or not.
      *
-     * @exception Exception
-     *                if an error occurs
+     * @param jmxServerConnection The JMX connection that should be used
+     * @return An error message string in some situations
+     * @exception Exception if an error occurs
      */
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
             throws Exception {
@@ -573,7 +592,7 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
 
     /**
      * @param name context of result
-     * @param result
+     * @param result The result
      */
     protected void echoResult(String name, Object result) {
         if (isEcho()) {
@@ -606,8 +625,8 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask {
      * option is that you delimit your result with a delimiter
      * (java.util.StringTokenizer is used).
      *
-     * @param propertyPrefix
-     * @param result
+     * @param propertyPrefix Prefix for the property
+     * @param result The result
      */
     protected void createProperty(String propertyPrefix, Object result) {
         if (propertyPrefix == null)
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorUnregisterTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorUnregisterTask.java
index 8e2752e..07f4597 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorUnregisterTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorUnregisterTask.java
@@ -28,14 +28,14 @@ import org.apache.tools.ant.BuildException;
  * </ul>
  * <p>
  * Examples:
- * <br/>
+ * <br>
  * unregister an existing Mbean at jmx.server connection
+ * </p>
  * <pre>
  *   &lt;jmx:unregister
  *           ref="jmx.server"
  *           name="Catalina:type=MBeanFactory" /&gt;
  * </pre>
- * </p>
  * <p>
  * <b>WARNING</b>Not all Tomcat MBeans can successfully unregister remotely. The mbean
  * unregistration don't remove valves, realm, .. from parent class.
@@ -72,14 +72,6 @@ public class JMXAccessorUnregisterTask extends JMXAccessorTask {
     }
     // ------------------------------------------------------ protected Methods
 
-    /**
-     * Execute the specified command, based on the configured properties. The
-     * input stream will be closed upon completion of this task, whether it was
-     * executed successfully or not.
-     *
-     * @exception Exception
-     *                if an error occurs
-     */
     @Override
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
         throws Exception {
@@ -92,11 +84,12 @@ public class JMXAccessorUnregisterTask extends JMXAccessorTask {
 
 
     /**
-     * Unregister Mbean
-     * @param jmxServerConnection
-     * @param name
-     * @return The value of the given named attribute
-     * @throws Exception
+     * Unregister MBean.
+     *
+     * @param jmxServerConnection Connection to the JMX server
+     * @param name The MBean name
+     * @return null (no error message to report other than exception)
+     * @throws Exception An error occurred
      */
     protected String jmxUuregister(MBeanServerConnection jmxServerConnection,String name) throws Exception {
         String error = null;
diff --git a/java/org/apache/catalina/ant/jmx/package.html b/java/org/apache/catalina/ant/jmx/package.html
index 0dc843f..8b2c6dd 100644
--- a/java/org/apache/catalina/ant/jmx/package.html
+++ b/java/org/apache/catalina/ant/jmx/package.html
@@ -27,42 +27,43 @@ https://tomcat.apache.org/tomcat-7.0-doc/monitoring.html</a>.</p>
 existing one. The following attribute are exists in every tasks:</p>
 
 <table>
+  <caption>Common task attributes</caption>
   <tr>
-    <th align="center" width="15%">Attribute</th>
-    <th align="center" width="85%">Description</th>
+    <th>Attribute</th>
+    <th>Description</th>
   </tr>
   <tr>
-    <td align="center">url</td>
+    <td>url</td>
     <td>
       The JMX Connection URL of the remote Tomcat MBeansServer.
     </td>
   </tr>
   <tr>
-    <td align="center">username</td>
+    <td>username</td>
     <td>
       The username of a MBeanServer auth, when configured.
     </td>
   </tr>
   <tr>
-    <td align="center">password</td>
+    <td>password</td>
     <td>
       The password of a MBeanServer auth, when configured.
     </td>
   </tr>
   <tr>
-    <td align="center">host</td>
+    <td>host</td>
     <td>
       The JMX Connection host.
     </td>
   </tr>
   <tr>
-    <td align="center">port</td>
+    <td>port</td>
     <td>
       The JMX Connection port.
     </td>
   </tr>
   <tr>
-    <td align="center">ref</td>
+    <td>ref</td>
     <td>
       The name of the ant internal reference for a jmx connection.
     </td>


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


[tomcat] 01/02: Refactor to reduce code duplication identified by Simian.

Posted by ma...@apache.org.
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 a35cb870f50f5d90b1ff10728fc84b21e9141c4b
Author: Mark Emlyn David Thomas <ma...@apache.org>
AuthorDate: Mon Sep 8 12:21:13 2014 +0000

    Refactor to reduce code duplication identified by Simian.
---
 .../catalina/ant/jmx/JMXAccessorCondition.java     | 168 +-------------------
 ...ondition.java => JMXAccessorConditionBase.java} |  90 ++---------
 .../ant/jmx/JMXAccessorEqualsCondition.java        | 170 +--------------------
 3 files changed, 26 insertions(+), 402 deletions(-)

diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java b/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
index 3d2a21f..ca41ffb 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
@@ -14,18 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.catalina.ant.jmx;
 
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.ProjectComponent;
-import org.apache.tools.ant.taskdefs.condition.Condition;
 
 /**
  *
@@ -87,21 +78,12 @@ import org.apache.tools.ant.taskdefs.condition.Condition;
  * @author Peter Rossbach
  * @since 5.5.10
  */
-public class JMXAccessorCondition extends ProjectComponent implements Condition {
+public class JMXAccessorCondition extends JMXAccessorConditionBase {
 
     // ----------------------------------------------------- Instance Variables
 
-    private String url = null;
-    private String host = "localhost";
-    private String port = "8050";
-    private String password = null;
-    private String username = null;
-    private String name = null;
-    private String attribute;
-    private String value;
     private String operation = "==" ;
     private String type = "long" ;
-    private String ref = "jmx.server";
     private String unlessCondition;
     private String ifCondition;
 
@@ -118,10 +100,9 @@ public class JMXAccessorCondition extends ProjectComponent implements Condition
      * <code>&lt;description&gt;/&lt;version&gt;</code>.
      */
     public String getInfo() {
-
-        return (info);
-
+        return info;
     }
+
     // ----------------------------------------------------- Properties
 
     /**
@@ -149,114 +130,8 @@ public class JMXAccessorCondition extends ProjectComponent implements Condition
     public void setType(String type) {
         this.type = type;
     }
-    /**
-     * @return Returns the attribute.
-     */
-    public String getAttribute() {
-        return attribute;
-    }
-    /**
-     * @param attribute The attribute to set.
-     */
-    public void setAttribute(String attribute) {
-        this.attribute = attribute;
-    }
-    /**
-     * @return Returns the host.
-     */
-    public String getHost() {
-        return host;
-    }
-    /**
-     * @param host The host to set.
-     */
-    public void setHost(String host) {
-        this.host = host;
-    }
-    /**
-     * @return Returns the name.
-     */
-    public String getName() {
-        return name;
-    }
-    /**
-     * @param objectName The name to set.
-     */
-    public void setName(String objectName) {
-        this.name = objectName;
-    }
-    /**
-     * @return Returns the password.
-     */
-    public String getPassword() {
-        return password;
-    }
-    /**
-     * @param password The password to set.
-     */
-    public void setPassword(String password) {
-        this.password = password;
-    }
-    /**
-     * @return Returns the port.
-     */
-    public String getPort() {
-        return port;
-    }
-    /**
-     * @param port The port to set.
-     */
-    public void setPort(String port) {
-        this.port = port;
-    }
-    /**
-     * @return Returns the url.
-     */
-    public String getUrl() {
-        return url;
-    }
-    /**
-     * @param url The url to set.
-     */
-    public void setUrl(String url) {
-        this.url = url;
-    }
-    /**
-     * @return Returns the username.
-     */
-    public String getUsername() {
-        return username;
-    }
-    /**
-     * @param username The username to set.
-     */
-    public void setUsername(String username) {
-        this.username = username;
-    }
-    /**
-     * @return Returns the value.
-     */
-    public String getValue() {
-        return value;
-    }
-    // The setter for the "value" attribute
-    public void setValue(String value) {
-        this.value = value;
-    }
 
     /**
-     * @return Returns the ref.
-     */
-    public String getRef() {
-        return ref;
-    }
-    /**
-     * @param refId The ref to set.
-     */
-    public void setRef(String refId) {
-        this.ref = refId;
-    }
-    /**
      * @return Returns the ifCondition.
      */
     public String getIf() {
@@ -269,13 +144,13 @@ public class JMXAccessorCondition extends ProjectComponent implements Condition
     public void setIf(String c) {
         ifCondition = c;
     }
+
    /**
      * @return Returns the unlessCondition.
      */
     public String getUnless() {
         return unlessCondition;
     }
-
     /**
      * Only execute if a property of the given name does not
      * exist in the current project.
@@ -286,36 +161,6 @@ public class JMXAccessorCondition extends ProjectComponent implements Condition
     }
 
     /**
-     * Get JMXConnection (default look at <em>jmx.server</em> project reference from jmxOpen Task)
-     * @return active JMXConnection
-     * @throws MalformedURLException
-     * @throws IOException
-     */
-    protected MBeanServerConnection getJMXConnection()
-            throws MalformedURLException, IOException {
-        return JMXAccessorTask.accessJMXConnection(
-                getProject(),
-                getUrl(), getHost(),
-                getPort(), getUsername(), getPassword(), ref);
-    }
-
-    /**
-     * Get value from MBeans attribute
-     * @return The value
-     */
-    protected String accessJMXValue() {
-        try {
-            Object result = getJMXConnection().getAttribute(
-                    new ObjectName(name), attribute);
-            if(result != null)
-                return result.toString();
-        } catch (Exception e) {
-            // ignore access or connection open errors
-        }
-        return null;
-    }
-
-    /**
      * test the if condition
      * @return true if there is no if condition, or the named property exists
      */
@@ -345,15 +190,16 @@ public class JMXAccessorCondition extends ProjectComponent implements Condition
      */
     @Override
     public boolean eval() {
+        String value = getValue();
         if (operation == null) {
             throw new BuildException("operation attribute is not set");
         }
         if (value == null) {
             throw new BuildException("value attribute is not set");
         }
-        if ((name == null || attribute == null)) {
+        if ((getName() == null || getAttribute() == null)) {
             throw new BuildException(
-                    "Must specify a 'attribute', name for equals condition");
+                    "Must specify an MBean name and attribute for condition");
         }
         if (testIfCondition() && testUnlessCondition()) {
             String jmxValue = accessJMXValue();
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java b/java/org/apache/catalina/ant/jmx/JMXAccessorConditionBase.java
similarity index 61%
copy from java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
copy to java/org/apache/catalina/ant/jmx/JMXAccessorConditionBase.java
index b001c0e..8348213 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorConditionBase.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.catalina.ant.jmx;
 
 import java.io.IOException;
@@ -23,52 +22,10 @@ import java.net.MalformedURLException;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 
-import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.ProjectComponent;
 import org.apache.tools.ant.taskdefs.condition.Condition;
 
-/**
- *
- * Definition
- * <pre>
- *   &lt;path id="catalina_ant">
- *       &lt;fileset dir="${catalina.home}/server/lib">
- *           &lt;include name="catalina-ant.jar"/>
- *       &lt;/fileset>
- *   &lt;/path>
- *
- *   &lt;typedef
- *       name="jmxEquals"
- *       classname="org.apache.catalina.ant.jmx.JMXAccessorEqualsCondition"
- *       classpathref="catalina_ant"/>
- * </pre>
- *
- * usage: Wait for start backup node
- * <pre>
- *     &lt;target name="wait"&gt;
- *        &lt;waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" &gt;
- *           &lt;and&gt;
- *               &lt;socket server="${server.name}" port="${server.port}"/&gt;
- *               &lt;http url="${url}"/&gt;
- *               &lt;jmxEquals
- *                   host="localhost" port="9014" username="controlRole" password="tomcat"
- *                   name="Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025"
- *                   attribute="connected" value="true"
- *               /&gt;
- *           &lt;/and&gt;
- *       &lt;/waitfor&gt;
- *       &lt;fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" /&gt;
- *       &lt;echo message="Server ${url} alive" /&gt;
- *   &lt;/target&gt;
- *
- * </pre>
- *
- * @author Peter Rossbach
- * @since 5.5.10
- */
-public class JMXAccessorEqualsCondition  extends ProjectComponent  implements Condition {
-
-    // ----------------------------------------------------- Instance Variables
+public abstract class JMXAccessorConditionBase extends ProjectComponent implements Condition {
 
     private String url = null;
     private String host = "localhost";
@@ -79,24 +36,6 @@ public class JMXAccessorEqualsCondition  extends ProjectComponent  implements Co
     private String attribute;
     private String value;
     private String ref = "jmx.server" ;
-    // ----------------------------------------------------- Instance Info
-
-    /**
-     * Descriptive information describing this implementation.
-     */
-    private static final String info = "org.apache.catalina.ant.JMXAccessorEqualsCondition/1.1";
-
-    /**
-     * Return descriptive information about this implementation and the
-     * corresponding version number, in the format
-     * <code>&lt;description&gt;/&lt;version&gt;</code>.
-     */
-    public String getInfo() {
-
-        return (info);
-
-    }
-    // ----------------------------------------------------- Properties
 
     /**
      * @return Returns the attribute.
@@ -206,6 +145,14 @@ public class JMXAccessorEqualsCondition  extends ProjectComponent  implements Co
         this.ref = refId;
     }
 
+    /**
+     * Get JMXConnection (default look at <em>jmx.server</em> project reference
+     * from jmxOpen Task).
+     *
+     * @return active JMXConnection
+     * @throws MalformedURLException
+     * @throws IOException
+     */
     protected MBeanServerConnection getJMXConnection()
             throws MalformedURLException, IOException {
         return JMXAccessorTask.accessJMXConnection(
@@ -215,6 +162,8 @@ public class JMXAccessorEqualsCondition  extends ProjectComponent  implements Co
     }
 
     /**
+     * Get value from MBeans attribute.
+     *
      * @return The value
      */
     protected String accessJMXValue() {
@@ -228,22 +177,5 @@ public class JMXAccessorEqualsCondition  extends ProjectComponent  implements Co
         }
         return null;
     }
-
-    // This method evaluates the condition
-    @Override
-    public boolean eval() {
-        if (value == null) {
-            throw new BuildException("value attribute is not set");
-        }
-        if ((name == null || attribute == null)) {
-            throw new BuildException(
-                    "Must specify a 'attribute', name for equals condition");
-        }
-        //FIXME check url or host/parameter
-        String jmxValue = accessJMXValue();
-        if(jmxValue != null)
-            return jmxValue.equals(value);
-        return false;
-    }
 }
 
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java b/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
index b001c0e..16a9ae1 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorEqualsCondition.java
@@ -14,18 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.catalina.ant.jmx;
 
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.ProjectComponent;
-import org.apache.tools.ant.taskdefs.condition.Condition;
 
 /**
  *
@@ -66,20 +57,7 @@ import org.apache.tools.ant.taskdefs.condition.Condition;
  * @author Peter Rossbach
  * @since 5.5.10
  */
-public class JMXAccessorEqualsCondition  extends ProjectComponent  implements Condition {
-
-    // ----------------------------------------------------- Instance Variables
-
-    private String url = null;
-    private String host = "localhost";
-    private String port = "8050";
-    private String password = null;
-    private String username = null;
-    private String name = null;
-    private String attribute;
-    private String value;
-    private String ref = "jmx.server" ;
-    // ----------------------------------------------------- Instance Info
+public class JMXAccessorEqualsCondition extends JMXAccessorConditionBase {
 
     /**
      * Descriptive information describing this implementation.
@@ -92,157 +70,25 @@ public class JMXAccessorEqualsCondition  extends ProjectComponent  implements Co
      * <code>&lt;description&gt;/&lt;version&gt;</code>.
      */
     public String getInfo() {
-
-        return (info);
-
-    }
-    // ----------------------------------------------------- Properties
-
-    /**
-     * @return Returns the attribute.
-     */
-    public String getAttribute() {
-        return attribute;
-    }
-    /**
-     * @param attribute The attribute to set.
-     */
-    public void setAttribute(String attribute) {
-        this.attribute = attribute;
-    }
-    /**
-     * @return Returns the host.
-     */
-    public String getHost() {
-        return host;
-    }
-    /**
-     * @param host The host to set.
-     */
-    public void setHost(String host) {
-        this.host = host;
-    }
-    /**
-     * @return Returns the name.
-     */
-    public String getName() {
-        return name;
-    }
-    /**
-     * @param objectName The name to set.
-     */
-    public void setName(String objectName) {
-        this.name = objectName;
-    }
-    /**
-     * @return Returns the password.
-     */
-    public String getPassword() {
-        return password;
-    }
-    /**
-     * @param password The password to set.
-     */
-    public void setPassword(String password) {
-        this.password = password;
-    }
-    /**
-     * @return Returns the port.
-     */
-    public String getPort() {
-        return port;
-    }
-    /**
-     * @param port The port to set.
-     */
-    public void setPort(String port) {
-        this.port = port;
-    }
-    /**
-     * @return Returns the url.
-     */
-    public String getUrl() {
-        return url;
-    }
-    /**
-     * @param url The url to set.
-     */
-    public void setUrl(String url) {
-        this.url = url;
-    }
-    /**
-     * @return Returns the username.
-     */
-    public String getUsername() {
-        return username;
-    }
-    /**
-     * @param username The username to set.
-     */
-    public void setUsername(String username) {
-        this.username = username;
-    }
-    /**
-     * @return Returns the value.
-     */
-    public String getValue() {
-        return value;
-    }
-    // The setter for the "value" attribute
-    public void setValue(String value) {
-        this.value = value;
+        return info;
     }
 
-    /**
-     * @return Returns the ref.
-     */
-    public String getRef() {
-        return ref;
-    }
-    /**
-     * @param refId The ref to set.
-     */
-    public void setRef(String refId) {
-        this.ref = refId;
-    }
-
-    protected MBeanServerConnection getJMXConnection()
-            throws MalformedURLException, IOException {
-        return JMXAccessorTask.accessJMXConnection(
-                getProject(),
-                getUrl(), getHost(),
-                getPort(), getUsername(), getPassword(), ref);
-    }
-
-    /**
-     * @return The value
-     */
-    protected String accessJMXValue() {
-        try {
-            Object result = getJMXConnection().getAttribute(
-                    new ObjectName(name), attribute);
-            if(result != null)
-                return result.toString();
-        } catch (Exception e) {
-            // ignore access or connection open errors
-        }
-        return null;
-    }
-
-    // This method evaluates the condition
     @Override
     public boolean eval() {
+        String value = getValue();
+
         if (value == null) {
             throw new BuildException("value attribute is not set");
         }
-        if ((name == null || attribute == null)) {
+        if (getName() == null || getAttribute() == null) {
             throw new BuildException(
-                    "Must specify a 'attribute', name for equals condition");
+                    "Must specify an MBean name and attribute for equals condition");
         }
         //FIXME check url or host/parameter
         String jmxValue = accessJMXValue();
-        if(jmxValue != null)
+        if (jmxValue != null) {
             return jmxValue.equals(value);
+        }
         return false;
     }
 }


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