Package io.netty.util.concurrent
Interface Ticker
-
- All Known Subinterfaces:
MockTicker
public interface TickerA nanosecond-based time source, e.g.System.nanoTime().
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description longinitialNanoTime()The initial value used for delay and computations based upon a monotonic time source.longnanoTime()The time elapsed since initialization of this class in nanoseconds.static MockTickernewMockTicker()Returns a newly created mockTickerthat allows the caller control the flow of time.voidsleep(long delay, java.util.concurrent.TimeUnit unit)Waits until the given amount of time goes by.default voidsleepMillis(long delayMillis)Waits until the given amount of time goes by.static TickersystemTicker()Returns the singletonTickerthat returns the values from the real system clock source.
-
-
-
Method Detail
-
systemTicker
static Ticker systemTicker()
Returns the singletonTickerthat returns the values from the real system clock source. However, note that this is not the same asSystem.nanoTime()because we apply a fixed offset to thenanoTime.
-
newMockTicker
static MockTicker newMockTicker()
Returns a newly created mockTickerthat allows the caller control the flow of time. This can be useful when you test time-sensitive logic without waiting for too long or introducing flakiness due to non-deterministic nature of system clock.
-
initialNanoTime
long initialNanoTime()
The initial value used for delay and computations based upon a monotonic time source.- Returns:
- initial value used for delay and computations based upon a monotonic time source.
-
nanoTime
long nanoTime()
The time elapsed since initialization of this class in nanoseconds. This may return a negative number just likeSystem.nanoTime().
-
sleep
void sleep(long delay, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionWaits until the given amount of time goes by.- Parameters:
delay- the amount of delay.unit- theTimeUnitofdelay.- Throws:
java.lang.InterruptedException- See Also:
Thread.sleep(long)
-
sleepMillis
default void sleepMillis(long delayMillis) throws java.lang.InterruptedExceptionWaits until the given amount of time goes by.- Parameters:
delayMillis- the number of milliseconds.- Throws:
java.lang.InterruptedException- See Also:
Thread.sleep(long)
-
-