Class DefaultMockTicker

java.lang.Object
io.netty.util.concurrent.DefaultMockTicker
All Implemented Interfaces:
MockTicker, Ticker

final class DefaultMockTicker extends java.lang.Object implements MockTicker
The default MockTicker implementation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final java.util.concurrent.locks.ReentrantLock
     
    private final java.util.concurrent.atomic.AtomicLong
     
    private final java.util.concurrent.locks.Condition
     
    private final java.util.Set<java.lang.Thread>
     
    private final java.util.concurrent.locks.Condition
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advance(long amount, java.util.concurrent.TimeUnit unit)
    Advances the current Ticker.nanoTime() by the given amount of time.
    void
    awaitSleepingThread(java.lang.Thread thread)
    Wait for the given thread to enter the sleep(long, TimeUnit) method, and block.
    long
    The time elapsed since initialization of this class in nanoseconds.
    void
    sleep(long delay, java.util.concurrent.TimeUnit unit)
    Waits until the given amount of time goes by.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface MockTicker

    advanceMillis, initialNanoTime

    Methods inherited from interface Ticker

    sleepMillis
  • Field Details

    • lock

      private final java.util.concurrent.locks.ReentrantLock lock
    • tickCondition

      private final java.util.concurrent.locks.Condition tickCondition
    • sleeperCondition

      private final java.util.concurrent.locks.Condition sleeperCondition
    • nanoTime

      private final java.util.concurrent.atomic.AtomicLong nanoTime
    • sleepers

      private final java.util.Set<java.lang.Thread> sleepers
  • Constructor Details

    • DefaultMockTicker

      DefaultMockTicker()
  • Method Details

    • nanoTime

      public long nanoTime()
      Description copied from interface: Ticker
      The time elapsed since initialization of this class in nanoseconds. This may return a negative number just like System.nanoTime().
      Specified by:
      nanoTime in interface Ticker
    • sleep

      public void sleep(long delay, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
      Description copied from interface: Ticker
      Waits until the given amount of time goes by.
      Specified by:
      sleep in interface Ticker
      Parameters:
      delay - the amount of delay.
      unit - the TimeUnit of delay.
      Throws:
      java.lang.InterruptedException
      See Also:
      • Thread.sleep(long)
    • awaitSleepingThread

      public void awaitSleepingThread(java.lang.Thread thread) throws java.lang.InterruptedException
      Wait for the given thread to enter the sleep(long, TimeUnit) method, and block.
      Throws:
      java.lang.InterruptedException
    • advance

      public void advance(long amount, java.util.concurrent.TimeUnit unit)
      Description copied from interface: MockTicker
      Advances the current Ticker.nanoTime() by the given amount of time.
      Specified by:
      advance in interface MockTicker
      Parameters:
      amount - the amount of time to advance this ticker by.
      unit - the TimeUnit of amount.