tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject svn commit: r441172 - in /tomcat/container/tc5.5.x: catalina/src/share/org/apache/catalina/ant/jmx/Arg.java catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java webapps/docs/changelog.xml webapps/docs/monitoring.xml
Date Thu, 07 Sep 2006 18:38:08 GMT
Author: pero
Date: Thu Sep  7 11:38:07 2006
New Revision: 441172

URL: http://svn.apache.org/viewvc?view=rev&rev=441172
Log:
Add multi attribute setting to jmx:set JMX remote ant task.
Patch contributed by Didier Donsez

Modified:
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/Arg.java
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml
    tomcat/container/tc5.5.x/webapps/docs/monitoring.xml

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/Arg.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/Arg.java?view=diff&rev=441172&r1=441171&r2=441172
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/Arg.java (original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/Arg.java Thu Sep
 7 11:38:07 2006
@@ -23,9 +23,13 @@
  * @since 5.5.10
  */
 public class Arg {
+    String name;
     String type;
     String value;
 
+    public void setName( String name) {
+        this.name=name;
+    }
     public void setType( String type) {
         this.type=type;
     }
@@ -35,11 +39,12 @@
     public void addText( String text ) {
         this.value=text;
     }
-
+    public String getName() {
+        return name;
+    }
     public String getValue() {
         return value;
     }
-
     public String getType() {
         return type;
     }

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java?view=diff&rev=441172&r1=441171&r2=441172
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
(original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
Thu Sep  7 11:38:07 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002,2004-2005 The Apache Software Foundation.
+ * Copyright 2002,2004-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,7 +18,12 @@
 package org.apache.catalina.ant.jmx;
 
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import javax.management.Attribute;
+import javax.management.AttributeList;
 import javax.management.MBeanAttributeInfo;
 import javax.management.MBeanInfo;
 import javax.management.MBeanServerConnection;
@@ -30,9 +35,7 @@
 /**
  * Access <em>JMX</em> JSR 160 MBeans Server. 
  * <ul>
- * <li>Get Mbeans attributes</li>
- * <li>Show Get result as Ant console log</li>
- * <li>Bind Get result as Ant properties</li>
+ * <li>Set Mbeans attributes</li>
  * </ul>
  * <p>
  * Examples:
@@ -42,7 +45,6 @@
  *   &lt;jmx:set
  *           host="127.0.0.1"
  *           port="9014"
- *           ref=""
  *           name="Catalina:type=Manager,path="/ClusterTest",host=localhost" 
  *           attribute="maxActiveSessions"
  *           value="100"
@@ -50,6 +52,26 @@
  *           echo="false"&gt;
  *       /&gt;
  * </pre>
+ *
+ * or 
+ * 
+ * <pre>
+ *   &lt;jmx:set
+ *           host="127.0.0.1"
+ *           port="9014"
+ *           name="Catalina:type=Manager,path="/ClusterTest",host=localhost" 
+ *           echo="false"&gt;
+ *       &gt;
+ *       
+ *        &lt;arg name="notifyListenersOnReplication"
+ *                value="true"
+ *                type="boolean"/&gt;
+ *        &lt;arg name="notifySessionListenersOnReplication"
+ *                value="true"
+ *                type="boolean"/&gt;
+ *   &lt;/jmx:set&gt;
+ *
+ * </pre>
  * </p>
  * <p>
  * First call to a remote MBeanserver save the JMXConnection a referenz <em>jmx.server</em>
@@ -69,13 +91,14 @@
     private String value;
     private String type;
     private boolean convert = false ;
-    
+    private List args=new ArrayList();
+
     // ----------------------------------------------------- Instance Info
 
     /**
      * Descriptive information describing this implementation.
      */
-    private static final String info = "org.apache.catalina.ant.JMXAccessorSetTask/1.0";
+    private static final String info = "org.apache.catalina.ant.JMXAccessorSetTask/1.1";
 
     /**
      * Return descriptive information about this implementation and the
@@ -89,21 +112,30 @@
     }
 
     // ------------------------------------------------------------- Properties
-    
+
+    public void addArg(Arg attribute) {
+        args.add(attribute);
+    }
+
+    public List getArgs() {
+        return args;
+    }
+
+
     /**
      * @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 value.
      */
@@ -116,23 +148,23 @@
     public void setValue(String value) {
         this.value = value;
     }
-    
-    
+
+
     /**
      * @return Returns the type.
      */
     public String getType() {
         return type;
     }
-    
+
     /**
      * @param valueType The type to set.
      */
     public void setType(String valueType) {
         this.type = valueType;
     }
- 
- 
+
+
     /**
      * @return Returns the convert.
      */
@@ -146,7 +178,7 @@
         this.convert = convert;
     }
     // ------------------------------------------------------ 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
@@ -156,17 +188,29 @@
      *                if an error occurs
      */
     public String jmxExecute(MBeanServerConnection jmxServerConnection)
-        throws Exception {
+            throws Exception {
 
         if (getName() == null) {
             throw new BuildException("Must specify a 'name'");
         }
-        if ((attribute == null || value == null)) {
+
+        if ((attribute == null || value == null) && args.isEmpty()) {
             throw new BuildException(
-                    "Must specify a 'attribute' and 'value' for set");
+                    "Must specify a 'attribute' and 'value' or 'attribute' elements for set
with args");
         }
-        return  jmxSet(jmxServerConnection, getName());
-     }
+        if (args.isEmpty()) {
+            return jmxSet(jmxServerConnection, getName());
+        } else {
+            if ((attribute != null && value != null)) {
+                Arg a = new Arg();
+                a.setName(attribute);
+                a.setValue(value);
+                a.setType(type);
+                args.add(a);
+            }
+            return jmxSetWithAttributList(jmxServerConnection, getName());
+        }
+    }
 
     /**
      * @param jmxServerConnection
@@ -190,8 +234,94 @@
                 attribute, realValue));
         return null;
     }
-    
 
+    /**
+     * set several attributes in one invocation to the server
+     * @param jmxServerConnection
+     * @param name
+     * @throws Exception
+     */
+    protected String jmxSetWithAttributList(MBeanServerConnection jmxServerConnection,
+            String name) throws Exception {
+
+        AttributeList attributeList = new AttributeList();
+        MBeanInfo minfo = null;
+
+        for (Iterator iter = args.iterator(); iter.hasNext();) {
+            Arg element = (Arg) iter.next();
+            Object realValue;
+            if (element.getType() != null) {
+                realValue = convertStringToType(element.getValue(), element
+                        .getType());
+            } else {
+                if (isConvert()) {
+                    if (minfo == null)
+                        minfo = getMBeanInfo(jmxServerConnection, name);
+                    String mType = getMBeanAttributeType(minfo, element
+                            .getName());
+                    realValue = convertStringToType(element.getValue(), mType);
+                } else
+                    realValue = element.getValue();
+            }
+            Attribute a = new Attribute(element.getName(), realValue);
+            attributeList.add(a);
+        }
+
+        AttributeList settedAttributes = jmxServerConnection.setAttributes(
+                new ObjectName(name), attributeList);
+        if (isEcho())
+            if (settedAttributes.isEmpty()) {
+                getProject().log("No setted attributes!");
+            } else {
+                StringBuffer sb = new StringBuffer();
+                sb.append("Attributes");
+                for (Iterator iter = settedAttributes.iterator(); iter
+                        .hasNext();) {
+                    Attribute element = (Attribute) iter.next();
+                    sb.append(' ').append(element.getName());
+                }
+                sb.append(" were setted");
+                getProject().log(sb.toString());
+            }
+        return null;
+    }
+
+    /**
+     * Get MBean Attribute from the MBeanInfo
+     * @param minfo
+     * @param attribute
+     * @return The type
+     * @throws Exception
+     */
+    protected String getMBeanAttributeType(
+            MBeanInfo minfo,
+            String attribute) throws Exception {
+        String mattrType = null;
+        MBeanAttributeInfo attrs[] = minfo.getAttributes();
+        if (attrs != null) {
+            for (int i = 0; mattrType == null && i < attrs.length; i++) {
+                if (attribute.equals(attrs[i].getName()))
+                    mattrType = attrs[i].getType();
+            }
+        }
+        return mattrType;
+    }
+
+
+    /**
+     * Get the MBeanInfo from Mbean Server
+     * @param jmxServerConnection
+     * @param name
+     * @return The mbean info
+     * @throws Exception
+     */
+    protected MBeanInfo getMBeanInfo(
+            MBeanServerConnection jmxServerConnection,
+            String name) throws Exception {
+        ObjectName oname = new ObjectName(name);
+        MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
+        return minfo;
+    }
 
     /**
      * Get MBean Attriute from Mbean Server
@@ -217,4 +347,4 @@
         }
         return mattrType;
     }
- }
+}

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?view=diff&rev=441172&r1=441171&r2=441172
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Thu Sep  7 11:38:07 2006
@@ -18,7 +18,9 @@
   <subsection name="General">
     <changelog>
       <update>
-      </update>
+         Add multi attribute setting to jmx:set JMX remote ant task.
+         Patch contributed by Didier Donsez (pero)
+      </update>      
     </changelog>
   </subsection>
   <subsection name="Catalina">

Modified: tomcat/container/tc5.5.x/webapps/docs/monitoring.xml
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/monitoring.xml?view=diff&rev=441172&r1=441171&r2=441172
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/monitoring.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/monitoring.xml Thu Sep  7 11:38:07 2006
@@ -507,6 +507,16 @@
     /&gt;
 </source>
 </p>  
+<p>
+Examples to set multiple remote mbean attributes<br/>
+<source>
+    &lt;jmx:set
+        name="java.lang:type=Threading"&gt; 
+			 &lt;arg name="ThreadContentionMonitoringEnabled" value="true" type="boolean"/&gt;
+			 &lt;arg name="ThreadCpuTimeEnabled" value="false" type="boolean"/&gt;
+    &lt;/jmx:set&gt;
+</source>
+</p>  
 
 </section>
 



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


Mime
View raw message