Class 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.
    • Constructor Detail

      • 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 Detail

      • 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