I have a object named EXOB
which has multiple routines. EXOB
is a Spring bean
and I want to execute the routine named routine1
which takes a String
parameter. I have written this code till now:
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
JMXServiceURL url = new JMXServiceURL("URL");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("com.example.package:service=EXOB");
Object Params[] = {"str"};
String Sig[] = {String.class.getName()};
mbsc.invoke(mbeanName,"routine1",Params,Sig);
jmxc.close();
I am using intellij
and it shows error at invoke()
method as cannot resolve symbol routine1
. Is the way in which I have written the code above wrong? How can I access a JMX Mbean
and invoke a function inside it?
I also wanted to know if the above approach to invoke a function inside a MBean is appropriate or if there is some better way to do it?
UPDATE: When I execute the above code nothing happens and the execution seems to get hanged while I am running it
Also when I add following to the above code:
Set<ObjectName> names = new TreeSet<ObjectName>(mbsc.queryNames(null, null));
for (ObjectName name : names) {
System.out.println("\tObjectName = " + name);
}
I get this as an output
ObjectName = com.example.package:service=EXOB
This is the object
name that I am passing in my code above when I getting mbeanName
. This EXOB has the routine called routine1
which I want to invoke