Class TimeoutBlockingWaitStrategy
- java.lang.Object
-
- org.apache.logging.log4j.core.async.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 forEventProcessor
s waiting on a barrier. However, it will periodically wake up if it has been idle for specified period by throwing aTimeoutException
. To make use of this, the event handler class should overrideEventHandler#onTimeout(long)
, which theBatchEventProcessor
will call if the timeout occurs.This strategy can be used when throughput and low-latency are not as important as CPU resource.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
mutex
private static int
ONE_MILLISECOND_IN_NANOSECONDS
private long
timeoutInNanos
-
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)
-
-
-
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
-
-
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 interfacecom.lmax.disruptor.WaitStrategy
- Throws:
com.lmax.disruptor.AlertException
java.lang.InterruptedException
com.lmax.disruptor.TimeoutException
-
signalAllWhenBlocking
public void signalAllWhenBlocking()
- Specified by:
signalAllWhenBlocking
in interfacecom.lmax.disruptor.WaitStrategy
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
awaitNanos
private static long awaitNanos(java.lang.Object mutex, long timeoutNanos) throws java.lang.InterruptedException
- Parameters:
mutex
- The object to wait ontimeoutNanos
- 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
-
-