本文整理汇总了Java中com.codahale.metrics.MetricRegistryListener类的典型用法代码示例。如果您正苦于以下问题:Java MetricRegistryListener类的具体用法?Java MetricRegistryListener怎么用?Java MetricRegistryListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MetricRegistryListener类属于com.codahale.metrics包,在下文中一共展示了MetricRegistryListener类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyListenerOfAddedMetric
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
private void notifyListenerOfAddedMetric(
final MetricRegistryListener listener, final Metric metric, final String name
) {
if(metric instanceof Gauge) {
listener.onGaugeAdded(name, (Gauge<?>) metric);
} else if(metric instanceof Counter) {
listener.onCounterAdded(name, (Counter) metric);
} else if(metric instanceof Histogram) {
listener.onHistogramAdded(name, (Histogram) metric);
} else if(metric instanceof Meter) {
listener.onMeterAdded(name, (Meter) metric);
} else if(metric instanceof Timer) {
listener.onTimerAdded(name, (Timer) metric);
} else {
throw new IllegalArgumentException("Unsupported metric type: " + metric.getClass());
}
}
示例2: notifyListenerOfRemovedMetric
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
private void notifyListenerOfRemovedMetric(
final String name, final Metric metric, final MetricRegistryListener listener
) {
if(metric instanceof Gauge) {
listener.onGaugeRemoved(name);
} else if(metric instanceof Counter) {
listener.onCounterRemoved(name);
} else if(metric instanceof Histogram) {
listener.onHistogramRemoved(name);
} else if(metric instanceof Meter) {
listener.onMeterRemoved(name);
} else if(metric instanceof Timer) {
listener.onTimerRemoved(name);
} else {
throw new IllegalArgumentException("Unsupported metric type: " + metric.getClass());
}
}
示例3: testWrappingDropwizardMetrics
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
@Test
public void testWrappingDropwizardMetrics() {
Metric2Registry registry = new Metric2Registry();
MetricRegistryListener listener = Mockito.mock(MetricRegistryListener.class);
registry.getMetricRegistry().addListener(listener);
registry.register(MetricName.name("test").build(), new Gauge<Integer>() {
@Override
public Integer getValue() {
return 1;
}
});
// Verify the underlying Dropwizard listener was called
Mockito.verify(listener).onGaugeAdded(Mockito.eq("test"), Mockito.<Gauge>any());
// Should be able to read the gauge from either registry
Map.Entry<MetricName, Gauge> stagemonitorEntry = registry.getGauges().entrySet().iterator().next();
Map.Entry<String, Gauge> dropwizardEntry = registry.getMetricRegistry().getGauges().entrySet().iterator().next();
assertEquals("test", stagemonitorEntry.getKey().getName());
assertEquals(1,
stagemonitorEntry.getValue().getValue());
assertEquals("test", dropwizardEntry.getKey());
assertEquals(1,
dropwizardEntry.getValue().getValue());
// Unregister should notify Dropwizard listeners
registry.remove(MetricName.name("test").build());
Mockito.verify(listener).onGaugeRemoved(Mockito.eq("test"));
assertEquals(0, registry.getGauges().size());
assertEquals(0, registry.getMetricRegistry().getGauges().size());
}
示例4: CustomMetricRegistry
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
/**
* Creates a new {@link CustomMetricRegistry}.
*/
public CustomMetricRegistry() {
this.metrics = buildMap();
this.listeners = new CopyOnWriteArrayList<MetricRegistryListener>();
}
示例5: onMetricAdded
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
private void onMetricAdded(final String name, final Metric metric) {
for(final MetricRegistryListener listener : listeners) {
notifyListenerOfAddedMetric(listener, metric, name);
}
}
示例6: onMetricRemoved
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
private void onMetricRemoved(final String name, final Metric metric) {
for(final MetricRegistryListener listener : listeners) {
notifyListenerOfRemovedMetric(name, metric, listener);
}
}
示例7: removeListener
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
@Override
public void removeListener(MetricRegistryListener listener) {
throw new UnsupportedOperationException();
}
示例8: addListener
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
@Override
public void addListener(MetricRegistryListener listener) {
throw new UnsupportedOperationException();
}
示例9: addListener
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
/**
* Adds a {@link MetricRegistryListener} to a collection of listeners that will be notified on
* metric creation. Listeners will be notified in the order in which they are added.
* <p>
* <b>N.B.:</b> The listener will be notified of all existing metrics when it first registers.
*
* @param listener the listener that will be notified
*/
public final void addListener(final MetricRegistryListener listener) {
listeners.add(listener);
for(Map.Entry<String, Metric> entry : metrics.entrySet()) {
notifyListenerOfAddedMetric(listener, entry.getValue(), entry.getKey());
}
}
示例10: removeListener
import com.codahale.metrics.MetricRegistryListener; //导入依赖的package包/类
/**
* Removes a {@link MetricRegistryListener} from this registry's collection of listeners.
*
* @param listener the listener that will be removed
*/
public final void removeListener(final MetricRegistryListener listener) {
listeners.remove(listener);
}