在为QFJ构建JMX客户端服务时,我在使用不同的MBean接口时遇到了错误。我需要调用ConnectorAdminMBean中的方法,但它不能绑定到SessionAdminMBean的方法。引发的错误:
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);
然而,当我尝试这样做时,它会抛出第3个参数错误的错误:
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();
}
请告知接口ConnectorAdminMbean无法绑定到Class&lt; \ T&gt;的原因。谢谢!
答案 0 :(得分:1)
通过将参数类与MBean代理类匹配来解决问题,即通过更改:
SessionAdminMBean mBeanConnectorProxy = MBeanServerInvocationHandler.newProxyInstance(jmxConnectionInstance.getmBeanServerConnection(), mBeanConnector, ConnectorAdminMBean.class, true);
到
ConnectorAdminMBean mBeanConnectorProxy = MBeanServerInvocationHandler.newProxyInstance(jmxConnectionInstance.getmBeanServerConnection(), mBeanConnector, ConnectorAdminMBean.class, true);