代码之家  ›  专栏  ›  技术社区  ›  Toon

QuickFIXJ MBeanServerInvocationHandler。newProxyInstance参数类型错误

  •  1
  • Toon  · 技术社区  · 7 年前

    在为QFJ构建JMX客户端服务时,我在使用不同的MBean接口时遇到了错误。我需要调用ConnectorAdminBean中的方法,但它不能绑定到SessionAdminBean的方法。引发的错误:

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

    方法:

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

    这已确认有效:

    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);
    

    然而,当我尝试这样做时,它抛出了一个错误,即第三个参数是错误的:

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

    我已经查看了各自的接口,但没有看到任何差异。

    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();
        ...
    

    与之相比:

    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();
    }
    

    请说明接口ConnectorAdminBean无法绑定到类的原因<\T>。谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   Toon    7 年前

    通过将参数类与MBean代理类相匹配,即通过更改以下内容来解决此问题:

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

    ConnectorAdminMBean mBeanConnectorProxy = MBeanServerInvocationHandler.newProxyInstance(jmxConnectionInstance.getmBeanServerConnection(), mBeanConnector, ConnectorAdminMBean.class, true);
    
    推荐文章