Package com.yahoo.time
Class TimeBudget
- java.lang.Object
-
- com.yahoo.time.TimeBudget
-
public class TimeBudget extends java.lang.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 java.util.Optional<java.time.Instant>
deadline()
Returns the deadline, if present.static TimeBudget
from(java.time.Clock clock, java.time.Instant start, java.util.Optional<java.time.Duration> timeout)
static TimeBudget
fromNow(java.time.Clock clock, java.time.Duration timeout)
Returns a TimeBudget with a start time of now, and with the given timeout.java.util.Optional<java.time.Duration>
originalTimeout()
Returns the original timeout, if any.java.util.Optional<java.time.Duration>
timeLeft()
Returns the time left, possibly negative if the deadline has passed.TimeBudget
timeLeftAsTimeBudget()
Returns the time left as a new TimeBudget.java.util.Optional<java.time.Duration>
timeLeftOrThrow()
Returns the time until deadline, if there is one.java.time.Duration
timePassed()
Returns time since start.TimeBudget
withDeadline(java.time.Instant deadline)
Returns a new TimeBudget with the same clock and start, but with this deadline.
-
-
-
Method Detail
-
fromNow
public static TimeBudget fromNow(java.time.Clock clock, java.time.Duration timeout)
Returns a TimeBudget with a start time of now, and with the given timeout.
-
from
public static TimeBudget from(java.time.Clock clock, java.time.Instant start, java.util.Optional<java.time.Duration> timeout)
-
timePassed
public java.time.Duration timePassed()
Returns time since start.
-
originalTimeout
public java.util.Optional<java.time.Duration> originalTimeout()
Returns the original timeout, if any.
-
deadline
public java.util.Optional<java.time.Instant> deadline()
Returns the deadline, if present.
-
timeLeftOrThrow
public java.util.Optional<java.time.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 java.util.Optional<java.time.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(java.time.Instant deadline)
Returns a new TimeBudget with the same clock and start, but with this deadline.
-
-