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.WaitStrategyBlocking strategy that uses a lock and condition variable forEventProcessors 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 theBatchEventProcessorwill 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.Objectmutexprivate static intONE_MILLISECOND_IN_NANOSECONDSprivate longtimeoutInNanos
-
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 longawaitNanos(java.lang.Object mutex, long timeoutNanos)voidsignalAllWhenBlocking()java.lang.StringtoString()longwaitFor(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:
waitForin interfacecom.lmax.disruptor.WaitStrategy- Throws:
com.lmax.disruptor.AlertExceptionjava.lang.InterruptedExceptioncom.lmax.disruptor.TimeoutException
-
signalAllWhenBlocking
public void signalAllWhenBlocking()
- Specified by:
signalAllWhenBlockingin interfacecom.lmax.disruptor.WaitStrategy
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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
-
-