@Test public void testGetOrCreateSimpleSensor() { try { MetricRegistryHolder holder = MetricRegistryHolder.getInstance(); assertEquals(holder.getOrCreateSimpleSensor("Sensor"), holder.getOrCreateSimpleSensor("Sensor")); } catch (Exception e) { fail("Exception should not have been thrwon!"); } }
@SuppressWarnings("unchecked") public <T extends Serializable> SimpleSensor<T> getOrCreateSimpleSensor(String metricName) { final Gauge sensor = metrics.gauge(metricName, SimpleSensor::new); if (sensor instanceof SimpleSensor) { return (SimpleSensor<T>) sensor; } throw new IllegalArgumentException(metricName + " is already used for a different type of metric"); }
MetricRegistryHolder { @SuppressWarnings("unchecked") public <T extends Serializable> SimpleSensor<T> getOrCreateSimpleSensor(String metricName) { final Gauge sensor = metrics.gauge(metricName, SimpleSensor::new); if (sensor instanceof SimpleSensor) { return (SimpleSensor<T>) sensor; } throw new IllegalArgumentException(metricName + " is already used for a different type of metric"); } }
MetricRegistryHolder { @SuppressWarnings("unchecked") public <T extends Serializable> SimpleSensor<T> getOrCreateSimpleSensor(String metricName) { final Gauge sensor = metrics.gauge(metricName, SimpleSensor::new); if (sensor instanceof SimpleSensor) { return (SimpleSensor<T>) sensor; } throw new IllegalArgumentException(metricName + " is already used for a different type of metric"); } private  MetricRegistryHolder(); }
MetricRegistryHolder { @SuppressWarnings("unchecked") public <T extends Serializable> SimpleSensor<T> getOrCreateSimpleSensor(String metricName) { final Gauge sensor = metrics.gauge(metricName, SimpleSensor::new); if (sensor instanceof SimpleSensor) { return (SimpleSensor<T>) sensor; } throw new IllegalArgumentException(metricName + " is already used for a different type of metric"); } private  MetricRegistryHolder(); static MetricRegistryHolder getInstance(); MetricRegistry getMetrics(); void setMetrics(MetricRegistry metricRegistry); @SuppressWarnings("unchecked") SimpleSensor<T> getOrCreateSimpleSensor(String metricName); Histogram getOrCreateHistogram(String metricName); }
MetricRegistryHolder { @SuppressWarnings("unchecked") public <T extends Serializable> SimpleSensor<T> getOrCreateSimpleSensor(String metricName) { final Gauge sensor = metrics.gauge(metricName, SimpleSensor::new); if (sensor instanceof SimpleSensor) { return (SimpleSensor<T>) sensor; } throw new IllegalArgumentException(metricName + " is already used for a different type of metric"); } private  MetricRegistryHolder(); static MetricRegistryHolder getInstance(); MetricRegistry getMetrics(); void setMetrics(MetricRegistry metricRegistry); @SuppressWarnings("unchecked") SimpleSensor<T> getOrCreateSimpleSensor(String metricName); Histogram getOrCreateHistogram(String metricName);  }