@Test(expected = IllegalArgumentException.class) public void testDuplicateMetricNameEndsWithIllegalArgumentException() { Metric2Registry registry = new Metric2Registry(); MetricName metric1 = MetricName.name("test").build(); registry.register(metric1, getGauge()); registry.register(metric1, getMetered()); }
@SuppressWarnings("unchecked") public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException { if (metric instanceof MetricSet) { throw new IllegalArgumentException("This metrics registry is not compatible with MetricSets. Use a Metric2Set instead."); } else { final Metric existing = metrics.putIfAbsent(name, metric); if (existing != null) { throw new IllegalArgumentException("A metric named " + name + " already exists"); } else { metricRegistry.register(name.toGraphiteName(), metric); } } return metric; }
Metric2Registry implements Metric2Set { @SuppressWarnings("unchecked") public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException { if (metric instanceof MetricSet) { throw new IllegalArgumentException("This metrics registry is not compatible with MetricSets. Use a Metric2Set instead."); } else { final Metric existing = metrics.putIfAbsent(name, metric); if (existing != null) { throw new IllegalArgumentException("A metric named " + name + " already exists"); } else { metricRegistry.register(name.toGraphiteName(), metric); } } return metric; } }
Metric2Registry implements Metric2Set { @SuppressWarnings("unchecked") public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException { if (metric instanceof MetricSet) { throw new IllegalArgumentException("This metrics registry is not compatible with MetricSets. Use a Metric2Set instead."); } else { final Metric existing = metrics.putIfAbsent(name, metric); if (existing != null) { throw new IllegalArgumentException("A metric named " + name + " already exists"); } else { metricRegistry.register(name.toGraphiteName(), metric); } } return metric; } Metric2Registry();  Metric2Registry(MetricRegistry metricRegistry); }
Metric2Registry implements Metric2Set { @SuppressWarnings("unchecked") public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException { if (metric instanceof MetricSet) { throw new IllegalArgumentException("This metrics registry is not compatible with MetricSets. Use a Metric2Set instead."); } else { final Metric existing = metrics.putIfAbsent(name, metric); if (existing != null) { throw new IllegalArgumentException("A metric named " + name + " already exists"); } else { metricRegistry.register(name.toGraphiteName(), metric); } } return metric; } 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(); }
Metric2Registry implements Metric2Set { @SuppressWarnings("unchecked") public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException { if (metric instanceof MetricSet) { throw new IllegalArgumentException("This metrics registry is not compatible with MetricSets. Use a Metric2Set instead."); } else { final Metric existing = metrics.putIfAbsent(name, metric); if (existing != null) { throw new IllegalArgumentException("A metric named " + name + " already exists"); } else { metricRegistry.register(name.toGraphiteName(), metric); } } return metric; } 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();  }