com.lmax.disruptor
Class Sequencer

java.lang.Object
  extended by com.lmax.disruptor.Sequencer
Direct Known Subclasses:
RingBuffer

public class Sequencer
extends java.lang.Object

Coordinator for claiming sequences for access to a data structure while tracking dependent Sequences


Field Summary
static long INITIAL_CURSOR_VALUE
          Set to -1 as sequence starting point
 
Constructor Summary
Sequencer(ClaimStrategy claimStrategy, WaitStrategy waitStrategy)
          Construct a Sequencer with the selected strategies.
 
Method Summary
 long claim(long sequence)
          Claim a specific sequence when only one publisher is involved.
 void forcePublish(long sequence)
          Force the publication of a cursor sequence.
 int getBufferSize()
          The capacity of the data structure to hold entries.
 long getCursor()
          Get the value of the cursor indicating the published sequence.
 boolean hasAvailableCapacity(int availableCapacity)
          Has the buffer got capacity to allocate another sequence.
 SequenceBarrier newBarrier(Sequence... sequencesToTrack)
          Create a SequenceBarrier that gates on the the cursor and a list of Sequences
 BatchDescriptor newBatchDescriptor(int size)
          Create a new BatchDescriptor that is the minimum of the requested size and the buffer size.
 long next()
          Claim the next event in sequence for publishing.
 BatchDescriptor next(BatchDescriptor batchDescriptor)
          Claim the next batch of sequence numbers for publishing.
 void publish(BatchDescriptor batchDescriptor)
          Publish the batch of events in sequence.
 void publish(long sequence)
          Publish an event and make it visible to EventProcessors
 long remainingCapacity()
           
 void setGatingSequences(Sequence... sequences)
          Set the sequences that will gate publishers to prevent the buffer wrapping.
 long tryNext(int requiredCapacity)
          Attempt to claim the next event in sequence for publishing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_CURSOR_VALUE

public static final long INITIAL_CURSOR_VALUE
Set to -1 as sequence starting point

See Also:
Constant Field Values
Constructor Detail

Sequencer

public Sequencer(ClaimStrategy claimStrategy,
                 WaitStrategy waitStrategy)
Construct a Sequencer with the selected strategies.

Parameters:
claimStrategy - for those claiming sequences.
waitStrategy - for those waiting on sequences.
Method Detail

setGatingSequences

public void setGatingSequences(Sequence... sequences)
Set the sequences that will gate publishers to prevent the buffer wrapping. This method must be called prior to claiming sequences otherwise a NullPointerException will be thrown.

Parameters:
sequences - to be to be gated on.

newBarrier

public SequenceBarrier newBarrier(Sequence... sequencesToTrack)
Create a SequenceBarrier that gates on the the cursor and a list of Sequences

Parameters:
sequencesToTrack - this barrier will track
Returns:
the barrier gated as required

newBatchDescriptor

public BatchDescriptor newBatchDescriptor(int size)
Create a new BatchDescriptor that is the minimum of the requested size and the buffer size.

Parameters:
size - for the batch
Returns:
the new BatchDescriptor

getBufferSize

public int getBufferSize()
The capacity of the data structure to hold entries.

Returns:
the size of the RingBuffer.

getCursor

public long getCursor()
Get the value of the cursor indicating the published sequence.

Returns:
value of the cursor for events that have been published.

hasAvailableCapacity

public boolean hasAvailableCapacity(int availableCapacity)
Has the buffer got capacity to allocate another sequence. This is a concurrent method so the response should only be taken as an indication of available capacity.

Parameters:
availableCapacity - in the buffer
Returns:
true if the buffer has the capacity to allocate the next sequence otherwise false.

next

public long next()
Claim the next event in sequence for publishing.

Returns:
the claimed sequence value

tryNext

public long tryNext(int requiredCapacity)
             throws InsufficientCapacityException
Attempt to claim the next event in sequence for publishing. Will return the number of the slot if there is at least requiredCapacity slots available.

Parameters:
requiredCapacity - as slots in the data structure
Returns:
the claimed sequence value
Throws:
InsufficientCapacityException - when the requiredCapacity is not available

next

public BatchDescriptor next(BatchDescriptor batchDescriptor)
Claim the next batch of sequence numbers for publishing.

Parameters:
batchDescriptor - to be updated for the batch range.
Returns:
the updated batchDescriptor.

claim

public long claim(long sequence)
Claim a specific sequence when only one publisher is involved.

Parameters:
sequence - to be claimed.
Returns:
sequence just claimed.

publish

public void publish(long sequence)
Publish an event and make it visible to EventProcessors

Parameters:
sequence - to be published

publish

public void publish(BatchDescriptor batchDescriptor)
Publish the batch of events in sequence.

Parameters:
batchDescriptor - to be published.

forcePublish

public void forcePublish(long sequence)
Force the publication of a cursor sequence. Only use this method when forcing a sequence and you are sure only one publisher exists. This will cause the cursor to advance to this sequence.

Parameters:
sequence - which is to be forced for publication.

remainingCapacity

public long remainingCapacity()


Copyright © 2011 LMAX Ltd. All Rights Reserved.