pero 2005/07/08 13:54:40
Modified: catalina/src/share/org/apache/catalina/ant/jmx
JMXAccessorQueryTask.java JMXAccessorTask.java
Log:
more support for MXBean data
better property binding support
Revision Changes Path
1.3 +54 -60
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java
Index: JMXAccessorQueryTask.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JMXAccessorQueryTask.java 30 Jun 2005 13:01:27 -0000 1.2
+++ JMXAccessorQueryTask.java 8 Jul 2005 20:54:40 -0000 1.3
@@ -135,31 +135,29 @@
String resultproperty = getResultproperty();
try {
names = jmxServerConnection.queryNames(new ObjectName(qry),
null);
- if (resultproperty != null)
- getProject().setNewProperty(resultproperty + ".length",
- Integer.toString(names.size()));
+ if (resultproperty != null) {
+ setProperty(resultproperty +
".Length",Integer.toString(names.size()));
+ }
} catch (Exception e) {
if (isEcho())
handleErrorOutput(e.getMessage());
return "Can't query mbeans " + qry;
}
- Iterator it = names.iterator();
- int oindex = 0;
- String pname = null;
- while (it.hasNext()) {
- ObjectName oname = (ObjectName) it.next();
- pname = resultproperty + "." + Integer.toString(oindex) + ".";
- oindex++;
- if (isEcho())
- handleOutput(pname + "name=" + oname.toString());
- if (resultproperty != null) {
- getProject().setNewProperty(pname + "name",
- oname.toString());
- }
- if (isAttributebinding()) {
- bindAttributes(jmxServerConnection, resultproperty, pname,
oname);
- }
+ if (resultproperty != null) {
+ Iterator it = names.iterator();
+ int oindex = 0;
+ String pname = null;
+ while (it.hasNext()) {
+ ObjectName oname = (ObjectName) it.next();
+ pname = resultproperty + "." + Integer.toString(oindex) +
".";
+ oindex++;
+ setProperty(pname + "Name", oname.toString());
+ if (isAttributebinding()) {
+ bindAttributes(jmxServerConnection, resultproperty,
pname, oname);
+
+ }
+ }
}
return isError;
}
@@ -171,50 +169,46 @@
* @param oname
*/
protected void bindAttributes(MBeanServerConnection jmxServerConnection,
String resultproperty, String pname, ObjectName oname) {
- try {
- MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
- String code = minfo.getClassName();
- if ("org.apache.commons.modeler.BaseModelMBean"
- .equals(code)) {
- code = (String) jmxServerConnection.getAttribute(oname,
- "modelerType");
- }
- MBeanAttributeInfo attrs[] = minfo.getAttributes();
- Object value = null;
-
- for (int i = 0; i < attrs.length; i++) {
- if (!attrs[i].isReadable())
- continue;
- String attName = attrs[i].getName();
- if (attName.indexOf("=") >= 0
- || attName.indexOf(":") >= 0
- || attName.indexOf(" ") >= 0) {
- continue;
+ if (jmxServerConnection != null && resultproperty != null
+ && pname != null && oname != null ) {
+ try {
+ MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
+ String code = minfo.getClassName();
+ if
("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
+ code = (String) jmxServerConnection.getAttribute(oname,
+ "modelerType");
}
+ MBeanAttributeInfo attrs[] = minfo.getAttributes();
+ Object value = null;
- try {
- value = jmxServerConnection.getAttribute(oname,
- attName);
- } catch (Throwable t) {
- if (isEcho())
- handleErrorOutput("Error getting attribute "
- + oname + " " + pname + attName + " "
- + t.toString());
- continue;
+ for (int i = 0; i < attrs.length; i++) {
+ if (!attrs[i].isReadable())
+ continue;
+ String attName = attrs[i].getName();
+ if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0
+ || attName.indexOf(" ") >= 0) {
+ continue;
+ }
+
+ try {
+ value = jmxServerConnection
+ .getAttribute(oname, attName);
+ } catch (Throwable t) {
+ if (isEcho())
+ handleErrorOutput("Error getting attribute "
+ + oname + " " + pname + attName + " "
+ + t.toString());
+ continue;
+ }
+ if (value == null)
+ continue;
+ if ("modelerType".equals(attName))
+ continue;
+ createProperty(pname + attName, value);
}
- if (value == null)
- continue;
- if ("modelerType".equals(attName))
- continue;
- String valueString = value.toString();
- if (isEcho())
- handleOutput(pname + attName + "=" + valueString);
- if (resultproperty != null)
- getProject().setNewProperty(pname + attName,
- valueString);
+ } catch (Exception e) {
+ // Ignore
}
- } catch (Exception e) {
- // Ignore
}
}
}
1.5 +76 -27
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorTask.java
Index: JMXAccessorTask.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/ant/jmx/JMXAccessorTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JMXAccessorTask.java 1 Jul 2005 18:54:13 -0000 1.4
+++ JMXAccessorTask.java 8 Jul 2005 20:54:40 -0000 1.5
@@ -23,12 +23,15 @@
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.StringTokenizer;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import javax.management.openmbean.CompositeDataSupport;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
@@ -461,8 +464,10 @@
if ((jmxServerConnection == null)) {
throw new BuildException("Must open a connection!");
+ } else if (isEcho()) {
+ handleOutput("JMX Connection ref=" + ref + " is open!");
}
- return null;
+ return null;
}
/**
@@ -552,40 +557,84 @@
/**
* create result as property with name from attribute resultproperty
- * When result is an array and isSeparateArrayResults is true,
- * resultproperty used as prefix
(<code>resultproperty.0-array.length</code>
- * and store the result array length at
<code>resultproperty.length</code>.
- * Other option is that you delemit your result with a delimiter
(java.util.StringTokenizer is used).
* @param result
+ * @see #createProperty(String, Object)
*/
protected void createProperty(Object result) {
if (resultproperty != null) {
- if (result.getClass().isArray()) {
- if (isSeparatearrayresults()) {
- Object array[] = (Object[]) result;
- for (int i = 0; i < array.length; i++) {
- getProject().setNewProperty(resultproperty + "." + i,
- array[i].toString());
+ createProperty(resultproperty,result);
+ }
+ }
+
+ /**
+ * create result as property with name from property prefix
+ * When result is an array and isSeparateArrayResults is true,
+ * resultproperty used as prefix
(<code>resultproperty.0-array.length</code>
+ * and store the result array length at
<code>resultproperty.length</code>.
+ * Other option is that you delemit your result with a delimiter
(java.util.StringTokenizer is used).
+ * @param propertyPrefix
+ * @param result
+ */
+ protected void createProperty(String propertyPrefix, Object result) {
+ if (propertyPrefix == null)
+ propertyPrefix = "";
+ if (result instanceof CompositeDataSupport) {
+ CompositeDataSupport data = (CompositeDataSupport) result ;
+ Set keys = data.getCompositeType().keySet() ;
+ for (Iterator iter = keys.iterator(); iter.hasNext();) {
+ String key = (String) iter.next();
+ Object value = data.get(key);
+ setProperty(propertyPrefix + "." + key , value);
+ }
+ } else if (result.getClass().isArray()) {
+ if (isSeparatearrayresults()) {
+ Object array[] = (Object[]) result;
+ int size = 0 ;
+ for (int i = 0; i < array.length; i++) {
+ if(setProperty(propertyPrefix + "." + size , array[i])) {
+ size++;
}
- getProject().setNewProperty(resultproperty + ".length",
- Integer.toString(array.length));
- return ;
+ }
+ if(size > 0) {
+ setProperty(propertyPrefix + ".Length",
+ Integer.toString(size));
}
}
+ } else {
String delim = getDelimiter();
- if(delim != null) {
- StringTokenizer tokenizer = new
StringTokenizer(result.toString(),delim);
- int len = 0;
- for (; tokenizer.hasMoreTokens(); len++) {
- String token = tokenizer.nextToken();
- getProject().setNewProperty(resultproperty + "." + len,
- token);
+ if (delim != null) {
+ StringTokenizer tokenizer = new
StringTokenizer(result.toString(),
+ delim);
+ int size = 0;
+ for (; tokenizer.hasMoreTokens();) {
+ String token = tokenizer.nextToken();
+ if(setProperty(propertyPrefix + "." + size, token)) {
+ size++;
+ }
}
- getProject().setNewProperty(resultproperty + ".length",
- Integer.toString(len));
- } else
- getProject().setNewProperty(resultproperty,
result.toString());
+ if(size>0)
+ setProperty(propertyPrefix + ".Length",
+ Integer.toString(size));
+ } else {
+ setProperty(propertyPrefix, result.toString());
+ }
}
}
-
+
+ /**
+ * @param propertyPrefix
+ * @param value
+ */
+ protected boolean setProperty(String property, Object value) {
+ if(property != null ) {
+ if(value == null )
+ value="" ;
+ if (isEcho()) {
+ handleOutput(property + "=" + value.toString());
+ }
+ getProject().setNewProperty(property,value.toString());
+ return true ;
+ }
+ return false ;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]