2
看來,事實證明我的階級是一個內部類原因造成的問題,這是我的預感 - 但基本上它,否則通常的模式:爲什麼這個內部類可能是一個不兼容的MBean?
public class UserProvisionerProfiler implements UserProvisionerProfilerMBean {
@Override
public int getTotalNumberOfUsers() {
return activeClients.size();
}
}
和接口(嵌套在一個更大的類):
public interface UserProvisionerProfilerMBean {
public int getTotalNumberOfUsers();
}
註冊代碼:
UserProvisionerProfiler userProvisionerProfiler = new UserProvisionerProfiler();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName(userProvisionerProfiler.getClass().getPackage().getName() + ":type=" + userProvisionerProfiler.getClass().getName());
mbs.registerMBean(userProvisionerProfiler, name);
和錯誤:
1356 [1;31mERROR[39m [main], UserProvisioner ; Unhandled exception caught in main()
javax.management.NotCompliantMBeanException: MBean class UserProvisioner$UserProvisionerProfiler does not implement DynamicMBean, and neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class UserProvisioner$UserProvisionerProfiler is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: UserProvisioner$UserProvisionerProfiler: Class UserProvisioner$UserProvisionerProfiler is not a JMX compliant MXBean)
at com.sun.jmx.mbeanserver.Introspector.checkCompliance(Introspector.java:171)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:317)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:512)
UserProvisioner.registerThisAsMBean(UserProvisioner.java:734)
UserProvisioner.start(UserProvisioner.java:797)
UserProvisioner.main(UserProvisioner.java:844)
我在尋找JMX規範或代碼短的MBean更嚴格的定義方面一直沒有取得成功,所以我想知道是否可以挽救內部類或者如果必須將它分離出來,或者如果還有其他東西我錯過了。
你的內部類是靜態的嗎?如果不是,沒有外部類的實例就不能構造內部類。這可能構成違規行爲。 –