Class DefaultTimer

java.lang.Object
org.apache.iceberg.metrics.DefaultTimer
All Implemented Interfaces:
Timer

public class DefaultTimer extends Object implements Timer
A default Timer implementation that uses a Stopwatch instance internally to measure time.
  • Constructor Details

    • DefaultTimer

      public DefaultTimer(TimeUnit timeUnit)
  • Method Details

    • count

      public long count()
      Description copied from interface: Timer
      The number of times Timer.time(Duration) was called.
      Specified by:
      count in interface Timer
      Returns:
      The number of times Timer.time(Duration) was called.
    • totalDuration

      public Duration totalDuration()
      Description copied from interface: Timer
      The total duration that was recorded.
      Specified by:
      totalDuration in interface Timer
      Returns:
      The total duration that was recorded.
    • start

      public Timer.Timed start()
      Description copied from interface: Timer
      Starts the timer and returns a Timer.Timed instance. Call Timer.Timed.stop() to complete the timing.
      Specified by:
      start in interface Timer
      Returns:
      A Timer.Timed instance with the start time recorded.
    • record

      public void record(long amount, TimeUnit unit)
      Description copied from interface: Timer
      Records a custom amount in the given time unit.
      Specified by:
      record in interface Timer
      Parameters:
      amount - The amount to record
      unit - The time unit of the amount
    • time

      public <T> T time(Supplier<T> supplier)
      Description copied from interface: Timer
      Gets the result from the given Supplier and measures its execution time.
      Specified by:
      time in interface Timer
      Type Parameters:
      T - The type of the Supplier.
      Parameters:
      supplier - The Supplier to execute and measure.
      Returns:
      The result of the underlying Supplier.
    • timeCallable

      public <T> T timeCallable(Callable<T> callable) throws Exception
      Description copied from interface: Timer
      Executes and measures the given Callable and returns its result.
      Specified by:
      timeCallable in interface Timer
      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

      public void time(Runnable runnable)
      Description copied from interface: Timer
      Executes and measures the given Runnable instance.
      Specified by:
      time in interface Timer
      Parameters:
      runnable - The Runnable to execute and measure.
    • unit

      public TimeUnit unit()
      Description copied from interface: Timer
      The TimeUnit of the timer.
      Specified by:
      unit in interface Timer
      Returns:
      The TimeUnit of the timer.
    • toString

      public String toString()
      Overrides:
      toString in class Object