Class TimeoutBlockingWaitStrategy

java.lang.Object
org.apache.logging.log4j.core.async.TimeoutBlockingWaitStrategy
All Implemented Interfaces:
com.lmax.disruptor.WaitStrategy

class TimeoutBlockingWaitStrategy extends Object implements com.lmax.disruptor.WaitStrategy
Blocking strategy that uses a lock and condition variable for
invalid reference
EventProcessor
s waiting on a barrier. However, it will periodically wake up if it has been idle for specified period by throwing a TimeoutException. To make use of this, the event handler class should override
invalid reference
EventHandler#onTimeout(long)
, which the
invalid reference
BatchEventProcessor
will call if the timeout occurs.

This strategy can be used when throughput and low-latency are not as important as CPU resource.

  • Field Details

    • mutex

      private final Object mutex
    • timeoutInNanos

      private final long timeoutInNanos
    • ONE_MILLISECOND_IN_NANOSECONDS

      private static final int ONE_MILLISECOND_IN_NANOSECONDS
      See Also:
  • Constructor Details

    • TimeoutBlockingWaitStrategy

      public TimeoutBlockingWaitStrategy(long timeout, TimeUnit units)
      Parameters:
      timeout - how long to wait before waking up
      units - the unit in which timeout is specified
  • Method Details

    • waitFor

      public long waitFor(long sequence, com.lmax.disruptor.Sequence cursorSequence, com.lmax.disruptor.Sequence dependentSequence, com.lmax.disruptor.SequenceBarrier barrier) throws com.lmax.disruptor.AlertException, InterruptedException, com.lmax.disruptor.TimeoutException
      Specified by:
      waitFor in interface com.lmax.disruptor.WaitStrategy
      Throws:
      com.lmax.disruptor.AlertException
      InterruptedException
      com.lmax.disruptor.TimeoutException
    • signalAllWhenBlocking

      public void signalAllWhenBlocking()
      Specified by:
      signalAllWhenBlocking in interface com.lmax.disruptor.WaitStrategy
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • awaitNanos

      private static long awaitNanos(Object mutex, long timeoutNanos) throws InterruptedException
      Parameters:
      mutex - The object to wait on
      timeoutNanos - The number of nanoseconds to wait for
      Returns:
      the number of nanoseconds waited (approximately)
      Throws:
      InterruptedException - if the underlying call to wait is interrupted