Metric2Registry implements Metric2Set { public void registerAny(Metric2Set metrics) { for (Map.Entry<MetricName, Metric> entry : metrics.getMetrics().entrySet()) { registerNewMetrics(entry.getKey(), entry.getValue()); } } Metric2Registry();  Metric2Registry(MetricRegistry metricRegistry); @SuppressWarnings("unchecked") T register(MetricName name, T metric); void registerAll(Metric2Set metrics); void registerAny(Metric2Set metrics); void registerNewMetrics(MetricName name, Metric metric); Counter counter(MetricName name); Histogram histogram(MetricName name); Meter meter(MetricName name); Timer timer(MetricName name); boolean remove(MetricName name); Set<MetricName> getNames(); Map<MetricName, Gauge> getGauges(); Map<MetricName, Gauge> getGauges(Metric2Filter filter); Map<MetricName, Counter> getCounters(); Map<MetricName, Counter> getCounters(Metric2Filter filter); Map<MetricName, Histogram> getHistograms(); Map<MetricName, Histogram> getHistograms(Metric2Filter filter); Map<MetricName, Meter> getMeters(); Map<MetricName, Meter> getMeters(Metric2Filter filter); Map<MetricName, Timer> getTimers(); Map<MetricName, Timer> getTimers(Metric2Filter filter); @Override Map<MetricName, Metric> getMetrics(); void removeMatching(MetricFilter filter); void removeMatching(Metric2Filter filter); MetricRegistry getMetricRegistry();  }
@Test public void testRegisterAny() { Metric2Registry registry = new Metric2Registry(); final MetricName metric1 = MetricName.name("test").build(); final Gauge<Integer> gauge = getGauge(); final Metered metered = getMetered(); Metric2Set metricSet1 = new Metric2Set() { @Override public Map<MetricName, Metric> getMetrics() { Map<MetricName, Metric> map = new HashMap<MetricName, Metric>(1); map.put(metric1, gauge); return map; } }; Metric2Set metricSet2 = new Metric2Set() { @Override public Map<MetricName, Metric> getMetrics() { Map<MetricName, Metric> map = new HashMap<MetricName, Metric>(1); map.put(metric1, metered); return map; } }; registry.registerAny(metricSet1); registry.registerAny(metricSet2); assertEquals(1, registry.getGauges().entrySet().size()); assertEquals(0, registry.getMeters().entrySet().size()); Map.Entry<MetricName, Gauge> stagemonitorEntry = registry.getGauges().entrySet().iterator().next(); assertEquals("test", stagemonitorEntry.getKey().getName()); assertEquals(1, stagemonitorEntry.getValue().getValue()); }