How to execute a method with JMX without JConsole?
I want to invoke methods through JMX from Java code. With the code below I can get the name of all methods of the MBean interface but I am not yet able to actually execute them. Something is still missing, could anybody please help me?
private static String connectJmx() {
StringBuilder sb = new StringBuilder();
JMXServiceURL serviceUrl;
JMXConnector jmxConnector = null;
try {
serviceUrl = new JMXServiceURL(URL);
jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
ObjectName objectName = ObjectNameProvider.getObjectName();
MBeanInfo info = mbeanConn.getMBeanInfo(objectName);
MBeanOperationInfo[] operations = info.getOperations();
for (int i = 0; i < operations.length; i++) {
sb.append(operations[i].getName()).append("\n");
}
}
catch (Exception e) {
LogManager.doLog(LOG, LOGLEVEL.INFO, "exception connection jmx", e);
} finally {
try {
if(jmxConnector != null){
jmxConnector.close();
}
} catch (IOException e) {
//
}
}
return sb.toString();
}
The for cycle above collects the names of the methods. I want something similar, that instead of collecting the names, actually executes them. Please do not recommend JConsole, it does not work for other reasons.