Package com.yahoo.time
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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<Instant>
deadline()
Returns the deadline, if present.static TimeBudget
from(Clock clock, Instant start, Optional<Duration> timeout)
static TimeBudget
fromNow(Clock clock, Duration timeout)
Returns a TimeBudget with a start time of now, and with the given timeout.Optional<Duration>
originalTimeout()
Returns the original timeout, if any.Optional<Duration>
timeLeft()
Returns the time left, possibly negative if the deadline has passed.TimeBudget
timeLeftAsTimeBudget()
Returns the time left as a new TimeBudget.Optional<Duration>
timeLeftOrThrow()
Returns the time until deadline, if there is one.Duration
timePassed()
Returns time since start.TimeBudget
withDeadline(Instant deadline)
Returns a new TimeBudget with the same clock and start, but with this deadline.
-
-
-
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.
-
from
public static TimeBudget from(Clock clock, Instant start, Optional<Duration> timeout)
-
timePassed
public Duration timePassed()
Returns time since start.
-
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.
-
-