I have a Jmx client that I use to test the jmx bean that I wrote. Here is the code for the client:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("com.spmsoftware.processing.ping:type=ProcessingPing"); ProcessingPing mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, ProcessingPing.class, true); System.out.println("\nResult = " + mbeanProxy.ping(346, 0).getResultCode()); jmxc.close();
ProcessingPing and all its dependencies are present in the library in IntelliJ.
My jmx beans:
public interface ProcessingPing { public PingResult ping(Integer environmentId, Integer timeout); }
and
@Service("ProcessingPing") @ManagedResource(description = "") public class ProcessingPingImpl implements ProcessingPing { private static final Integer DEFAULT_TIMEOUT = 5000; @Autowired private PingProcessService pingProcessService; @Override @ManagedOperation(description = "") public PingResult ping(Integer environmentId, Integer timeout) { return pingProcessService.run(environmentId, timeout); } }
When the client starts, I get an exception when I try to call the ping method:
Caused by: javax.management.InstanceNotFoundException: com.spmsoftware.processing.ping:type=ProcessingPing at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getClassLoaderFor(DefaultMBeanServerInterceptor.java:1444) at com.sun.jmx.mbeanserver.JmxMBeanServer.getClassLoaderFor(JmxMBeanServer.java:1308) at com.sun.enterprise.v3.admin.DynamicInterceptor.getClassLoaderFor(DynamicInterceptor.java:907) at javax.management.remote.rmi.RMIConnectionImpl$4.run(RMIConnectionImpl.java:1346) at java.security.AccessController.doPrivileged(Native Method) at javax.management.remote.rmi.RMIConnectionImpl.getClassLoaderFor(RMIConnectionImpl.java:1342) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:795) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) at sun.rmi.transport.Transport$1.run(Transport.java:177) at sun.rmi.transport.Transport$1.run(Transport.java:174) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:173) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160) at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source) at javax.management.remote.rmi.RMIConnectionImpl_Stub.invoke(Unknown Source) at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.invoke(RMIConnector.java:1017) Disconnected from the target VM, address: '127.0.0.1:56621', transport: 'socket' at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:305) ... 2 more
I don't understand why jmx seems to be able to get a bean, but not an actual instance of the class. I assume this is a class question, but could not find it. As a side, when testing with JConsole it works fine.
thanks
source share