Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmx client throwing InstanceNotFoundException

I have a Jmx Client that i use to test a jmx bean I've written. Here's 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 it's dependencies are present in a library in IntelliJ.

My jmx beans are:

    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 running, the client, i get an exception when trying to invoke 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 do not understand why jmx seems to be able to get the bean, but not the actual instance of the class. I am guessing it's sort of a classpath issue, but couldn't find it. As a side not, when testing with JConsole, it works fine.

Thanks

like image 461
sebi Avatar asked Mar 12 '13 10:03

sebi


1 Answers

It looks like the object name used to register the MBean differs from the object name you use when trying to retrieve the managed bean.

Try to check the object name in JConsole.

like image 66
JB- Avatar answered Sep 19 '22 17:09

JB-