use of javax.management.MBeanOperationInfo in project tomee by apache.
the class LocalJMXCommand method invoke.
private void invoke(final String value) {
if (!value.contains("(") || !value.contains(")")) {
streamManager.writeErr("method should follow the format: <methoName>(<arg1>,<arg2>,...)");
return;
}
int open = value.indexOf("(");
int close = value.lastIndexOf(")");
final String name = value.substring(0, open).trim();
final String rawArgs = value.substring(open + 1, close).trim();
final ObjectName on;
try {
on = new ObjectName(value.substring(close + 1).trim());
} catch (MalformedObjectNameException e) {
streamManager.writeErr(e);
return;
}
final MBeanServer server = LocalMBeanServer.get();
final String[] args;
if (rawArgs == null || rawArgs.isEmpty()) {
args = new String[0];
} else {
args = rawArgs.split(",");
}
try {
final MBeanInfo minfo = server.getMBeanInfo(on);
final MBeanOperationInfo[] methods = minfo.getOperations();
MBeanOperationInfo operation = null;
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(name)) {
operation = methods[i];
break;
}
}
if (operation == null) {
streamManager.writeErr("can't find operation '" + name + "'");
return;
}
final Object[] passedArgs = new Object[args.length];
final String[] passedArgTypes = new String[args.length];
for (int i = 0; i < passedArgs.length; i++) {
final String expected = operation.getSignature()[i].getType();
if (!String.class.getName().equals(expected)) {
passedArgs[i] = PropertyEditors.getValue(expected, args[i], Thread.currentThread().getContextClassLoader());
} else {
passedArgs[i] = args[i];
}
passedArgTypes[i] = expected;
}
streamManager.writeOut(stringify(server.invoke(on, name, passedArgs, passedArgTypes)));
} catch (Exception e) {
streamManager.writeErr(e);
return;
}
}
Aggregations