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

JMXAccessorInvokeTask

public class JMXAccessorInvokeTask extends JMXAccessorTask
Access JMX JSR 160 MBeans Server.
  • open more then one JSR 160 rmi connection
  • Get/Set Mbeans attributes
  • Call Mbean Operation with arguments
  • Argument values can be converted from string to int,long,float,double,boolean,ObjectName or InetAddress
  • Query Mbeans
  • Show Get, Call, Query result at Ant console log
  • Bind Get, Call, Query result at Ant properties
Examples:
  • Get a session attribute hello from session with ref ${sessionid.0} form app Catalina:type=Manager,path=/ClusterTest,host=localhost
    <jmx:invoke
    name="Catalina:type=Manager,path=/ClusterTest,host=localhost"
    operation="getSessionAttribute"
    resultproperty="hello">
    <arg value="${sessionid.0}"/>
    <arg value="Hello"/>
    </jmx:invoke>
    
  • Create new AccessLogger at localhost <jmx:invoke name="Catalina:type=MBeanFactory" operation="createAcccesLoggerValve" resultproperty="acccesLoggerObjectName" > <arg value="Catalina:type=Host,host=localhost"/> </jmx:invoke>
  • Remove existing AccessLogger at localhost <jmx:invoke name="Catalina:type=MBeanFactory" operation="removeValve" > <arg value="Catalina:type=Valve,name=AccessLogValve,host=localhost"/> </jmx:invoke>

First call to a remote MBeanserver save the JMXConnection a referenz jmx.server

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 String
operation
private List
args
private static final String
info
Descriptive information describing this implementation.
Constructors Summary
Methods Summary
public voidaddArg(Arg arg)

        args.add(arg);
    
public java.util.ListgetArgs()

return
Returns the args.

        return args;
    
public java.lang.StringgetInfo()
Return descriptive information about this implementation and the corresponding version number, in the format <description>/<version>.


                        
       

        return (info);

    
public java.lang.StringgetOperation()

return
Returns the operation.

        return operation;
    
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
BuildException if an error occurs


        if (getName() == null) {
            throw new BuildException("Must specify a 'name'");
        }
        if ((operation == null)) {
            throw new BuildException(
                    "Must specify a 'operation' for call");
        }
        return  jmxInvoke(jmxServerConnection, getName());
     
protected java.lang.StringjmxInvoke(javax.management.MBeanServerConnection jmxServerConnection, java.lang.String name)

param
jmxServerConnection
throws
Exception

        Object result ;
        if (args == null) {
             result = jmxServerConnection.invoke(new ObjectName(name),
                    operation, null, null);
        } else {
            Object argsA[]=new Object[ args.size()];
            String sigA[]=new String[args.size()];
            for( int i=0; i<args.size(); i++ ) {
                Arg arg=(Arg)args.get(i);
                if( arg.type==null) {
                    arg.type="java.lang.String";
                    sigA[i]=arg.getType();
                    argsA[i]=arg.getValue();
                } else {
                    sigA[i]=arg.getType();
                    argsA[i]=convertStringToType(arg.getValue(),arg.getType());
                }                
            }
            result = jmxServerConnection.invoke(new ObjectName(name), operation, argsA, sigA);
        }
        if(result != null) {
            echoResult(operation,result);
            createProperty(result);
        }
        return null;
    
public voidsetArgs(java.util.List args)

param
args The args to set.

        this.args = args;
    
public voidsetOperation(java.lang.String operation)

param
operation The operation to set.

        this.operation = operation;