Class CachedGauge<T>

java.lang.Object
com.codahale.metrics.CachedGauge<T>
Type Parameters:
T - the type of the gauge's value
All Implemented Interfaces:
Gauge<T>, Metric

public abstract class CachedGauge<T> extends Object implements Gauge<T>
A Gauge implementation which caches its value for a period of time.
  • Field Details

    • clock

      private final Clock clock
    • reloadAt

      private final AtomicLong reloadAt
    • timeoutNS

      private final long timeoutNS
    • value

      private volatile T value
  • Constructor Details

    • CachedGauge

      protected CachedGauge(long timeout, TimeUnit timeoutUnit)
      Creates a new cached gauge with the given timeout period.
      Parameters:
      timeout - the timeout
      timeoutUnit - the unit of timeout
    • CachedGauge

      protected CachedGauge(Clock clock, long timeout, TimeUnit timeoutUnit)
      Creates a new cached gauge with the given clock and timeout period.
      Parameters:
      clock - the clock used to calculate the timeout
      timeout - the timeout
      timeoutUnit - the unit of timeout
  • Method Details

    • loadValue

      protected abstract T loadValue()
      Loads the value and returns it.
      Returns:
      the new value
    • getValue

      public T getValue()
      Description copied from interface: Gauge
      Returns the metric's current value.
      Specified by:
      getValue in interface Gauge<T>
      Returns:
      the metric's current value
    • shouldLoad

      private boolean shouldLoad()