@Test public void unregisterSingletonInstance() throws Exception { ServiceStub service = new ServiceStub(); context.checking(new Expectations() {{ oneOf(mBeanServer).unregisterMBean(with(objectname(domain + ":type=ServiceStub,annotation=BasicService"))); }}); BasicService basicServiceAnnotation = createBasicServiceAnnotation(); Key<?> key = Key.of(ServiceStub.class, basicServiceAnnotation); jmxRegistry.unregisterSingleton(key, service); }
public void unregisterSingleton(@NotNull Key<?> key, Object singletonInstance) { if (isMBean(singletonInstance.getClass())) { try { String name = createNameForKey(key); ObjectName objectName = new ObjectName(name); mbs.unregisterMBean(objectName); registeredObjectNames.remove(objectName); } catch (ReflectiveOperationException | JMException e) { String msg = format("Error during attempt to unregister MBean for instance with key %s.", key.toString()); logger.error(msg, e); } } }
JmxRegistry implements JmxRegistryMXBean { public void unregisterSingleton(@NotNull Key<?> key, Object singletonInstance) { if (isMBean(singletonInstance.getClass())) { try { String name = createNameForKey(key); ObjectName objectName = new ObjectName(name); mbs.unregisterMBean(objectName); registeredObjectNames.remove(objectName); } catch (ReflectiveOperationException | JMException e) { String msg = format("Error during attempt to unregister MBean for instance with key %s.", key.toString()); logger.error(msg, e); } } } }
JmxRegistry implements JmxRegistryMXBean { public void unregisterSingleton(@NotNull Key<?> key, Object singletonInstance) { if (isMBean(singletonInstance.getClass())) { try { String name = createNameForKey(key); ObjectName objectName = new ObjectName(name); mbs.unregisterMBean(objectName); registeredObjectNames.remove(objectName); } catch (ReflectiveOperationException | JMException e) { String msg = format("Error during attempt to unregister MBean for instance with key %s.", key.toString()); logger.error(msg, e); } } } private  JmxRegistry(@NotNull MBeanServer mbs,
			DynamicMBeanFactory mbeanFactory,
			Map<Key<?>, String> keyToObjectNames,
			Map<Type, JmxCustomTypeAdapter<?>> customTypes); }
JmxRegistry implements JmxRegistryMXBean { public void unregisterSingleton(@NotNull Key<?> key, Object singletonInstance) { if (isMBean(singletonInstance.getClass())) { try { String name = createNameForKey(key); ObjectName objectName = new ObjectName(name); mbs.unregisterMBean(objectName); registeredObjectNames.remove(objectName); } catch (ReflectiveOperationException | JMException e) { String msg = format("Error during attempt to unregister MBean for instance with key %s.", key.toString()); logger.error(msg, e); } } } private  JmxRegistry(@NotNull MBeanServer mbs,
			DynamicMBeanFactory mbeanFactory,
			Map<Key<?>, String> keyToObjectNames,
			Map<Type, JmxCustomTypeAdapter<?>> customTypes); static JmxRegistry create(MBeanServer mbs, DynamicMBeanFactory mbeanFactory); static JmxRegistry create(MBeanServer mbs,
			DynamicMBeanFactory mbeanFactory,
			Map<Key<?>, String> keyToObjectNames,
			Map<Type, JmxCustomTypeAdapter<?>> customTypes); JmxRegistry withScopes(boolean withScopes); void addWorkerPoolKey(WorkerPool workerPool, Key<?> workerPoolKey); void registerSingleton(@NotNull Key<?> key, @NotNull Object singletonInstance, @NotNull JmxBeanSettings settings); void unregisterSingleton(@NotNull Key<?> key, Object singletonInstance); void registerWorkers(@NotNull WorkerPool pool, Key<?> key, @NotNull List<?> poolInstances, JmxBeanSettings settings); void unregisterWorkers(WorkerPool pool, @NotNull Key<?> key, List<?> poolInstances); void unregisterAll(); @Override int getRegisteredSingletons(); @Override int getRegisteredPools(); @Override int getTotallyRegisteredMBeans(); @Override String getRefreshPeriod(); @Override void setRefreshPeriod(String refreshPeriod); @Override int getMaxRefreshesPerOneCycle(); @Override void setMaxRefreshesPerOneCycle(int maxRefreshesPerOneCycle); @Override String[] getRefreshStats(); }
JmxRegistry implements JmxRegistryMXBean { public void unregisterSingleton(@NotNull Key<?> key, Object singletonInstance) { if (isMBean(singletonInstance.getClass())) { try { String name = createNameForKey(key); ObjectName objectName = new ObjectName(name); mbs.unregisterMBean(objectName); registeredObjectNames.remove(objectName); } catch (ReflectiveOperationException | JMException e) { String msg = format("Error during attempt to unregister MBean for instance with key %s.", key.toString()); logger.error(msg, e); } } } private  JmxRegistry(@NotNull MBeanServer mbs,
			DynamicMBeanFactory mbeanFactory,
			Map<Key<?>, String> keyToObjectNames,
			Map<Type, JmxCustomTypeAdapter<?>> customTypes); static JmxRegistry create(MBeanServer mbs, DynamicMBeanFactory mbeanFactory); static JmxRegistry create(MBeanServer mbs,
			DynamicMBeanFactory mbeanFactory,
			Map<Key<?>, String> keyToObjectNames,
			Map<Type, JmxCustomTypeAdapter<?>> customTypes); JmxRegistry withScopes(boolean withScopes); void addWorkerPoolKey(WorkerPool workerPool, Key<?> workerPoolKey); void registerSingleton(@NotNull Key<?> key, @NotNull Object singletonInstance, @NotNull JmxBeanSettings settings); void unregisterSingleton(@NotNull Key<?> key, Object singletonInstance); void registerWorkers(@NotNull WorkerPool pool, Key<?> key, @NotNull List<?> poolInstances, JmxBeanSettings settings); void unregisterWorkers(WorkerPool pool, @NotNull Key<?> key, List<?> poolInstances); void unregisterAll(); @Override int getRegisteredSingletons(); @Override int getRegisteredPools(); @Override int getTotallyRegisteredMBeans(); @Override String getRefreshPeriod(); @Override void setRefreshPeriod(String refreshPeriod); @Override int getMaxRefreshesPerOneCycle(); @Override void setMaxRefreshesPerOneCycle(int maxRefreshesPerOneCycle); @Override String[] getRefreshStats();  }