JMXAccessorQueryTaskpublic class JMXAccessorQueryTask extends JMXAccessorTask Query for Mbeans.
- open no existing JSR 160 rmi jmx connection
- Get all Mbeans attributes
- Get only the Query Mbeans ObjectNames
- Show query result as Ant console log
- Bind query result as Ant properties
Query a list of Mbeans.
<jmxQuery
host="127.0.0.1"
port="9014"
name="Catalina:type=Manager,*
resultproperty="manager" />
with attribute attributebinding="true" you can get
all attributes also from result objects.
The poperty manager.lenght show the size of the result
and with manager.[0..lenght].name the
resulted ObjectNames are saved.
These tasks require Ant 1.6 or later interface. |
Fields Summary |
---|
private boolean | attributebinding | private static final String | infoDescriptive information describing this implementation. |
Methods Summary |
---|
protected void | bindAttributes(javax.management.MBeanServerConnection jmxServerConnection, java.lang.String resultproperty, java.lang.String pname, javax.management.ObjectName oname)
if (jmxServerConnection != null && resultproperty != null
&& pname != null && oname != null ) {
try {
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
String code = minfo.getClassName();
if ("org.apache.tomcat.util.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;
}
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);
}
} catch (Exception e) {
// Ignore
}
}
| public java.lang.String | getInfo()Return descriptive information about this implementation and the
corresponding version number, in the format
<description>/<version> .
return (info);
| public boolean | isAttributebinding()
return attributebinding;
| public java.lang.String | jmxExecute(javax.management.MBeanServerConnection jmxServerConnection)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.
if (getName() == null) {
throw new BuildException("Must specify a 'name'");
}
return jmxQuery(jmxServerConnection, getName());
| protected java.lang.String | jmxQuery(javax.management.MBeanServerConnection jmxServerConnection, java.lang.String qry)Call Mbean server for some mbeans with same domain, attributes.
with attributebindung=true you can save all attributes from all found objects
as your ant properties
String isError = null;
Set names = null;
String resultproperty = getResultproperty();
try {
names = jmxServerConnection.queryNames(new ObjectName(qry), null);
if (resultproperty != null) {
setProperty(resultproperty + ".Length",Integer.toString(names.size()));
}
} catch (Exception e) {
if (isEcho())
handleErrorOutput(e.getMessage());
return "Can't query mbeans " + qry;
}
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;
| public void | setAttributebinding(boolean attributeBinding)
this.attributebinding = attributeBinding;
|
|