MonitorableRegistry { public static MonitorableRegistry getNamedInstance(String name) { MonitorableRegistry instance = NAMED_INSTANCES.get(name); if (instance == null) { instance = new MonitorableRegistry(); MonitorableRegistry existing = NAMED_INSTANCES.putIfAbsent(name, instance); if (existing != null) { return existing; } } return instance; }  synchronized void register(Monitorable<T> monitorable); @SuppressWarnings("unchecked") synchronized T registerOrReuse(Monitorable<T> monitorable); synchronized Collection<Monitorable<?>> getMonitorables(); static void clearDefaultRegistry(); static MonitorableRegistry getNamedInstance(String name); void addRegistryListener(MonitorableRegistryListener monitorableRegistryListener); void removeRegistryListener(MonitorableRegistryListener listener); static MonitorableRegistry DEFAULT_REGISTRY; }
@Test public void getNamedInstanceReturnsExistingIfPresent() { MonitorableRegistry registry1 = MonitorableRegistry.getNamedInstance("xxx"); MonitorableRegistry registry2 = MonitorableRegistry.getNamedInstance("xxx"); assertSame(registry1, registry2); }