Class TimeoutBlockingWaitStrategy

  • All Implemented Interfaces:
    com.lmax.disruptor.WaitStrategy

    class TimeoutBlockingWaitStrategy
    extends java.lang.Object
    implements com.lmax.disruptor.WaitStrategy
    Blocking strategy that uses a lock and condition variable for EventProcessors 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 EventHandler#onTimeout(long), which the BatchEventProcessor will call if the timeout occurs.

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

    • Constructor Summary

      Constructors 
      Constructor Description
      TimeoutBlockingWaitStrategy​(long timeout, java.util.concurrent.TimeUnit units)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static long awaitNanos​(java.lang.Object mutex, long timeoutNanos)  
      void signalAllWhenBlocking()  
      java.lang.String toString()  
      long waitFor​(long sequence, com.lmax.disruptor.Sequence cursorSequence, com.lmax.disruptor.Sequence dependentSequence, com.lmax.disruptor.SequenceBarrier barrier)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • mutex

        private final java.lang.Object mutex
      • timeoutInNanos

        private final long timeoutInNanos
      • ONE_MILLISECOND_IN_NANOSECONDS

        private static final int ONE_MILLISECOND_IN_NANOSECONDS
        See Also:
        Constant Field Values
    • Constructor Detail

      • TimeoutBlockingWaitStrategy

        public TimeoutBlockingWaitStrategy​(long timeout,
                                           java.util.concurrent.TimeUnit units)
        Parameters:
        timeout - how long to wait before waking up
        units - the unit in which timeout is specified
    • Method Detail

      • 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,
                            java.lang.InterruptedException,
                            com.lmax.disruptor.TimeoutException
        Specified by:
        waitFor in interface com.lmax.disruptor.WaitStrategy
        Throws:
        com.lmax.disruptor.AlertException
        java.lang.InterruptedException
        com.lmax.disruptor.TimeoutException
      • signalAllWhenBlocking

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

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

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