Package io.pravega.common
Class TimeoutTimer
- java.lang.Object
-
- io.pravega.common.TimeoutTimer
-
public class TimeoutTimer extends java.lang.ObjectHelps figuring out how much time is left from a particular (initial) timeout.
-
-
Constructor Summary
Constructors Constructor Description TimeoutTimer(java.time.Duration initialTimeout)Creates a new instance of the TimeoutTimer class.TimeoutTimer(java.time.Duration initialTimeout, java.util.function.Supplier<java.lang.Long> getNanos)Creates a new instance of the TimeoutTimer class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.time.DurationgetElapsed()Returns a Duration of the time elapsed in Nanoseconds.java.time.DurationgetRemaining()Calculates how much time is left of the original timeout.booleanhasRemaining()Returns true if there is time remaining.voidreset(java.time.Duration timeout)Reset the timeout so that the original amount of time is remaining.java.lang.StringtoString()voidzero()Adjust the time so that the is no time remaining.
-
-
-
Constructor Detail
-
TimeoutTimer
public TimeoutTimer(java.time.Duration initialTimeout)
Creates a new instance of the TimeoutTimer class.- Parameters:
initialTimeout- The initial timeout.
-
TimeoutTimer
public TimeoutTimer(java.time.Duration initialTimeout, java.util.function.Supplier<java.lang.Long> getNanos)Creates a new instance of the TimeoutTimer class.- Parameters:
initialTimeout- The initial timeout.getNanos- The supplier of nanoseconds.
-
-
Method Detail
-
getRemaining
public java.time.Duration getRemaining()
Calculates how much time is left of the original timeout.- Returns:
- The remaining time.
-
getElapsed
public java.time.Duration getElapsed()
Returns a Duration of the time elapsed in Nanoseconds.- Returns:
- The elapsed time.
-
hasRemaining
public boolean hasRemaining()
Returns true if there is time remaining.- Returns:
- False if there is no time remaining from the given timeout.
-
reset
public void reset(java.time.Duration timeout)
Reset the timeout so that the original amount of time is remaining. While it is safe to call this concurrently withgetRemaining(), the value returned bygetRemaining()may be wrong. A synchronized block is NOT required to avoid this.- Parameters:
timeout- The duration from now which should be placed on the timer.
-
zero
public void zero()
Adjust the time so that the is no time remaining.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-