1 17 18 19 package org.apache.catalina.ant.jmx; 20 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import javax.management.MBeanServerConnection ; 26 import javax.management.ObjectName ; 27 28 import org.apache.tools.ant.BuildException; 29 30 31 93 94 public class JMXAccessorInvokeTask extends JMXAccessorTask { 95 96 97 99 private String operation ; 100 private List args=new ArrayList (); 101 102 104 107 private static final String info = "org.apache.catalina.ant.JMXAccessorInvokeTask/1.0"; 108 109 114 public String getInfo() { 115 116 return (info); 117 118 } 119 120 122 125 public String getOperation() { 126 return operation; 127 } 128 131 public void setOperation(String operation) { 132 this.operation = operation; 133 } 134 135 public void addArg(Arg arg ) { 136 args.add(arg); 137 } 138 139 142 public List getArgs() { 143 return args; 144 } 145 148 public void setArgs(List args) { 149 this.args = args; 150 } 151 152 154 162 public String jmxExecute(MBeanServerConnection jmxServerConnection) 163 throws Exception { 164 165 if (getName() == null) { 166 throw new BuildException("Must specify a 'name'"); 167 } 168 if ((operation == null)) { 169 throw new BuildException( 170 "Must specify a 'operation' for call"); 171 } 172 return jmxInvoke(jmxServerConnection, getName()); 173 } 174 175 179 protected String jmxInvoke(MBeanServerConnection jmxServerConnection, String name) throws Exception { 180 Object result ; 181 if (args == null) { 182 result = jmxServerConnection.invoke(new ObjectName (name), 183 operation, null, null); 184 } else { 185 Object argsA[]=new Object [ args.size()]; 186 String sigA[]=new String [args.size()]; 187 for( int i=0; i<args.size(); i++ ) { 188 Arg arg=(Arg)args.get(i); 189 if( arg.type==null) { 190 arg.type="java.lang.String"; 191 sigA[i]=arg.getType(); 192 argsA[i]=arg.getValue(); 193 } else { 194 sigA[i]=arg.getType(); 195 argsA[i]=convertStringToType(arg.getValue(),arg.getType()); 196 } 197 } 198 result = jmxServerConnection.invoke(new ObjectName (name), operation, argsA, sigA); 199 } 200 if(result != null) { 201 echoResult(operation,result); 202 createProperty(result); 203 } 204 return null; 205 } 206 207 } 208 | Popular Tags |