Class AbstractTaggedMetricRegistry

java.lang.Object
com.palantir.tritium.metrics.registry.AbstractTaggedMetricRegistry
All Implemented Interfaces:
TaggedMetricRegistry, TaggedMetricSet
Direct Known Subclasses:
DefaultTaggedMetricRegistry, SlidingWindowTaggedMetricRegistry

public abstract class AbstractTaggedMetricRegistry extends Object implements TaggedMetricRegistry
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractTaggedMetricRegistry(Supplier<com.codahale.metrics.Reservoir> reservoirSupplier)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    addMetrics(String safeTagName, String safeTagValue, TaggedMetricSet other)
    Adds a set of metrics to this TaggedMetricRegistry's metric set, which are to be uniquely identified by the tags provided.
    final com.codahale.metrics.Counter
    counter(MetricName metricName)
    Returns existing or new counter metric for the specified metric name.
    final com.codahale.metrics.Counter
    counter(MetricName metricName, Supplier<com.codahale.metrics.Counter> counterSupplier)
     
    protected @NonNull Supplier<com.codahale.metrics.Counter>
    Supplies counter instances for this registry.
    protected final @NonNull com.codahale.metrics.Reservoir
    Supplies reservoir instances for this registry.
    final void
    forEachMetric(BiConsumer<MetricName, com.codahale.metrics.Metric> consumer)
     
    final <T> Optional<com.codahale.metrics.Gauge<T>>
    gauge(MetricName metricName)
    Returns existing gauge metric for the specified metric name or empty if none has been registered.
    final <T> com.codahale.metrics.Gauge<T>
    gauge(MetricName metricName, com.codahale.metrics.Gauge<T> gauge)
    Returns existing or new gauge metric for the specified metric name.
    final Map<MetricName, com.codahale.metrics.Metric>
    Returns a map of metrics.
    protected final <T extends com.codahale.metrics.Metric>
    T
    getOrAdd(MetricName metricName, Class<T> metricClass, Supplier<T> metricSupplier)
     
    final com.codahale.metrics.Histogram
    histogram(MetricName metricName)
    Returns existing or new histogram metric for the specified metric name.
    final com.codahale.metrics.Histogram
    histogram(MetricName metricName, Supplier<com.codahale.metrics.Histogram> histogramSupplier)
     
    protected @NonNull Supplier<com.codahale.metrics.Histogram>
    Supplies histogram instances for this registry.
    final com.codahale.metrics.Meter
    meter(MetricName metricName)
    Returns existing or new meter metric for the specified metric name.
    final com.codahale.metrics.Meter
    meter(MetricName metricName, Supplier<com.codahale.metrics.Meter> meterSupplier)
     
    protected @NonNull Supplier<com.codahale.metrics.Meter>
    Supplies meter instances for this registry.
    final void
    registerWithReplacement(MetricName metricName, com.codahale.metrics.Gauge<?> gauge)
    Registers and returns the specified gauge, replacing any existing gauge with the specified metric name.
    final Optional<com.codahale.metrics.Metric>
    remove(MetricName metricName)
    Removes the tagged metric with the specified metric name.
    removeMetrics(String safeTagName, String safeTagValue)
    Removes a TaggedMetricsSet added via addMetrics from this metrics set.
    final boolean
    removeMetrics(String safeTagName, String safeTagValue, TaggedMetricSet metrics)
    Removes a TaggedMetricsSet added via addMetrics from this metrics set, if currently registered to this metric set.
    final com.codahale.metrics.Timer
    timer(MetricName metricName)
    Returns existing or new timer metric for the specified metric name.
    final com.codahale.metrics.Timer
    timer(MetricName metricName, Supplier<com.codahale.metrics.Timer> timerSupplier)
     
    protected @NonNull Supplier<com.codahale.metrics.Timer>
    Supplies timer instances for this registry.

    Methods inherited from class Object

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

    • AbstractTaggedMetricRegistry

      public AbstractTaggedMetricRegistry(Supplier<com.codahale.metrics.Reservoir> reservoirSupplier)
  • Method Details

    • counterSupplier

      protected @NonNull Supplier<com.codahale.metrics.Counter> counterSupplier()
      Supplies counter instances for this registry.
      Returns:
      counter supplier
    • histogramSupplier

      protected @NonNull Supplier<com.codahale.metrics.Histogram> histogramSupplier()
      Supplies histogram instances for this registry.
      Returns:
      histogram supplier
    • meterSupplier

      protected @NonNull Supplier<com.codahale.metrics.Meter> meterSupplier()
      Supplies meter instances for this registry.
      Returns:
      meter supplier
    • timerSupplier

      protected @NonNull Supplier<com.codahale.metrics.Timer> timerSupplier()
      Supplies timer instances for this registry.
      Returns:
      timer supplier
    • createReservoir

      protected final @NonNull com.codahale.metrics.Reservoir createReservoir()
      Supplies reservoir instances for this registry.
      Returns:
      reservoir supplier
    • counter

      public final com.codahale.metrics.Counter counter(MetricName metricName)
      Description copied from interface: TaggedMetricRegistry
      Returns existing or new counter metric for the specified metric name.
      Specified by:
      counter in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      Returns:
      counter metric
    • counter

      public final com.codahale.metrics.Counter counter(MetricName metricName, Supplier<com.codahale.metrics.Counter> counterSupplier)
      Specified by:
      counter in interface TaggedMetricRegistry
    • gauge

      public final <T> Optional<com.codahale.metrics.Gauge<T>> gauge(MetricName metricName)
      Description copied from interface: TaggedMetricRegistry
      Returns existing gauge metric for the specified metric name or empty if none has been registered.
      Specified by:
      gauge in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      Returns:
      gauge metric or empty if none exists for this name
    • gauge

      public final <T> com.codahale.metrics.Gauge<T> gauge(MetricName metricName, com.codahale.metrics.Gauge<T> gauge)
      Description copied from interface: TaggedMetricRegistry
      Returns existing or new gauge metric for the specified metric name.
      Specified by:
      gauge in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      gauge - gauge
      Returns:
      gauge metric

      In most cases, one typically wants TaggedMetricRegistry.registerWithReplacement(MetricName, Gauge) as gauges may retain references to large backing data structures (e.g. queue or cache), and if a gauge is being registered with the same name, one is likely replacing that previous data structure and the registry should not retain references to the previous version. If lookup of an existing gauge is desired, one should use TaggedMetricRegistry.gauge(MetricName).

    • registerWithReplacement

      public final void registerWithReplacement(MetricName metricName, com.codahale.metrics.Gauge<?> gauge)
      Description copied from interface: TaggedMetricRegistry
      Registers and returns the specified gauge, replacing any existing gauge with the specified metric name.
      Specified by:
      registerWithReplacement in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      gauge - gauge
    • histogram

      public final com.codahale.metrics.Histogram histogram(MetricName metricName)
      Description copied from interface: TaggedMetricRegistry
      Returns existing or new histogram metric for the specified metric name.
      Specified by:
      histogram in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      Returns:
      histogram metric
    • histogram

      public final com.codahale.metrics.Histogram histogram(MetricName metricName, Supplier<com.codahale.metrics.Histogram> histogramSupplier)
      Specified by:
      histogram in interface TaggedMetricRegistry
    • meter

      public final com.codahale.metrics.Meter meter(MetricName metricName)
      Description copied from interface: TaggedMetricRegistry
      Returns existing or new meter metric for the specified metric name.
      Specified by:
      meter in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      Returns:
      meter metric
    • meter

      public final com.codahale.metrics.Meter meter(MetricName metricName, Supplier<com.codahale.metrics.Meter> meterSupplier)
      Specified by:
      meter in interface TaggedMetricRegistry
    • timer

      public final com.codahale.metrics.Timer timer(MetricName metricName)
      Description copied from interface: TaggedMetricRegistry
      Returns existing or new timer metric for the specified metric name.
      Specified by:
      timer in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      Returns:
      timer metric
    • timer

      public final com.codahale.metrics.Timer timer(MetricName metricName, Supplier<com.codahale.metrics.Timer> timerSupplier)
      Specified by:
      timer in interface TaggedMetricRegistry
    • getMetrics

      public final Map<MetricName, com.codahale.metrics.Metric> getMetrics()
      Description copied from interface: TaggedMetricSet
      Returns a map of metrics.
      Specified by:
      getMetrics in interface TaggedMetricSet
      Returns:
      map of metrics
    • forEachMetric

      public final void forEachMetric(BiConsumer<MetricName, com.codahale.metrics.Metric> consumer)
      Specified by:
      forEachMetric in interface TaggedMetricSet
    • remove

      public final Optional<com.codahale.metrics.Metric> remove(MetricName metricName)
      Description copied from interface: TaggedMetricRegistry
      Removes the tagged metric with the specified metric name.
      Specified by:
      remove in interface TaggedMetricRegistry
      Parameters:
      metricName - metric name
      Returns:
      the removed metric
    • addMetrics

      public final void addMetrics(String safeTagName, String safeTagValue, TaggedMetricSet other)
      Description copied from interface: TaggedMetricRegistry
      Adds a set of metrics to this TaggedMetricRegistry's metric set, which are to be uniquely identified by the tags provided.

      So, if I have a metric registry with a single metric called 'foo', and I add it with tag (bar, baz), this registry will now contain 'foo', tagged with (bar, baz).

      If a metric exists with duplicate tags, then calling TaggedMetricSet.getMetrics() will be impossible.

      Specified by:
      addMetrics in interface TaggedMetricRegistry
      Parameters:
      safeTagName - a tag key which should be added to all metrics in the metrics set
      safeTagValue - a tag value which should be added to all metrics in the metrics set
      other - the metrics which should be added
    • removeMetrics

      public final Optional<TaggedMetricSet> removeMetrics(String safeTagName, String safeTagValue)
      Description copied from interface: TaggedMetricRegistry
      Removes a TaggedMetricsSet added via addMetrics from this metrics set.
      Specified by:
      removeMetrics in interface TaggedMetricRegistry
    • removeMetrics

      public final boolean removeMetrics(String safeTagName, String safeTagValue, TaggedMetricSet metrics)
      Description copied from interface: TaggedMetricRegistry
      Removes a TaggedMetricsSet added via addMetrics from this metrics set, if currently registered to this metric set.

      The value is removed only when Object.equals(Object) for the values returns true, therefore you should generally provide the same instance as a previous call to addMetrics.

      Specified by:
      removeMetrics in interface TaggedMetricRegistry
      Returns:
      true if value was removed
    • getOrAdd

      protected final <T extends com.codahale.metrics.Metric> T getOrAdd(MetricName metricName, Class<T> metricClass, Supplier<T> metricSupplier)