Class 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.MetricSet
    A registry of metric instances.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  MetricRegistry.Listener
      Listeners for events from the registry.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        MetricRegistry()
      Creates a new MetricRegistry.
      protected MetricRegistry​(java.util.concurrent.ConcurrentMap<org.xbib.metrics.api.MetricName,​org.xbib.metrics.api.Metric> metricsMap)
      Creates a MetricRegistry with a custom ConcurrentMap implementation for use inside the registry.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(MetricRegistry.Listener listener)
      Adds a MetricRegistry.Listener to a collection of listeners that will be notified on metric creation.
      CountMetric counter​(java.lang.String name)  
      CountMetric counter​(org.xbib.metrics.api.MetricName name)
      Return the CountMetric registered under this name; or create and register a new CountMetric if 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.
      Histogram histogram​(java.lang.String name)  
      Histogram histogram​(org.xbib.metrics.api.MetricName name)
      Return the Histogram registered under this name; or create and register a new Histogram if none is registered.
      Meter meter​(java.lang.String name)  
      Meter meter​(org.xbib.metrics.api.MetricName name)
      Return the Meter registered under this name; or create and register a new Meter if none is registered.
      static org.xbib.metrics.api.MetricName name​(java.lang.Class<?> klass, java.lang.String... names)  
      static org.xbib.metrics.api.MetricName name​(java.lang.String name, java.lang.String... names)
      Shorthand method for backwards compatibility in creating metric names.
      <T extends org.xbib.metrics.api.Metric>
      T
      register​(java.lang.String name, T metric)  
      <T extends org.xbib.metrics.api.Metric>
      T
      register​(org.xbib.metrics.api.MetricName name, T metric)
      Given a Metric, registers it under the given name.
      void registerAll​(org.xbib.metrics.api.MetricSet metrics)
      Given a metric set, registers them.
      boolean remove​(org.xbib.metrics.api.MetricName name)
      Removes the metric with the given name.
      void removeListener​(MetricRegistry.Listener listener)
      Removes a MetricRegistry.Listener from this registry's collection of listeners.
      void removeMatching​(org.xbib.metrics.api.MetricFilter filter)
      Removes all metrics which match the given filter.
      Sampler timer​(java.lang.String name)  
      Sampler timer​(org.xbib.metrics.api.MetricName name)
      Return the Sampler registered under this name; or create and register a new Sampler if none is registered.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MetricRegistry

        public MetricRegistry()
        Creates a new MetricRegistry.
      • MetricRegistry

        protected MetricRegistry​(java.util.concurrent.ConcurrentMap<org.xbib.metrics.api.MetricName,​org.xbib.metrics.api.Metric> metricsMap)
        Creates a MetricRegistry with a custom ConcurrentMap implementation for use inside the registry. Call as the super-constructor to create a MetricRegistry with 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 class
        names - 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. Uses MetricName.build(String...) for its heavy lifting.
        Parameters:
        name - The first element of the name
        names - 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 name
        metric - 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 a Metric, registers it under the given name.
        Type Parameters:
        T - the type of the metric
        Parameters:
        name - the name of the metric
        metric - 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​(org.xbib.metrics.api.MetricName name)
        Return the CountMetric registered under this name; or create and register a new CountMetric if none is registered.
        Parameters:
        name - the name of the metric
        Returns:
        a new or pre-existing CountMetric
      • histogram

        public Histogram histogram​(org.xbib.metrics.api.MetricName name)
        Return the Histogram registered under this name; or create and register a new Histogram if 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 the Meter registered under this name; or create and register a new Meter if 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 the Sampler registered under this name; or create and register a new Sampler if 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 a MetricRegistry.Listener to 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
      • 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:
        getMetrics in interface org.xbib.metrics.api.MetricSet