JolokiaMBeanServerUtil { public static MBeanServer getJolokiaMBeanServer() { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); MBeanServer jolokiaMBeanServer; try { jolokiaMBeanServer = (MBeanServer) server.getAttribute(createObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME), JOLOKIA_MBEAN_SERVER_ATTRIBUTE); } catch (InstanceNotFoundException exp) { jolokiaMBeanServer = registerJolokiaMBeanServerHolderMBean(server); } catch (JMException e) { throw new IllegalStateException("Internal: Cannot get JolokiaMBean server via JMX lookup: " + e,e); } return jolokiaMBeanServer; } private  JolokiaMBeanServerUtil(); static MBeanServer getJolokiaMBeanServer(); static ObjectInstance registerMBean(Object object, ObjectName name); static void unregisterMBean(ObjectName name); static final String JOLOKIA_MBEAN_SERVER_ATTRIBUTE; }
@Test public void checkNotRegistered() throws MalformedObjectNameException { MBeanServer jolokiaServer = JolokiaMBeanServerUtil.getJolokiaMBeanServer(); Assert.assertNotEquals(ManagementFactory.getPlatformMBeanServer(), jolokiaServer); for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) { Assert.assertNotEquals(server, jolokiaServer); } }