Package org.xbib.metrics.common
Class MetricRegistry
- java.lang.Object
-
- org.xbib.metrics.common.MetricRegistry
-
- All Implemented Interfaces:
org.xbib.metrics.api.Metric,org.xbib.metrics.api.MetricSet
public class MetricRegistry extends java.lang.Object implements org.xbib.metrics.api.MetricSetA registry of metric instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMetricRegistry.ListenerListeners for events from the registry.
-
Constructor Summary
Constructors Modifier Constructor Description MetricRegistry()Creates a newMetricRegistry.protectedMetricRegistry(java.util.concurrent.ConcurrentMap<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Metric> metricsMap)Creates aMetricRegistrywith a customConcurrentMapimplementation for use inside the registry.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(MetricRegistry.Listener listener)Adds aMetricRegistry.Listenerto a collection of listeners that will be notified on metric creation.CountMetriccounter(java.lang.String name)CountMetriccounter(org.xbib.metrics.api.MetricName name)Return theCountMetricregistered under this name; or create and register a newCountMetricif none is registered.java.util.SortedMap<org.xbib.metrics.api.MetricName,CountMetric>getCounters()Returns a map of all the counters in the registry and their names.java.util.SortedMap<org.xbib.metrics.api.MetricName,CountMetric>getCounters(org.xbib.metrics.api.MetricFilter filter)Returns a map of all the counters in the registry and their names which match the given filter.java.util.SortedMap<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Gauge>getGauges()Returns a map of all the gauges in the registry and their names.java.util.SortedMap<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Gauge>getGauges(org.xbib.metrics.api.MetricFilter filter)Returns a map of all the gauges in the registry and their names which match the given filter.java.util.SortedMap<org.xbib.metrics.api.MetricName,Histogram>getHistograms()Returns a map of all the histograms in the registry and their names.java.util.SortedMap<org.xbib.metrics.api.MetricName,Histogram>getHistograms(org.xbib.metrics.api.MetricFilter filter)Returns a map of all the histograms in the registry and their names which match the given filter.java.util.SortedMap<org.xbib.metrics.api.MetricName,Meter>getMeters()Returns a map of all the meters in the registry and their names.java.util.SortedMap<org.xbib.metrics.api.MetricName,Meter>getMeters(org.xbib.metrics.api.MetricFilter filter)Returns a map of all the meters in the registry and their names which match the given filter.java.util.Map<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Metric>getMetrics()java.util.SortedSet<org.xbib.metrics.api.MetricName>getNames()Returns a set of the names of all the metrics in the registry.java.util.SortedMap<org.xbib.metrics.api.MetricName,Sampler>getTimers()Returns a map of all the timers in the registry and their names.java.util.SortedMap<org.xbib.metrics.api.MetricName,Sampler>getTimers(org.xbib.metrics.api.MetricFilter filter)Returns a map of all the timers in the registry and their names which match the given filter.Histogramhistogram(java.lang.String name)Histogramhistogram(org.xbib.metrics.api.MetricName name)Metermeter(java.lang.String name)Metermeter(org.xbib.metrics.api.MetricName name)static org.xbib.metrics.api.MetricNamename(java.lang.Class<?> klass, java.lang.String... names)static org.xbib.metrics.api.MetricNamename(java.lang.String name, java.lang.String... names)Shorthand method for backwards compatibility in creating metric names.<T extends org.xbib.metrics.api.Metric>
Tregister(java.lang.String name, T metric)<T extends org.xbib.metrics.api.Metric>
Tregister(org.xbib.metrics.api.MetricName name, T metric)Given aMetric, registers it under the given name.voidregisterAll(org.xbib.metrics.api.MetricSet metrics)Given a metric set, registers them.booleanremove(org.xbib.metrics.api.MetricName name)Removes the metric with the given name.voidremoveListener(MetricRegistry.Listener listener)Removes aMetricRegistry.Listenerfrom this registry's collection of listeners.voidremoveMatching(org.xbib.metrics.api.MetricFilter filter)Removes all metrics which match the given filter.Samplertimer(java.lang.String name)Samplertimer(org.xbib.metrics.api.MetricName name)
-
-
-
Constructor Detail
-
MetricRegistry
public MetricRegistry()
Creates a newMetricRegistry.
-
MetricRegistry
protected MetricRegistry(java.util.concurrent.ConcurrentMap<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Metric> metricsMap)
Creates aMetricRegistrywith a customConcurrentMapimplementation for use inside the registry. Call as the super-constructor to create aMetricRegistrywith space- or time-bounded metric lifecycles, for example.- Parameters:
metricsMap- metrics map
-
-
Method Detail
-
name
public static org.xbib.metrics.api.MetricName name(java.lang.Class<?> klass, java.lang.String... names)- Parameters:
klass- the classnames- The remaining elements of the name- Returns:
- A metric name matching the specified components.
- See Also:
name(String, String...)
-
name
public static org.xbib.metrics.api.MetricName name(java.lang.String name, java.lang.String... names)Shorthand method for backwards compatibility in creating metric names. UsesMetricName.build(String...)for its heavy lifting.- Parameters:
name- The first element of the namenames- The remaining elements of the name- Returns:
- A metric name matching the specified components.
- See Also:
MetricName.build(String...)
-
register
public <T extends org.xbib.metrics.api.Metric> T register(java.lang.String name, T metric)- Type Parameters:
T- the type of the metric- Parameters:
name- the metric namemetric- the metric- Returns:
metric- See Also:
register(MetricName, Metric)
-
register
public <T extends org.xbib.metrics.api.Metric> T register(org.xbib.metrics.api.MetricName name, T metric)Given aMetric, registers it under the given name.- Type Parameters:
T- the type of the metric- Parameters:
name- the name of the metricmetric- the metric- Returns:
metric- Throws:
java.lang.IllegalArgumentException- if the name is already registered
-
registerAll
public void registerAll(org.xbib.metrics.api.MetricSet metrics)
Given a metric set, registers them.- Parameters:
metrics- a set of metrics- Throws:
java.lang.IllegalArgumentException- if any of the names are already registered
-
counter
public CountMetric counter(java.lang.String name)
- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
CountMetric - See Also:
counter(MetricName)
-
counter
public CountMetric counter(org.xbib.metrics.api.MetricName name)
Return theCountMetricregistered under this name; or create and register a newCountMetricif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
CountMetric
-
histogram
public Histogram histogram(java.lang.String name)
- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Histogram - See Also:
histogram(MetricName)
-
histogram
public Histogram histogram(org.xbib.metrics.api.MetricName name)
Return theHistogramregistered under this name; or create and register a newHistogramif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Histogram
-
meter
public Meter meter(java.lang.String name)
- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Meter - See Also:
meter(MetricName)
-
meter
public Meter meter(org.xbib.metrics.api.MetricName name)
Return theMeterregistered under this name; or create and register a newMeterif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Meter
-
timer
public Sampler timer(java.lang.String name)
- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Sampler - See Also:
timer(MetricName)
-
timer
public Sampler timer(org.xbib.metrics.api.MetricName name)
Return theSamplerregistered under this name; or create and register a newSamplerif none is registered.- Parameters:
name- the name of the metric- Returns:
- a new or pre-existing
Sampler
-
remove
public boolean remove(org.xbib.metrics.api.MetricName name)
Removes the metric with the given name.- Parameters:
name- the name of the metric- Returns:
- whether or not the metric was removed
-
removeMatching
public void removeMatching(org.xbib.metrics.api.MetricFilter filter)
Removes all metrics which match the given filter.- Parameters:
filter- a filter
-
addListener
public void addListener(MetricRegistry.Listener listener)
Adds aMetricRegistry.Listenerto a collection of listeners that will be notified on metric creation. Listeners will be notified in the order in which they are added. The listener will be notified of all existing metrics when it first registers.- Parameters:
listener- the listener that will be notified
-
removeListener
public void removeListener(MetricRegistry.Listener listener)
Removes aMetricRegistry.Listenerfrom this registry's collection of listeners.- Parameters:
listener- the listener that will be removed
-
getNames
public java.util.SortedSet<org.xbib.metrics.api.MetricName> getNames()
Returns a set of the names of all the metrics in the registry.- Returns:
- the names of all the metrics
-
getGauges
public java.util.SortedMap<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Gauge> getGauges()
Returns a map of all the gauges in the registry and their names.- Returns:
- all the gauges in the registry
-
getGauges
public java.util.SortedMap<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Gauge> getGauges(org.xbib.metrics.api.MetricFilter filter)
Returns a map of all the gauges in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the gauges in the registry
-
getCounters
public java.util.SortedMap<org.xbib.metrics.api.MetricName,CountMetric> getCounters()
Returns a map of all the counters in the registry and their names.- Returns:
- all the counters in the registry
-
getCounters
public java.util.SortedMap<org.xbib.metrics.api.MetricName,CountMetric> getCounters(org.xbib.metrics.api.MetricFilter filter)
Returns a map of all the counters in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the counters in the registry
-
getHistograms
public java.util.SortedMap<org.xbib.metrics.api.MetricName,Histogram> getHistograms()
Returns a map of all the histograms in the registry and their names.- Returns:
- all the histograms in the registry
-
getHistograms
public java.util.SortedMap<org.xbib.metrics.api.MetricName,Histogram> getHistograms(org.xbib.metrics.api.MetricFilter filter)
Returns a map of all the histograms in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the histograms in the registry
-
getMeters
public java.util.SortedMap<org.xbib.metrics.api.MetricName,Meter> getMeters()
Returns a map of all the meters in the registry and their names.- Returns:
- all the meters in the registry
-
getMeters
public java.util.SortedMap<org.xbib.metrics.api.MetricName,Meter> getMeters(org.xbib.metrics.api.MetricFilter filter)
Returns a map of all the meters in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the meters in the registry
-
getTimers
public java.util.SortedMap<org.xbib.metrics.api.MetricName,Sampler> getTimers()
Returns a map of all the timers in the registry and their names.- Returns:
- all the timers in the registry
-
getTimers
public java.util.SortedMap<org.xbib.metrics.api.MetricName,Sampler> getTimers(org.xbib.metrics.api.MetricFilter filter)
Returns a map of all the timers in the registry and their names which match the given filter.- Parameters:
filter- the metric filter to match- Returns:
- all the timers in the registry
-
getMetrics
public java.util.Map<org.xbib.metrics.api.MetricName,org.xbib.metrics.api.Metric> getMetrics()
- Specified by:
getMetricsin interfaceorg.xbib.metrics.api.MetricSet
-
-