Class MetricsSupport

java.lang.Object
org.opensaml.core.metrics.MetricsSupport

public final class MetricsSupport extends Object
Support code for use of metrics.
Since:
3.3.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.codahale.metrics.MetricRegistry
    Get the metric registry installed into the runtime.
    static boolean
    isMetricInstanceRegisteredUnderName(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>
    T
    register(String name, T metric)
    Register a metric instance under the given name.
    static <T extends com.codahale.metrics.Metric>
    T
    register(String name, T metric, boolean replaceExisting)
    Register a metric instance under the given name.
    static <T extends com.codahale.metrics.Metric>
    T
    register(String name, T metric, boolean replaceExisting, com.codahale.metrics.MetricRegistry registry)
    Register a metric instance under the given name.
    static boolean
    remove(String name)
    Remove a metric instance registered under the given name.
    static boolean
    remove(String name, com.codahale.metrics.Metric metric)
    Remove a metric instance registered under the given name.
    static boolean
    remove(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.Context
    startTimer(com.codahale.metrics.Timer timer)
    Start the specified timer.
    static Long
    stopTimer(com.codahale.metrics.Timer.Context context)
    Stop the timer represented by the specified timer context instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 MetricRegistry on which to operate will be obtained via getMetricRegistry().

      Type Parameters:
      T - the type of metric being registered
      Parameters:
      name - the name under which to register the metric
      metric - 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 MetricRegistry on which to operate will be obtained via getMetricRegistry().

      Type Parameters:
      T - the type of metric being registered
      Parameters:
      name - the name under which to register the metric
      metric - the metric instance to register
      replaceExisting - 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 metric
      metric - the metric instance to register
      replaceExisting - whether or not to replace the existing metric registered under that name
      registry - the metric registry on which to operate. If null, will be obtained via getMetricRegistry().
      Returns:
      the metric instance which was registered
    • remove

      public static boolean remove(@Nonnull String name)
      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

      public static boolean remove(@Nonnull String name, @Nullable com.codahale.metrics.Metric metric)
      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 MetricRegistry on which to operate will be obtained via getMetricRegistry().

      Parameters:
      name - the name under which to deregister the metric
      metric - 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 MetricRegistry on which to operate will be obtained via getMetricRegistry().

      Parameters:
      name - the name under which to deregister the metric
      metric - the metric instance to remove
      registry - the metric registry on which to operate. If null, will be obtained via getMetricRegistry().
      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 metric
      metric - the metric instance to remove
      registry - 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

      @Nullable public static Long stopTimer(@Nullable com.codahale.metrics.Timer.Context context)
      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