Interface SimpleTimer

  • All Superinterfaces:
    Counting, Metric

    public interface SimpleTimer
    extends Metric, Counting
    A simple timer metric which tracks elapsed time durations and count. This is a lightweight alternative to (@link Timer). The simple timer measures duration in nanoseconds.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  SimpleTimer.Context
      A timing context.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      long getCount()
      Returns the current count.
      java.time.Duration getElapsedTime()
      Returns the total elapsed timing durations of all completed timing events that are recorded with update(Duration).
      java.time.Duration getMaxTimeDuration()
      Get the maximum recorded time duration of the SimpleTimer for the previously completed full minute.
      java.time.Duration getMinTimeDuration()
      Get the minimum recorded time duration of the SimpleTimer for the previously completed full minute.
      SimpleTimer.Context time()
      Returns a new SimpleTimer.Context.
      void time​(java.lang.Runnable event)
      Times and records the duration of event.
      <T> T time​(java.util.concurrent.Callable<T> event)
      Times and records the duration of event.
      void update​(java.time.Duration duration)
      Adds a recorded duration.
    • Method Detail

      • update

        void update​(java.time.Duration duration)
        Adds a recorded duration.
        Parameters:
        duration - the length of the duration
      • time

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

        void time​(java.lang.Runnable event)
        Times and records the duration of event.
        Parameters:
        event - a Runnable whose Runnable.run() method implements a process whose duration should be timed
      • getElapsedTime

        java.time.Duration getElapsedTime()
        Returns the total elapsed timing durations of all completed timing events that are recorded with update(Duration).
        Returns:
        the elapsed time duration
      • getCount

        long getCount()
        Description copied from interface: Counting
        Returns the current count.
        Specified by:
        getCount in interface Counting
        Returns:
        the current count
      • getMaxTimeDuration

        java.time.Duration getMaxTimeDuration()
        Get the maximum recorded time duration of the SimpleTimer for the previously completed full minute.

        This represents the highest timed duration in the last completed full minute. For example if the last completed full minute recorded durations of 12 seconds, 9 seconds and 1 second the largest value is 12 seconds. If no time duration has been recorded in the last completed full minute then a null is returned. If there has only been one time duration recorded in the last completed full minute then this value will be returned by both getMaxTimeDuration() and getMinTimeDuration()

        Returns:
        The maximum recorded time duration in the previously completed full minute or null if no values were recorded
      • getMinTimeDuration

        java.time.Duration getMinTimeDuration()
        Get the minimum recorded time duration of the SimpleTimer for the previously completed full minute.

        This represents the lowest timed duration in the last completed full minute. For example if the last completed full minute recorded durations of 12 seconds, 9 seconds and 1 second the lowest value is 1 second. If no time duration has been recorded in the last completed full minute then a null is returned. If there has only been one time duration recorded in the last completed full minute then this value will be returned by both getMaxTimeDuration() and getMinTimeDuration()

        Returns:
        The minimum recorded time duration in the previously completed full minute or null if no values were recorded