com.codahale.metrics.SharedMetricRegistries Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metrics-core Show documentation
Show all versions of metrics-core Show documentation
Metrics is a Java library which gives you unparalleled insight into what your code does in
production. Metrics provides a powerful toolkit of ways to measure the behavior of critical
components in your production environment.
package com.codahale.metrics;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* A map of shared, named metric registries.
*/
public class SharedMetricRegistries {
private static final ConcurrentMap REGISTRIES =
new ConcurrentHashMap();
private SharedMetricRegistries() { /* singleton */ }
public static void clear() {
REGISTRIES.clear();
}
public static Set names() {
return REGISTRIES.keySet();
}
public static void remove(String key) {
REGISTRIES.remove(key);
}
public static MetricRegistry add(String name, MetricRegistry registry) {
return REGISTRIES.putIfAbsent(name, registry);
}
public static MetricRegistry getOrCreate(String name) {
final MetricRegistry existing = REGISTRIES.get(name);
if (existing == null) {
final MetricRegistry created = new MetricRegistry();
final MetricRegistry raced = add(name, created);
if (raced == null) {
return created;
}
return raced;
}
return existing;
}
}