It seems that the fact that my class is an inner class is causing the issue, that’s my hunch – but basically it’s otherwise the usual pattern:
public class UserProvisionerProfiler implements UserProvisionerProfilerMBean {
@Override
public int getTotalNumberOfUsers() {
return activeClients.size();
}
}
And the interface (nested in a larger class):
public interface UserProvisionerProfilerMBean {
public int getTotalNumberOfUsers();
}
Registered in the code:
UserProvisionerProfiler userProvisionerProfiler = new UserProvisionerProfiler();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName(userProvisionerProfiler.getClass().getPackage().getName() + ":type=" + userProvisionerProfiler.getClass().getName());
mbs.registerMBean(userProvisionerProfiler, name);
And the error:
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)
I’ve had little success in finding a stricter definition of a compliant MBean short of reading the JMX spec or code, so I’m wondering if I can salvage the inner class or if I have to separate it out, or if there is something else I’m missing.
According to JMX specification a standard MBean must consist of two parts:
Thanks to those restrictions a static inner class can be an MBean implementation if and only if the MBean interface is also a static inner class of the same containing class.