com.lmax.disruptor
Class SleepingWaitStrategy

java.lang.Object
  extended by com.lmax.disruptor.SleepingWaitStrategy
All Implemented Interfaces:
WaitStrategy

public final class SleepingWaitStrategy
extends java.lang.Object
implements WaitStrategy

Sleeping strategy that initially spins, then uses a Thread.yield(), and eventually for the minimum number of nanos the OS and JVM will allow while the EventProcessors are waiting on a barrier. This strategy is a good compromise between performance and CPU resource. Latency spikes can occur after quiet periods.


Constructor Summary
SleepingWaitStrategy()
           
 
Method Summary
 void signalAllWhenBlocking()
          Signal those EventProcessors waiting that the cursor has advanced.
 long waitFor(long sequence, Sequence cursor, Sequence[] dependents, SequenceBarrier barrier)
          Wait for the given sequence to be available
 long waitFor(long sequence, Sequence cursor, Sequence[] dependents, SequenceBarrier barrier, long timeout, java.util.concurrent.TimeUnit sourceUnit)
          Wait for the given sequence to be available with a timeout specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SleepingWaitStrategy

public SleepingWaitStrategy()
Method Detail

waitFor

public long waitFor(long sequence,
                    Sequence cursor,
                    Sequence[] dependents,
                    SequenceBarrier barrier)
             throws AlertException,
                    java.lang.InterruptedException
Description copied from interface: WaitStrategy
Wait for the given sequence to be available

Specified by:
waitFor in interface WaitStrategy
Parameters:
sequence - to be waited on.
cursor - on which to wait.
dependents - further back the chain that must advance first
barrier - the processor is waiting on.
Returns:
the sequence that is available which may be greater than the requested sequence.
Throws:
AlertException - if the status of the Disruptor has changed.
java.lang.InterruptedException - if the thread is interrupted.

waitFor

public long waitFor(long sequence,
                    Sequence cursor,
                    Sequence[] dependents,
                    SequenceBarrier barrier,
                    long timeout,
                    java.util.concurrent.TimeUnit sourceUnit)
             throws AlertException,
                    java.lang.InterruptedException
Description copied from interface: WaitStrategy
Wait for the given sequence to be available with a timeout specified.

Specified by:
waitFor in interface WaitStrategy
Parameters:
sequence - to be waited on.
cursor - on which to wait.
dependents - further back the chain that must advance first
barrier - the processor is waiting on.
timeout - value to abort after.
sourceUnit - of the timeout value.
Returns:
the sequence that is available which may be greater than the requested sequence.
Throws:
AlertException - if the status of the Disruptor has changed.
java.lang.InterruptedException - if the thread is interrupted.

signalAllWhenBlocking

public void signalAllWhenBlocking()
Description copied from interface: WaitStrategy
Signal those EventProcessors waiting that the cursor has advanced.

Specified by:
signalAllWhenBlocking in interface WaitStrategy


Copyright © 2011 LMAX Ltd. All Rights Reserved.