Clean up the APIMetricsRegistry
This is a clean up in the APIMetricsRegistry. It replaces snake case to camel case, and perform a better formatting of the code. Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
parent
2d97995229
commit
479a0769d1
@ -23,18 +23,19 @@ import com.yammer.metrics.core.Histogram.SampleType;
|
||||
*/
|
||||
|
||||
public class APIMetricsRegistry extends MetricsRegistry {
|
||||
Field field_metrics;
|
||||
Field field_clock;
|
||||
Field field_thread_pool;
|
||||
|
||||
Field fieldMetrics;
|
||||
Field fieldClock;
|
||||
Field fieldThreadPool;
|
||||
|
||||
public APIMetricsRegistry() {
|
||||
try {
|
||||
field_metrics = MetricsRegistry.class.getDeclaredField("metrics");
|
||||
field_metrics.setAccessible(true);
|
||||
field_clock = MetricsRegistry.class.getDeclaredField("clock");
|
||||
field_clock.setAccessible(true);
|
||||
field_thread_pool = MetricsRegistry.class.getDeclaredField("threadPools");
|
||||
field_thread_pool.setAccessible(true);
|
||||
fieldMetrics = MetricsRegistry.class.getDeclaredField("metrics");
|
||||
fieldMetrics.setAccessible(true);
|
||||
fieldClock = MetricsRegistry.class.getDeclaredField("clock");
|
||||
fieldClock.setAccessible(true);
|
||||
fieldThreadPool = MetricsRegistry.class
|
||||
.getDeclaredField("threadPools");
|
||||
fieldThreadPool.setAccessible(true);
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -43,192 +44,223 @@ public class APIMetricsRegistry extends MetricsRegistry {
|
||||
|
||||
public ThreadPools getThreadPools() {
|
||||
try {
|
||||
return (ThreadPools)field_thread_pool.get(this);
|
||||
return (ThreadPools) fieldThreadPool.get(this);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Clock getClock() {
|
||||
try {
|
||||
return (Clock)field_clock.get(this);
|
||||
return (Clock) fieldClock.get(this);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConcurrentMap<MetricName, Metric> get_metrics() {
|
||||
public ConcurrentMap<MetricName, Metric> getMetrics() {
|
||||
try {
|
||||
return (ConcurrentMap<MetricName, Metric>)field_metrics.get(this);
|
||||
return (ConcurrentMap<MetricName, Metric>) fieldMetrics.get(this);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Counter} and registers it under the given class and name.
|
||||
* Creates a new {@link Counter} and registers it under the given class and
|
||||
* name.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @return a new {@link Counter}
|
||||
*/
|
||||
public Counter newCounter(String url, Class<?> klass,
|
||||
String name) {
|
||||
public Counter newCounter(String url, Class<?> klass, String name) {
|
||||
return newCounter(url, klass, name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Counter} and registers it under the given class and name.
|
||||
* Creates a new {@link Counter} and registers it under the given class and
|
||||
* name.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param scope the scope of the metric
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param scope
|
||||
* the scope of the metric
|
||||
* @return a new {@link Counter}
|
||||
*/
|
||||
public Counter newCounter(String url, Class<?> klass,
|
||||
String name,
|
||||
String scope) {
|
||||
public Counter newCounter(String url, Class<?> klass, String name,
|
||||
String scope) {
|
||||
return newCounter(url, createName(klass, name, scope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Counter} and registers it under the given metric name.
|
||||
* Creates a new {@link Counter} and registers it under the given metric
|
||||
* name.
|
||||
*
|
||||
* @param metricName the name of the metric
|
||||
* @param metricName
|
||||
* the name of the metric
|
||||
* @return a new {@link Counter}
|
||||
*/
|
||||
public Counter newCounter(String url, MetricName metricName) {
|
||||
return getOrAdd(metricName, new APICounter(url));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new {@link Meter} and registers it under the given class and name.
|
||||
* Creates a new {@link Meter} and registers it under the given class and
|
||||
* name.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param eventType the plural name of the type of events the meter is measuring (e.g., {@code
|
||||
* "requests"})
|
||||
* @param unit the rate unit of the new meter
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param eventType
|
||||
* the plural name of the type of events the meter is measuring
|
||||
* (e.g., {@code "requests"})
|
||||
* @param unit
|
||||
* the rate unit of the new meter
|
||||
* @return a new {@link Meter}
|
||||
*/
|
||||
public Meter newMeter(String url, Class<?> klass,
|
||||
String name,
|
||||
String eventType,
|
||||
TimeUnit unit) {
|
||||
public Meter newMeter(String url, Class<?> klass, String name,
|
||||
String eventType, TimeUnit unit) {
|
||||
return newMeter(url, klass, name, null, eventType, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Meter} and registers it under the given class, name, and scope.
|
||||
* Creates a new {@link Meter} and registers it under the given class, name,
|
||||
* and scope.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param scope the scope of the metric
|
||||
* @param eventType the plural name of the type of events the meter is measuring (e.g., {@code
|
||||
* "requests"})
|
||||
* @param unit the rate unit of the new meter
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param scope
|
||||
* the scope of the metric
|
||||
* @param eventType
|
||||
* the plural name of the type of events the meter is measuring
|
||||
* (e.g., {@code "requests"})
|
||||
* @param unit
|
||||
* the rate unit of the new meter
|
||||
* @return a new {@link Meter}
|
||||
*/
|
||||
public Meter newMeter(String url,
|
||||
Class<?> klass,
|
||||
String name,
|
||||
String scope,
|
||||
String eventType,
|
||||
TimeUnit unit) {
|
||||
public Meter newMeter(String url, Class<?> klass, String name,
|
||||
String scope, String eventType, TimeUnit unit) {
|
||||
return newMeter(url, createName(klass, name, scope), eventType, unit);
|
||||
}
|
||||
|
||||
private ScheduledExecutorService newMeterTickThreadPool() {
|
||||
return getThreadPools().newScheduledThreadPool(2, "meter-tick");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Meter} and registers it under the given metric name.
|
||||
*
|
||||
* @param metricName the name of the metric
|
||||
* @param eventType the plural name of the type of events the meter is measuring (e.g., {@code
|
||||
* "requests"})
|
||||
* @param unit the rate unit of the new meter
|
||||
* @param metricName
|
||||
* the name of the metric
|
||||
* @param eventType
|
||||
* the plural name of the type of events the meter is measuring
|
||||
* (e.g., {@code "requests"})
|
||||
* @param unit
|
||||
* the rate unit of the new meter
|
||||
* @return a new {@link Meter}
|
||||
*/
|
||||
public Meter newMeter(String url, MetricName metricName,
|
||||
String eventType,
|
||||
TimeUnit unit) {
|
||||
final Metric existingMetric = get_metrics().get(metricName);
|
||||
public Meter newMeter(String url, MetricName metricName, String eventType,
|
||||
TimeUnit unit) {
|
||||
final Metric existingMetric = getMetrics().get(metricName);
|
||||
if (existingMetric != null) {
|
||||
return (Meter) existingMetric;
|
||||
}
|
||||
return getOrAdd(metricName, new APIMeter(url, newMeterTickThreadPool(), eventType, unit, getClock()));
|
||||
return getOrAdd(metricName, new APIMeter(url, newMeterTickThreadPool(),
|
||||
eventType, unit, getClock()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new {@link Histogram} and registers it under the given class and name.
|
||||
* Creates a new {@link Histogram} and registers it under the given class
|
||||
* and name.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param biased whether or not the histogram should be biased
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param biased
|
||||
* whether or not the histogram should be biased
|
||||
* @return a new {@link Histogram}
|
||||
*/
|
||||
public Histogram newHistogram(String url, Class<?> klass,
|
||||
String name,
|
||||
boolean biased) {
|
||||
public Histogram newHistogram(String url, Class<?> klass, String name,
|
||||
boolean biased) {
|
||||
return newHistogram(url, klass, name, null, biased);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Histogram} and registers it under the given class, name, and scope.
|
||||
* Creates a new {@link Histogram} and registers it under the given class,
|
||||
* name, and scope.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param scope the scope of the metric
|
||||
* @param biased whether or not the histogram should be biased
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param scope
|
||||
* the scope of the metric
|
||||
* @param biased
|
||||
* whether or not the histogram should be biased
|
||||
* @return a new {@link Histogram}
|
||||
*/
|
||||
public Histogram newHistogram(String url, Class<?> klass,
|
||||
String name,
|
||||
String scope,
|
||||
boolean biased) {
|
||||
public Histogram newHistogram(String url, Class<?> klass, String name,
|
||||
String scope, boolean biased) {
|
||||
return newHistogram(url, createName(klass, name, scope), biased);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new non-biased {@link Histogram} and registers it under the given class and name.
|
||||
* Creates a new non-biased {@link Histogram} and registers it under the
|
||||
* given class and name.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @return a new {@link Histogram}
|
||||
*/
|
||||
public Histogram newHistogram(String url, Class<?> klass,
|
||||
String name) {
|
||||
public Histogram newHistogram(String url, Class<?> klass, String name) {
|
||||
return newHistogram(url, klass, name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new non-biased {@link Histogram} and registers it under the given class, name, and
|
||||
* scope.
|
||||
* Creates a new non-biased {@link Histogram} and registers it under the
|
||||
* given class, name, and scope.
|
||||
*
|
||||
* @param klass the class which owns the metric
|
||||
* @param name the name of the metric
|
||||
* @param scope the scope of the metric
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param scope
|
||||
* the scope of the metric
|
||||
* @return a new {@link Histogram}
|
||||
*/
|
||||
public Histogram newHistogram(String url, Class<?> klass,
|
||||
String name,
|
||||
String scope) {
|
||||
public Histogram newHistogram(String url, Class<?> klass, String name,
|
||||
String scope) {
|
||||
return newHistogram(url, klass, name, scope, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Histogram} and registers it under the given metric name.
|
||||
* Creates a new {@link Histogram} and registers it under the given metric
|
||||
* name.
|
||||
*
|
||||
* @param metricName the name of the metric
|
||||
* @param biased whether or not the histogram should be biased
|
||||
* @param metricName
|
||||
* the name of the metric
|
||||
* @param biased
|
||||
* whether or not the histogram should be biased
|
||||
* @return a new {@link Histogram}
|
||||
*/
|
||||
public Histogram newHistogram(String url, MetricName metricName,
|
||||
boolean biased) {
|
||||
return getOrAdd(metricName,
|
||||
new APIHistogram(url, biased ? SampleType.BIASED : SampleType.UNIFORM));
|
||||
boolean biased) {
|
||||
return getOrAdd(metricName, new APIHistogram(url,
|
||||
biased ? SampleType.BIASED : SampleType.UNIFORM));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user