@Test(expected=JmxRegistrationException.class) public void registerNameTwice() { final MockedJmxRegistry service; try { service = new MockedJmxRegistry(); assertRegisteredServices(service); service.register(new GoodService("Alpha")); } catch (Throwable t) { throw new RuntimeException(t); } service.register(new GoodService("Alpha")); }
@Override public ObjectName register(JmxManageable service) { final JmxObjectInfo info = service.getJmxObjectInfo(); validate(info); String serviceName = info.getObjectName(); if (!serviceName.matches("[\\w-]+")) { throw new JmxRegistrationException(service.getClass(), serviceName); } final ObjectName objectName; synchronized (INTERNAL_LOCK) { if (serviceToName.containsKey(service)) { throw new JmxRegistrationException("Already registered instance of " + service.getClass()); } objectName = getObjectName(serviceName, nameToService.keySet()); addService(objectName, service); if (started) { try { getMBeanServer().registerMBean(info.getInstance(), objectName); return objectName; } catch (Exception e) { removeService(objectName); throw new JmxRegistrationException(e); } } else { return objectName; } } }
JmxRegistryServiceImpl implements JmxRegistryService, JmxManageable, Service { @Override public ObjectName register(JmxManageable service) { final JmxObjectInfo info = service.getJmxObjectInfo(); validate(info); String serviceName = info.getObjectName(); if (!serviceName.matches("[\\w-]+")) { throw new JmxRegistrationException(service.getClass(), serviceName); } final ObjectName objectName; synchronized (INTERNAL_LOCK) { if (serviceToName.containsKey(service)) { throw new JmxRegistrationException("Already registered instance of " + service.getClass()); } objectName = getObjectName(serviceName, nameToService.keySet()); addService(objectName, service); if (started) { try { getMBeanServer().registerMBean(info.getInstance(), objectName); return objectName; } catch (Exception e) { removeService(objectName); throw new JmxRegistrationException(e); } } else { return objectName; } } } }
JmxRegistryServiceImpl implements JmxRegistryService, JmxManageable, Service { @Override public ObjectName register(JmxManageable service) { final JmxObjectInfo info = service.getJmxObjectInfo(); validate(info); String serviceName = info.getObjectName(); if (!serviceName.matches("[\\w-]+")) { throw new JmxRegistrationException(service.getClass(), serviceName); } final ObjectName objectName; synchronized (INTERNAL_LOCK) { if (serviceToName.containsKey(service)) { throw new JmxRegistrationException("Already registered instance of " + service.getClass()); } objectName = getObjectName(serviceName, nameToService.keySet()); addService(objectName, service); if (started) { try { getMBeanServer().registerMBean(info.getInstance(), objectName); return objectName; } catch (Exception e) { removeService(objectName); throw new JmxRegistrationException(e); } } else { return objectName; } } }  }
JmxRegistryServiceImpl implements JmxRegistryService, JmxManageable, Service { @Override public ObjectName register(JmxManageable service) { final JmxObjectInfo info = service.getJmxObjectInfo(); validate(info); String serviceName = info.getObjectName(); if (!serviceName.matches("[\\w-]+")) { throw new JmxRegistrationException(service.getClass(), serviceName); } final ObjectName objectName; synchronized (INTERNAL_LOCK) { if (serviceToName.containsKey(service)) { throw new JmxRegistrationException("Already registered instance of " + service.getClass()); } objectName = getObjectName(serviceName, nameToService.keySet()); addService(objectName, service); if (started) { try { getMBeanServer().registerMBean(info.getInstance(), objectName); return objectName; } catch (Exception e) { removeService(objectName); throw new JmxRegistrationException(e); } } else { return objectName; } } }  @Override ObjectName register(JmxManageable service); @Override void unregister(String objectNameString); @Override void unregister(ObjectName registeredObject); @Override void start(); @Override void stop(); @Override void crash(); @Override JmxObjectInfo getJmxObjectInfo(); }
JmxRegistryServiceImpl implements JmxRegistryService, JmxManageable, Service { @Override public ObjectName register(JmxManageable service) { final JmxObjectInfo info = service.getJmxObjectInfo(); validate(info); String serviceName = info.getObjectName(); if (!serviceName.matches("[\\w-]+")) { throw new JmxRegistrationException(service.getClass(), serviceName); } final ObjectName objectName; synchronized (INTERNAL_LOCK) { if (serviceToName.containsKey(service)) { throw new JmxRegistrationException("Already registered instance of " + service.getClass()); } objectName = getObjectName(serviceName, nameToService.keySet()); addService(objectName, service); if (started) { try { getMBeanServer().registerMBean(info.getInstance(), objectName); return objectName; } catch (Exception e) { removeService(objectName); throw new JmxRegistrationException(e); } } else { return objectName; } } }  @Override ObjectName register(JmxManageable service); @Override void unregister(String objectNameString); @Override void unregister(ObjectName registeredObject); @Override void start(); @Override void stop(); @Override void crash(); @Override JmxObjectInfo getJmxObjectInfo();  }