FileDocCategorySizeDatePackage
JMXAccessorQueryTask.javaAPI DocApache Tomcat 6.0.147638Fri Jul 20 04:20:32 BST 2007org.apache.catalina.ant.jmx

JMXAccessorQueryTask

public 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.
author
Peter Rossbach
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
since
5.5.10

Fields Summary
private boolean
attributebinding
private static final String
info
Descriptive information describing this implementation.
Constructors Summary
Methods Summary
protected voidbindAttributes(javax.management.MBeanServerConnection jmxServerConnection, java.lang.String resultproperty, java.lang.String pname, javax.management.ObjectName oname)

param
jmxServerConnection
param
resultproperty
param
pname
param
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.StringgetInfo()
Return descriptive information about this implementation and the corresponding version number, in the format <description>/<version>.


                        
       

        return (info);

    
public booleanisAttributebinding()

return
Returns the attributebinding.

        return attributebinding;
    
public java.lang.StringjmxExecute(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.

exception
Exception if an error occurs


        if (getName() == null) {
            throw new BuildException("Must specify a 'name'");
        }
        return jmxQuery(jmxServerConnection, getName());

    
protected java.lang.StringjmxQuery(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

param
jmxServerConnection
param
qry
return
The query result

        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 voidsetAttributebinding(boolean attributeBinding)

param
attributeBinding The attributebinding to set.

        this.attributebinding = attributeBinding;