Class TimeBudget

java.lang.Object
com.yahoo.time.TimeBudget

public class TimeBudget extends Object
A TimeBudget can be used to track the time of an ongoing operation, possibly with a timeout.
Author:
hakon
  • Method Details

    • fromNow

      public static TimeBudget fromNow(Clock clock, Duration timeout)
      Returns a TimeBudget with a start time of now, and with the given timeout.
    • from

      public static TimeBudget from(Clock clock, Instant start, Optional<Duration> timeout)
    • timePassed

      public Duration timePassed()
      Returns time since start.
    • originalTimeout

      public Optional<Duration> originalTimeout()
      Returns the original timeout, if any.
    • deadline

      public Optional<Instant> deadline()
      Returns the deadline, if present.
    • timeLeftOrThrow

      public Optional<Duration> timeLeftOrThrow()
      Returns the time until deadline, if there is one.
      Returns:
      time until deadline. It's toMillis() is guaranteed to be positive.
      Throws:
      UncheckedTimeoutException - if the deadline has been reached or passed.
    • timeLeft

      public Optional<Duration> timeLeft()
      Returns the time left, possibly negative if the deadline has passed.
    • timeLeftAsTimeBudget

      public TimeBudget timeLeftAsTimeBudget()
      Returns the time left as a new TimeBudget.
    • withDeadline

      public TimeBudget withDeadline(Instant deadline)
      Returns a new TimeBudget with the same clock and start, but with this deadline.
    • withReserved

      public TimeBudget withReserved(Duration chunk)
      Returns a new TimeBudget with the given duration chopped off, reserved for something else.