com.lmax.disruptor
Interface ClaimStrategy

All Known Implementing Classes:
AbstractMultithreadedClaimStrategy, MultiThreadedClaimStrategy, MultiThreadedLowContentionClaimStrategy, SingleThreadedClaimStrategy

public interface ClaimStrategy

Strategy contract for claiming the sequence of events in the Sequencer by event publishers.


Method Summary
 long checkAndIncrement(int availableCapacity, int delta, Sequence[] gatingSequences)
          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.
 

Method Detail

getBufferSize

int getBufferSize()
Get the size of the data structure used to buffer events.

Returns:
size of the underlying buffer.

getSequence

long getSequence()
Get the current claimed sequence.

Returns:
the current claimed sequence.

hasAvailableCapacity

boolean hasAvailableCapacity(int availableCapacity,
                             Sequence[] dependentSequences)
Is there available capacity in the buffer for the requested sequence.

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

incrementAndGet

long incrementAndGet(Sequence[] dependentSequences)
Claim the next sequence in the Sequencer. The caller should be held up until the claimed sequence is available by tracking the dependentSequences.

Parameters:
dependentSequences - to be checked for range.
Returns:
the index to be used for the publishing.

incrementAndGet

long incrementAndGet(int delta,
                     Sequence[] dependentSequences)
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.

Parameters:
delta - to increment by.
dependentSequences - to be checked for range.
Returns:
the result after incrementing.

setSequence

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.

Parameters:
dependentSequences - to be checked for range.
sequence - to be set as the current value.

serialisePublishing

void serialisePublishing(long sequence,
                         Sequence cursor,
                         int batchSize)
Serialise publishers in sequence and set cursor to latest available sequence.

Parameters:
sequence - sequence to be applied
cursor - to serialise against.
batchSize - of the sequence.

checkAndIncrement

long checkAndIncrement(int availableCapacity,
                       int delta,
                       Sequence[] gatingSequences)
                       throws InsufficientCapacityException
Atomically checks the available capacity of the ring buffer and claims the next sequence. Will throw InsufficientCapacityException if the capacity not available.

Parameters:
availableCapacity - the capacity that should be available before claiming the next slot
delta - the number of slots to claim
gatingSequences - 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.