Class MetricsSupport
- Since:
- 3.3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.codahale.metrics.MetricRegistryGet the metric registry installed into the runtime.static booleanisMetricInstanceRegisteredUnderName(String name, com.codahale.metrics.Metric metric, com.codahale.metrics.MetricRegistry registry) Determine whether the given metric instance is registered under the given name.static <T extends com.codahale.metrics.Metric>
TRegister a metric instance under the given name.static <T extends com.codahale.metrics.Metric>
TRegister a metric instance under the given name.static <T extends com.codahale.metrics.Metric>
Tregister(String name, T metric, boolean replaceExisting, com.codahale.metrics.MetricRegistry registry) Register a metric instance under the given name.static booleanRemove a metric instance registered under the given name.static booleanRemove a metric instance registered under the given name.static booleanremove(String name, com.codahale.metrics.Metric metric, com.codahale.metrics.MetricRegistry registry) Remove a metric instance registered under the given name.static com.codahale.metrics.Timer.ContextstartTimer(com.codahale.metrics.Timer timer) Start the specified timer.static LongstopTimer(com.codahale.metrics.Timer.Context context) Stop the timer represented by the specified timer context instance.
-
Constructor Details
-
MetricsSupport
private MetricsSupport()Private constructor.
-
-
Method Details
-
getMetricRegistry
@Nullable public static com.codahale.metrics.MetricRegistry getMetricRegistry()Get the metric registry installed into the runtime.- Returns:
- default registry
-
register
@Nullable public static <T extends com.codahale.metrics.Metric> T register(@Nonnull String name, @Nonnull T metric) Register a metric instance under the given name.Any existing instance registered under the given name will be replaced. The
MetricRegistryon which to operate will be obtained viagetMetricRegistry().- Type Parameters:
T- the type of metric being registered- Parameters:
name- the name under which to register the metricmetric- the metric instance to register- Returns:
- the metric instance which was registered
-
register
@Nullable public static <T extends com.codahale.metrics.Metric> T register(@Nonnull String name, @Nonnull T metric, boolean replaceExisting) Register a metric instance under the given name.The
MetricRegistryon which to operate will be obtained viagetMetricRegistry().- Type Parameters:
T- the type of metric being registered- Parameters:
name- the name under which to register the metricmetric- the metric instance to registerreplaceExisting- whether or not to replace the existing metric registered under that name- Returns:
- the metric instance which was registered
-
register
@Nullable public static <T extends com.codahale.metrics.Metric> T register(@Nonnull String name, @Nonnull T metric, boolean replaceExisting, @Nullable com.codahale.metrics.MetricRegistry registry) Register a metric instance under the given name.- Type Parameters:
T- the type of metric being registered- Parameters:
name- the name under which to register the metricmetric- the metric instance to registerreplaceExisting- whether or not to replace the existing metric registered under that nameregistry- the metric registry on which to operate. If null, will be obtained viagetMetricRegistry().- Returns:
- the metric instance which was registered
-
remove
Remove a metric instance registered under the given name.- Parameters:
name- the name under which to deregister the metric- Returns:
- whether or not the metric was actually removed
-
remove
Remove a metric instance registered under the given name.If a non-null metric instance is supplied, the metric instance registered under the given name will only be removed if it is the same instance as supplied, as determined by
isMetricInstanceRegisteredUnderName(String, Metric, MetricRegistry)The
MetricRegistryon which to operate will be obtained viagetMetricRegistry().- Parameters:
name- the name under which to deregister the metricmetric- the metric instance to remove- Returns:
- whether or not the metric was actually removed
-
remove
public static boolean remove(@Nonnull String name, @Nullable com.codahale.metrics.Metric metric, @Nullable com.codahale.metrics.MetricRegistry registry) Remove a metric instance registered under the given name.If a non-null metric instance is supplied, the metric instance registered under the given name will only be removed if it is the same instance as supplied, as determined by
isMetricInstanceRegisteredUnderName(String, Metric, MetricRegistry)The
MetricRegistryon which to operate will be obtained viagetMetricRegistry().- Parameters:
name- the name under which to deregister the metricmetric- the metric instance to removeregistry- the metric registry on which to operate. If null, will be obtained viagetMetricRegistry().- Returns:
- whether or not the metric was actually removed
-
isMetricInstanceRegisteredUnderName
public static boolean isMetricInstanceRegisteredUnderName(@Nonnull String name, @Nonnull com.codahale.metrics.Metric metric, @Nonnull com.codahale.metrics.MetricRegistry registry) Determine whether the given metric instance is registered under the given name.- Parameters:
name- the name under which to deregister the metricmetric- the metric instance to removeregistry- the metric registry on which to operate.- Returns:
- true if the given metric instance is registered under the given name, false if not
-
startTimer
@Nullable public static com.codahale.metrics.Timer.Context startTimer(@Nullable com.codahale.metrics.Timer timer) Start the specified timer.- Parameters:
timer- the timer to start, may be null- Returns:
- the timer context, or null if the input timer was null
-
stopTimer
Stop the timer represented by the specified timer context instance.- Parameters:
context- the timer context to stop, may be null- Returns:
- the elapsed time in nanoseconds, or null if the input context was null
-