com.lmax.disruptor
Class SingleThreadedClaimStrategy

java.lang.Object
  extended by com.lmax.disruptor.SingleThreadedClaimStrategy
All Implemented Interfaces:
ClaimStrategy

public final class SingleThreadedClaimStrategy
extends java.lang.Object
implements ClaimStrategy

Optimised strategy can be used when there is a single publisher thread claiming sequences. This strategy must not be used when multiple threads are used for publishing concurrently on the same Sequencer


Constructor Summary
SingleThreadedClaimStrategy(int bufferSize)
          Construct a new single threaded publisher ClaimStrategy for a given buffer size.
 
Method Summary
 long checkAndIncrement(int availableCapacity, int delta, Sequence[] dependentSequences)
          Atomically checks the available capacity of the ring buffer and claims the next sequence.
 int getBufferSize()
          Get the size of the data structure used to buffer events.
 long getSequence()
          Get the current claimed sequence.
 boolean hasAvailableCapacity(int availableCapacity, Sequence[] dependentSequences)
          Is there available capacity in the buffer for the requested sequence.
 long incrementAndGet(int delta, Sequence[] dependentSequences)
          Increment sequence by a delta and get the result.
 long incrementAndGet(Sequence[] dependentSequences)
          Claim the next sequence in the Sequencer.
 void serialisePublishing(long sequence, Sequence cursor, int batchSize)
          Serialise publishers in sequence and set cursor to latest available sequence.
 void setSequence(long sequence, Sequence[] dependentSequences)
          Set the current sequence value for claiming an event in the Sequencer The caller should be held up until the claimed sequence is available by tracking the dependentSequences.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleThreadedClaimStrategy

public SingleThreadedClaimStrategy(int bufferSize)
Construct a new single threaded publisher ClaimStrategy for a given buffer size.

Parameters:
bufferSize - for the underlying data structure.
Method Detail

getBufferSize

public int getBufferSize()
Description copied from interface: ClaimStrategy
Get the size of the data structure used to buffer events.

Specified by:
getBufferSize in interface ClaimStrategy
Returns:
size of the underlying buffer.

getSequence

public long getSequence()
Description copied from interface: ClaimStrategy
Get the current claimed sequence.

Specified by:
getSequence in interface ClaimStrategy
Returns:
the current claimed sequence.

hasAvailableCapacity

public boolean hasAvailableCapacity(int availableCapacity,
                                    Sequence[] dependentSequences)
Description copied from interface: ClaimStrategy
Is there available capacity in the buffer for the requested sequence.

Specified by:
hasAvailableCapacity in interface ClaimStrategy
Parameters:
availableCapacity - remaining in the buffer.
dependentSequences - to be checked for range.
Returns:
true if the buffer has capacity for the requested sequence.

incrementAndGet

public long incrementAndGet(Sequence[] dependentSequences)
Description copied from interface: ClaimStrategy
Claim the next sequence in the Sequencer. The caller should be held up until the claimed sequence is available by tracking the dependentSequences.

Specified by:
incrementAndGet in interface ClaimStrategy
Parameters:
dependentSequences - to be checked for range.
Returns:
the index to be used for the publishing.

incrementAndGet

public long incrementAndGet(int delta,
                            Sequence[] dependentSequences)
Description copied from interface: ClaimStrategy
Increment sequence by a delta and get the result. The caller should be held up until the claimed sequence batch is available by tracking the dependentSequences.

Specified by:
incrementAndGet in interface ClaimStrategy
Parameters:
delta - to increment by.
dependentSequences - to be checked for range.
Returns:
the result after incrementing.

setSequence

public void setSequence(long sequence,
                        Sequence[] dependentSequences)
Description copied from interface: ClaimStrategy
Set the current sequence value for claiming an event in the Sequencer The caller should be held up until the claimed sequence is available by tracking the dependentSequences.

Specified by:
setSequence in interface ClaimStrategy
Parameters:
sequence - to be set as the current value.
dependentSequences - to be checked for range.

serialisePublishing

public void serialisePublishing(long sequence,
                                Sequence cursor,
                                int batchSize)
Description copied from interface: ClaimStrategy
Serialise publishers in sequence and set cursor to latest available sequence.

Specified by:
serialisePublishing in interface ClaimStrategy
Parameters:
sequence - sequence to be applied
cursor - to serialise against.
batchSize - of the sequence.

checkAndIncrement

public long checkAndIncrement(int availableCapacity,
                              int delta,
                              Sequence[] dependentSequences)
                       throws InsufficientCapacityException
Description copied from interface: ClaimStrategy
Atomically checks the available capacity of the ring buffer and claims the next sequence. Will throw InsufficientCapacityException if the capacity not available.

Specified by:
checkAndIncrement in interface ClaimStrategy
Parameters:
availableCapacity - the capacity that should be available before claiming the next slot
delta - the number of slots to claim
dependentSequences - the set of sequences to check to ensure capacity is available
Returns:
the slot after incrementing
Throws:
InsufficientCapacityException - thrown if capacity is not available


Copyright © 2011 LMAX Ltd. All Rights Reserved.