Class Timer

  • All Implemented Interfaces:
    Counting, Metered, Metric, Sampling

    public class Timer
    extends java.lang.Object
    implements Metered, Sampling
    A timer metric which aggregates timing durations and provides duration statistics, plus throughput statistics via Meter.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Timer.Context
      A timing context.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getCount()
      Returns the number of events which have been marked.
      double getFifteenMinuteRate()
      Returns the fifteen-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.
      double getFiveMinuteRate()
      Returns the five-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.
      double getMeanRate()
      Returns the mean rate at which events have occurred since the meter was created.
      double getOneMinuteRate()
      Returns the one-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.
      Snapshot getSnapshot()
      Returns a snapshot of the values.
      Timer.Context time()
      Returns a new Timer.Context.
      <T> T time​(java.util.concurrent.Callable<T> event)
      Times and records the duration of event.
      private void update​(long duration)  
      void update​(long duration, java.util.concurrent.TimeUnit unit)
      Adds a recorded duration.
      • Methods inherited from class java.lang.Object

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

      • meter

        private final Meter meter
      • histogram

        private final Histogram histogram
      • clock

        private final Clock clock
    • Method Detail

      • update

        public void update​(long duration,
                           java.util.concurrent.TimeUnit unit)
        Adds a recorded duration.
        Parameters:
        duration - the length of the duration
        unit - the scale unit of duration
      • time

        public <T> T time​(java.util.concurrent.Callable<T> event)
                   throws java.lang.Exception
        Times and records the duration of event.
        Type Parameters:
        T - the type of the value returned by event
        Parameters:
        event - a Callable whose Callable.call() method implements a process whose duration should be timed
        Returns:
        the value returned by event
        Throws:
        java.lang.Exception - if event throws an Exception
      • getCount

        public long getCount()
        Description copied from interface: Metered
        Returns the number of events which have been marked.
        Specified by:
        getCount in interface Counting
        Specified by:
        getCount in interface Metered
        Returns:
        the number of events which have been marked
      • getFifteenMinuteRate

        public double getFifteenMinuteRate()
        Description copied from interface: Metered
        Returns the fifteen-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.

        This rate has the same exponential decay factor as the fifteen-minute load average in the top Unix command.

        Specified by:
        getFifteenMinuteRate in interface Metered
        Returns:
        the fifteen-minute exponentially-weighted moving average rate at which events have occurred since the meter was created
      • getFiveMinuteRate

        public double getFiveMinuteRate()
        Description copied from interface: Metered
        Returns the five-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.

        This rate has the same exponential decay factor as the five-minute load average in the top Unix command.

        Specified by:
        getFiveMinuteRate in interface Metered
        Returns:
        the five-minute exponentially-weighted moving average rate at which events have occurred since the meter was created
      • getMeanRate

        public double getMeanRate()
        Description copied from interface: Metered
        Returns the mean rate at which events have occurred since the meter was created.
        Specified by:
        getMeanRate in interface Metered
        Returns:
        the mean rate at which events have occurred since the meter was created
      • getOneMinuteRate

        public double getOneMinuteRate()
        Description copied from interface: Metered
        Returns the one-minute exponentially-weighted moving average rate at which events have occurred since the meter was created.

        This rate has the same exponential decay factor as the one-minute load average in the top Unix command.

        Specified by:
        getOneMinuteRate in interface Metered
        Returns:
        the one-minute exponentially-weighted moving average rate at which events have occurred since the meter was created
      • getSnapshot

        public Snapshot getSnapshot()
        Description copied from interface: Sampling
        Returns a snapshot of the values.
        Specified by:
        getSnapshot in interface Sampling
        Returns:
        a snapshot of the values
      • update

        private void update​(long duration)