Class 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 Detail

      • fromNow

        public static TimeBudget fromNow​(Clock clock,
                                         Duration timeout)
        Returns a TimeBudget with a start time of now, and with the given 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:
        com.google.common.util.concurrent.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.