Interface Timer

All Known Implementing Classes:
DefaultTimer

public interface Timer
Generalized Timer interface for creating telemetry related instances for measuring duration of operations.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A timing sample that carries internal state about the Timer's start position.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Timer
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    The number of times time(Duration) was called.
    default boolean
    Determines whether this timer is a NOOP timer.
    void
    record(long amount, TimeUnit unit)
    Records a custom amount in the given time unit.
    Starts the timer and returns a Timer.Timed instance.
    void
    time(Runnable runnable)
    Executes and measures the given Runnable instance.
    default void
    time(Duration duration)
    The duration to record
    <T> T
    time(Supplier<T> supplier)
    Gets the result from the given Supplier and measures its execution time.
    <T> T
    timeCallable(Callable<T> callable)
    Executes and measures the given Callable and returns its result.
    The total duration that was recorded.
    default TimeUnit
    The TimeUnit of the timer.
  • Field Details

    • NOOP

      static final Timer NOOP
  • Method Details

    • count

      long count()
      The number of times time(Duration) was called.
      Returns:
      The number of times time(Duration) was called.
    • totalDuration

      Duration totalDuration()
      The total duration that was recorded.
      Returns:
      The total duration that was recorded.
    • start

      Timer.Timed start()
      Starts the timer and returns a Timer.Timed instance. Call Timer.Timed.stop() to complete the timing.
      Returns:
      A Timer.Timed instance with the start time recorded.
    • unit

      default TimeUnit unit()
      The TimeUnit of the timer.
      Returns:
      The TimeUnit of the timer.
    • record

      void record(long amount, TimeUnit unit)
      Records a custom amount in the given time unit.
      Parameters:
      amount - The amount to record
      unit - The time unit of the amount
    • time

      default void time(Duration duration)
      The duration to record
      Parameters:
      duration - The duration to record
    • time

      void time(Runnable runnable)
      Executes and measures the given Runnable instance.
      Parameters:
      runnable - The Runnable to execute and measure.
    • timeCallable

      <T> T timeCallable(Callable<T> callable) throws Exception
      Executes and measures the given Callable and returns its result.
      Type Parameters:
      T - The type of the Callable
      Parameters:
      callable - The Callable to execute and measure.
      Returns:
      The result of the underlying Callable.
      Throws:
      Exception - In case the Callable fails.
    • time

      <T> T time(Supplier<T> supplier)
      Gets the result from the given Supplier and measures its execution time.
      Type Parameters:
      T - The type of the Supplier.
      Parameters:
      supplier - The Supplier to execute and measure.
      Returns:
      The result of the underlying Supplier.
    • isNoop

      default boolean isNoop()
      Determines whether this timer is a NOOP timer.
      Returns:
      Whether this timer is a NOOP timer.