Class AbstractRegistry<M extends HelidonMetric>
- Type Parameters:
M
- general type of metric implementation supported by an implementation of this class (e.g.,HelidonMetric
- All Implemented Interfaces:
MetricRegistry
- Direct Known Subclasses:
Registry
This class provides the bookkeeping for tracking the metrics which are created and registered along with their IDs and metadata. Concrete subclasses create new instances of the various types of metrics (counter, timer, etc.).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Gauge factories based on either functions or suppliers.Nested classes/interfaces inherited from interface org.eclipse.microprofile.metrics.MetricRegistry
MetricRegistry.Type
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractRegistry
(MetricRegistry.Type type, Class<M> metricClass, RegistrySettings registrySettings) Create a registry of a certain type. -
Method Summary
Modifier and TypeMethodDescriptionconcurrentGauge
(String name) concurrentGauge
(String name, Tag... tags) concurrentGauge
(Metadata metadata) concurrentGauge
(Metadata metadata, Tag... tags) concurrentGauge
(MetricID metricID) createGauge
(Metadata metadata, Supplier<R> supplier) Creates a gauge instance according to the specified supplier which returns the gauge value.createGauge
(Metadata metadata, T object, Function<T, R> func) Creates a gauge instance according to the provided metadata such that retrievals of the gauge value trigger an invocation of the provided function, passing the indicated object.protected static MetricType
deriveType
(MetricType candidateType, Metric metric) Infers theMetricType
from a provided candidate type and a metric instance.boolean
empty()
Determines if registry is empty.getConcurrentGauge
(MetricID metricID) getConcurrentGauges
(MetricFilter filter) getCounter
(MetricID metricID) getCounters
(MetricFilter filter) Gauge<?>
getGauges
(MetricFilter filter) getHistogram
(MetricID metricID) getHistograms
(MetricFilter filter) getMetadata
(String name) getMeters
(MetricFilter filter) <T extends Metric>
TgetMetrics
(Class<T> ofType, MetricFilter filter) getMetrics
(MetricFilter filter) getMetricsByName
(String metricName) Returns a list of metric ID/metric pairs which match the provided metric name.getNames()
getOptionalMetricEntry
(String metricName) Returns anOptional
for an entry containing a metric ID and the corresponding metric matching the specified metric name.getSimpleTimer
(MetricID metricID) getSimpleTimers
(MetricFilter filter) getTimers
(MetricFilter filter) getType()
static boolean
isMarkedAsDeleted
(Metric metric) Indicates whether the specific metrics has been marked as deleted.protected abstract boolean
isMetricEnabled
(String metricName) Indicates whether the specified metric name is enabled or not.protected boolean
metadataWithIDs
(String metricName) Returns a map entry, its key the metadata and its value all metric IDs matching the provided metric name.protected Map<MetricType,
BiFunction<String, Metadata, M>> For testing.metricIDsForName
(String metricName) Returns a list of metric IDs given a metric name.protected abstract Map<MetricType,
BiFunction<String, Metadata, M>> Provides a map from MicroProfile metric type to a factory which creates a concrete metric instance of the MP metric type which also extends the implementation metric base class for the concrete implementation (e.g., no-op or full-featured).protected abstract Map<Class<? extends M>,
MetricType> Prepares the map from Java types of implementation metrics to the correspondingMetricType
.<T extends Metric>
T<T extends Metric>
T<T extends Metric>
Tboolean
Removes a metric by name.boolean
Removes a metric by ID.void
removeMatching
(MetricFilter filter) simpleTimer
(String name) simpleTimer
(String name, Tag... tags) simpleTimer
(Metadata metadata) simpleTimer
(Metadata metadata, Tag... tags) simpleTimer
(MetricID metricID) stream()
Returns a stream ofMap.Entry
for this registry for enabled metrics.Creates a new instance of an implementation wrapper around the indicated metric.toString()
type()
Returns type of this registry.void
update
(RegistrySettings registrySettings) Update the registry settings for this registry.
-
Constructor Details
-
AbstractRegistry
protected AbstractRegistry(MetricRegistry.Type type, Class<M> metricClass, RegistrySettings registrySettings) Create a registry of a certain type.- Parameters:
type
- Registry type.metricClass
- class of the specific metric type this registry managesregistrySettings
- registry settings which influence this registry
-
-
Method Details
-
isMarkedAsDeleted
Indicates whether the specific metrics has been marked as deleted.- Parameters:
metric
- the metric to check- Returns:
- true if it's a Helidon metric and has been marked as deleted; false otherwise
-
isMetricEnabled
Indicates whether the specified metric name is enabled or not.Concrete implementations of this method should account for registry settings that might have disabled the specified metric or the registry as a whole. They do not need to check whether metrics in its entirety is enabled.
- Parameters:
metricName
- name of the metric to check- Returns:
- true if the metric is enabled; false otherwise
-
register
- Specified by:
register
in interfaceMetricRegistry
- Throws:
IllegalArgumentException
-
register
- Specified by:
register
in interfaceMetricRegistry
- Throws:
IllegalArgumentException
-
register
public <T extends Metric> T register(Metadata metadata, T metric, Tag... tags) throws IllegalArgumentException - Specified by:
register
in interfaceMetricRegistry
- Throws:
IllegalArgumentException
-
counter
- Specified by:
counter
in interfaceMetricRegistry
-
counter
- Specified by:
counter
in interfaceMetricRegistry
-
counter
- Specified by:
counter
in interfaceMetricRegistry
-
counter
- Specified by:
counter
in interfaceMetricRegistry
-
counter
- Specified by:
counter
in interfaceMetricRegistry
-
getCounter
- Specified by:
getCounter
in interfaceMetricRegistry
-
histogram
- Specified by:
histogram
in interfaceMetricRegistry
-
histogram
- Specified by:
histogram
in interfaceMetricRegistry
-
histogram
- Specified by:
histogram
in interfaceMetricRegistry
-
histogram
- Specified by:
histogram
in interfaceMetricRegistry
-
histogram
- Specified by:
histogram
in interfaceMetricRegistry
-
getHistogram
- Specified by:
getHistogram
in interfaceMetricRegistry
-
meter
- Specified by:
meter
in interfaceMetricRegistry
-
meter
- Specified by:
meter
in interfaceMetricRegistry
-
meter
- Specified by:
meter
in interfaceMetricRegistry
-
meter
- Specified by:
meter
in interfaceMetricRegistry
-
meter
- Specified by:
meter
in interfaceMetricRegistry
-
getMeter
- Specified by:
getMeter
in interfaceMetricRegistry
-
timer
- Specified by:
timer
in interfaceMetricRegistry
-
timer
- Specified by:
timer
in interfaceMetricRegistry
-
timer
- Specified by:
timer
in interfaceMetricRegistry
-
timer
- Specified by:
timer
in interfaceMetricRegistry
-
timer
- Specified by:
timer
in interfaceMetricRegistry
-
getTimer
- Specified by:
getTimer
in interfaceMetricRegistry
-
concurrentGauge
- Specified by:
concurrentGauge
in interfaceMetricRegistry
-
concurrentGauge
- Specified by:
concurrentGauge
in interfaceMetricRegistry
-
concurrentGauge
- Specified by:
concurrentGauge
in interfaceMetricRegistry
-
concurrentGauge
- Specified by:
concurrentGauge
in interfaceMetricRegistry
-
concurrentGauge
- Specified by:
concurrentGauge
in interfaceMetricRegistry
-
getConcurrentGauge
- Specified by:
getConcurrentGauge
in interfaceMetricRegistry
-
simpleTimer
- Specified by:
simpleTimer
in interfaceMetricRegistry
-
simpleTimer
- Specified by:
simpleTimer
in interfaceMetricRegistry
-
simpleTimer
- Specified by:
simpleTimer
in interfaceMetricRegistry
-
simpleTimer
- Specified by:
simpleTimer
in interfaceMetricRegistry
-
getSimpleTimer
- Specified by:
getSimpleTimer
in interfaceMetricRegistry
-
simpleTimer
- Specified by:
simpleTimer
in interfaceMetricRegistry
-
gauge
- Specified by:
gauge
in interfaceMetricRegistry
-
gauge
- Specified by:
gauge
in interfaceMetricRegistry
-
gauge
public <T,R extends Number> Gauge<R> gauge(Metadata metadata, T object, Function<T, R> func, Tag... tags) - Specified by:
gauge
in interfaceMetricRegistry
-
gauge
- Specified by:
gauge
in interfaceMetricRegistry
-
gauge
- Specified by:
gauge
in interfaceMetricRegistry
-
gauge
- Specified by:
gauge
in interfaceMetricRegistry
-
getGauge
- Specified by:
getGauge
in interfaceMetricRegistry
-
remove
Removes a metric by name.- Specified by:
remove
in interfaceMetricRegistry
- Parameters:
name
- Name of the metric.- Returns:
- Outcome of removal.
-
remove
Removes a metric by ID.- Specified by:
remove
in interfaceMetricRegistry
- Parameters:
metricID
- ID of metric.- Returns:
- Outcome of removal.
-
removeMatching
- Specified by:
removeMatching
in interfaceMetricRegistry
-
getNames
- Specified by:
getNames
in interfaceMetricRegistry
-
getMetricIDs
- Specified by:
getMetricIDs
in interfaceMetricRegistry
-
getGauges
- Specified by:
getGauges
in interfaceMetricRegistry
-
getGauges
- Specified by:
getGauges
in interfaceMetricRegistry
-
getCounters
- Specified by:
getCounters
in interfaceMetricRegistry
-
getCounters
- Specified by:
getCounters
in interfaceMetricRegistry
-
getHistograms
- Specified by:
getHistograms
in interfaceMetricRegistry
-
getHistograms
- Specified by:
getHistograms
in interfaceMetricRegistry
-
getMeters
- Specified by:
getMeters
in interfaceMetricRegistry
-
getMeters
- Specified by:
getMeters
in interfaceMetricRegistry
-
getTimers
- Specified by:
getTimers
in interfaceMetricRegistry
-
getTimers
- Specified by:
getTimers
in interfaceMetricRegistry
-
getConcurrentGauges
- Specified by:
getConcurrentGauges
in interfaceMetricRegistry
-
getConcurrentGauges
- Specified by:
getConcurrentGauges
in interfaceMetricRegistry
-
getSimpleTimers
- Specified by:
getSimpleTimers
in interfaceMetricRegistry
-
getSimpleTimers
- Specified by:
getSimpleTimers
in interfaceMetricRegistry
-
getMetadata
- Specified by:
getMetadata
in interfaceMetricRegistry
-
getMetadata
- Specified by:
getMetadata
in interfaceMetricRegistry
-
getMetrics
- Specified by:
getMetrics
in interfaceMetricRegistry
-
getMetrics
- Specified by:
getMetrics
in interfaceMetricRegistry
-
getMetrics
- Specified by:
getMetrics
in interfaceMetricRegistry
-
getMetric
- Specified by:
getMetric
in interfaceMetricRegistry
-
getMetric
- Specified by:
getMetric
in interfaceMetricRegistry
-
update
Update the registry settings for this registry.- Parameters:
registrySettings
- new settings to use going forward
-
type
Returns type of this registry.- Returns:
- The type.
-
getType
- Specified by:
getType
in interfaceMetricRegistry
-
empty
public boolean empty()Determines if registry is empty.- Returns:
- Outcome of test.
-
toString
-
metadataWithIDs
Returns a map entry, its key the metadata and its value all metric IDs matching the provided metric name.- Parameters:
metricName
- name to search for- Returns:
- the metadata and metric IDs known for the specified metric name; null if the name is not registered
-
registrySettings
- Returns:
- the registry settings used to set up the registry
-
isStrictExemplars
protected boolean isStrictExemplars()- Returns:
- whether exemplars are to be implemented strictly
-
stream
Returns a stream ofMap.Entry
for this registry for enabled metrics.- Returns:
- Stream of
Map.Entry
-
toImpl
Creates a new instance of an implementation wrapper around the indicated metric.- Type Parameters:
T
- specific type ofMetric
provided and wrapped- Parameters:
metadata
-Metadata
for the metricmetric
- the existing metric to be wrapped by the impl- Returns:
- new wrapper implementation around the specified metric instance
-
prepareMetricFactories
Provides a map from MicroProfile metric type to a factory which creates a concrete metric instance of the MP metric type which also extends the implementation metric base class for the concrete implementation (e.g., no-op or full-featured).- Returns:
- map from each MicroProfile metric type to the correspondingfactory method
-
getOptionalMetricEntry
Returns anOptional
for an entry containing a metric ID and the corresponding metric matching the specified metric name.If multiple metrics match the name (because of tags), the returned metric is, preferentially, the one (if any) with no tags. If all metrics registered under the specified name have tags, then the method returns the metric which was registered earliest
- Parameters:
metricName
- name of the metric of interest- Returns:
Optional
of a map entry containing the metric ID and the metric selected
-
getMetricsByName
Returns a list of metric ID/metric pairs which match the provided metric name.- Parameters:
metricName
- name of the metric of interest- Returns:
- List of entries indicating metrics with the specified name; empty of no matches
-
metricIDsForName
Returns a list of metric IDs given a metric name.- Parameters:
metricName
- name of the metric of interest- Returns:
- list of metric IDs for metrics with the specified name; empty if no matches
-
createGauge
protected <T,R extends Number> Gauge<R> createGauge(Metadata metadata, T object, Function<T, R> func) Creates a gauge instance according to the provided metadata such that retrievals of the gauge value trigger an invocation of the provided function, passing the indicated object.This default implementation uses a capturing lambda for retrieving the value. Concrete subclasses can override this implementation if capturing lambda behavior might become a performance issue.
- Type Parameters:
T
- Java type of the function parameter (and the object to pass to it)R
- specificNumber
subtype the gauge reports- Parameters:
metadata
- metadata to use in creating the gaugeobject
- object to pass to the value-returning functionfunc
- gauge-value-returning function- Returns:
- new gauge
-
createGauge
Creates a gauge instance according to the specified supplier which returns the gauge value.- Type Parameters:
R
- specificNumber
subtype the supplier returns- Parameters:
metadata
- metadata to use in creating the gaugesupplier
- gauge-value-returning supplier- Returns:
- new gauge
-
deriveType
Infers theMetricType
from a provided candidate type and a metric instance.- Parameters:
candidateType
- type of metric to use if not invalid; typically computed from an existing metricmetric
- the metric for which to derive the metric type- Returns:
- the
MetricType
of the metric
-
metricFactories
For testing.- Returns:
- map from MicroProfile metric type to factory functions.
-
prepareMetricToTypeMap
Prepares the map from Java types of implementation metrics to the correspondingMetricType
.- Returns:
- prepared map for a given metrics implementation
-