javajmxquickfixmbeansquickfixj

QuickFIXJ MBeanServerInvocationHandler.newProxyInstance wrong argument type


While building the JMX Client service for QFJ, I encountered errors when using different MBean interfaces. I need to invoke the methods in ConnectorAdminMBean but it cannot be bound to SessionAdminMBean's method. The error thrown:

newProxyInstance() in MBeanServerInvocationHandler cannot be applied to: 
interfaceClass: (Expected) java.lang.Class<T> | (Actual) ConnectorAdminMBean.class

The method:

public static <T> T newProxyInstance(MBeanServerConnection connection,
                                         ObjectName objectName,
                                         Class<T> interfaceClass,
                                         boolean notificationBroadcaster) {
        return JMX.newMBeanProxy(connection, objectName, interfaceClass, notificationBroadcaster);
    }

This has confirmed to work:

ObjectName mBeanBLBG = new ObjectName("org.quickfixj:type=Session,beginString=FIX.4.2,senderCompID=SCB,targetCompID=BLBG");
SessionAdminMBean mBeanBLBGProxy = MBeanServerInvocationHandler.newProxyInstance(jmxConnectionInstance.getmBeanServerConnection(), mBeanBLBG, SessionAdminMBean.class, true);

However when I tried to do this, it throws an error of 3rd argument being wrong:

ObjectName mBeanConnector = new ObjectName("org.quickfixj:type=Connector,role=Initiator,id=1");
SessionAdminMBean mBeanConnectorProxy = MBeanServerInvocationHandler.newProxyInstance(jmxConnectionInstance.getmBeanServerConnection(), mBeanConnector, ConnectorAdminMBean.class, true);

I have looked into the respective interfaces but fail to see any difference.

package org.quickfixj.jmx.mbean.session;
import java.io.IOException;
import javax.management.ObjectName;
import quickfix.SessionNotFound;
public interface SessionAdminMBean {
    String getBeginString();
    String getTargetCompID();
    String getTargetSubID();
    ...

Compared with:

package org.quickfixj.jmx.mbean.connector;
import java.io.IOException;
import javax.management.openmbean.TabularData;
public interface ConnectorAdminMBean {
    String getRole() throws IOException;
    void stop(boolean var1) throws IOException;
    void stop() throws IOException;
    TabularData getSessions() throws IOException;
    String getHostName() throws IOException;
    int getQueueSize();
}

Please advise on what could be the reason that interface ConnectorAdminMbean cannot be bound to Class<\T>. Thanks!


Solution

  • Issue was resolved by matching the argument class to the MBean proxy class, i.e. by changing:

    SessionAdminMBean mBeanConnectorProxy = MBeanServerInvocationHandler.newProxyInstance(jmxConnectionInstance.getmBeanServerConnection(), mBeanConnector, ConnectorAdminMBean.class, true);
    

    to

    ConnectorAdminMBean mBeanConnectorProxy = MBeanServerInvocationHandler.newProxyInstance(jmxConnectionInstance.getmBeanServerConnection(), mBeanConnector, ConnectorAdminMBean.class, true);