MetricsSystemImpl extends MetricsSystem implements MetricsSource { @Override public synchronized void unregisterSource(String name) { if (sources.containsKey(name)) { sources.get(name).stop(); sources.remove(name); } if (allSources.containsKey(name)) { allSources.remove(name); } if (namedCallbacks.containsKey(name)) { namedCallbacks.remove(name); } } MetricsSystemImpl(String prefix);  MetricsSystemImpl(); @Override synchronized MetricsSystem init(String prefix); @Override synchronized void start(); @Override synchronized void stop(); @Override synchronized T register(String name, String desc, T source); @Override synchronized void unregisterSource(String name); @Override synchronized T register(final String name, final String description, final T sink); @Override synchronized void register(final Callback callback); @Override synchronized void startMetricsMBeans(); @Override synchronized void stopMetricsMBeans(); @Override synchronized String currentConfig(); @Override void publishMetricsNow(); @Override synchronized void getMetrics(MetricsCollector builder, boolean all); @Override synchronized boolean shutdown(); MetricsSource getSource(String name);  }
@Test public void testUnregisterSource() { MetricsSystem ms = new MetricsSystemImpl(); TestSource ts1 = new TestSource("ts1"); TestSource ts2 = new TestSource("ts2"); ms.register("ts1", "", ts1); ms.register("ts2", "", ts2); MetricsSource s1 = ms.getSource("ts1"); assertNotNull(s1); ms.unregisterSource("ts1"); s1 = ms.getSource("ts1"); assertNull(s1); MetricsSource s2 = ms.getSource("ts2"); assertNotNull(s2); ms.shutdown(); }