Package com.lmax.disruptor
Class SingleProducerSequencer
java.lang.Object
com.lmax.disruptor.AbstractSequencer
com.lmax.disruptor.SingleProducerSequencerPad
com.lmax.disruptor.SingleProducerSequencerFields
com.lmax.disruptor.SingleProducerSequencer
Coordinator for claiming sequences for access to a data structure while tracking dependent Sequences.
Not safe for use from multiple threads as it does not implement any barriers.
* Note on Cursored.getCursor(): With this sequencer the cursor value is updated after the call
to Sequenced.publish(long) is made.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected longprotected longprotected longprotected longprotected longprotected longFields inherited from class com.lmax.disruptor.SingleProducerSequencerFields
cachedValue, nextValueFields inherited from class com.lmax.disruptor.AbstractSequencer
bufferSize, cursor, gatingSequences, waitStrategyFields inherited from interface com.lmax.disruptor.Sequencer
INITIAL_CURSOR_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionSingleProducerSequencer(int bufferSize, WaitStrategy waitStrategy) Construct a Sequencer with the selected wait strategy and buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclaim(long sequence) Claim a specific sequence.longgetHighestPublishedSequence(long lowerBound, long availableSequence) Get the highest sequence number that can be safely read from the ring buffer.booleanhasAvailableCapacity(int requiredCapacity) Has the buffer got capacity to allocate another sequence.private booleanhasAvailableCapacity(int requiredCapacity, boolean doStore) booleanisAvailable(long sequence) Confirms if a sequence is published and the event is available for use; non-blocking.longnext()Claim the next event in sequence for publishing.longnext(int n) Claim the next n events in sequence for publishing.voidpublish(long sequence) Publishes a sequence.voidpublish(long lo, long hi) Batch publish sequences.longGet the remaining capacity for this sequencer.longtryNext()Attempt to claim the next event in sequence for publishing.longtryNext(int n) Attempt to claim the next n events in sequence for publishing.Methods inherited from class com.lmax.disruptor.AbstractSequencer
addGatingSequences, getBufferSize, getCursor, getMinimumSequence, newBarrier, newPoller, removeGatingSequence, toString
-
Field Details
-
p1
protected long p1 -
p2
protected long p2 -
p3
protected long p3 -
p4
protected long p4 -
p5
protected long p5 -
p6
protected long p6 -
p7
protected long p7
-
-
Constructor Details
-
SingleProducerSequencer
Construct a Sequencer with the selected wait strategy and buffer size.- Parameters:
bufferSize- the size of the buffer that this will sequence over.waitStrategy- for those waiting on sequences.
-
-
Method Details
-
hasAvailableCapacity
public boolean hasAvailableCapacity(int requiredCapacity) Description copied from interface:SequencedHas 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:
requiredCapacity- in the buffer- Returns:
- true if the buffer has the capacity to allocate the next sequence otherwise false.
- See Also:
-
hasAvailableCapacity
private boolean hasAvailableCapacity(int requiredCapacity, boolean doStore) -
next
public long next()Description copied from interface:SequencedClaim the next event in sequence for publishing.- Returns:
- the claimed sequence value
- See Also:
-
next
public long next(int n) Description copied from interface:SequencedClaim the next n events in sequence for publishing. This is for batch event producing. Using batch producing requires a little care and some math.int n = 10; long hi = sequencer.next(n); long lo = hi - (n - 1); for (long sequence = lo; sequence <= hi; sequence++) { // Do work. } sequencer.publish(lo, hi);- Parameters:
n- the number of sequences to claim- Returns:
- the highest claimed sequence value
- See Also:
-
tryNext
Description copied from interface:SequencedAttempt to claim the next event in sequence for publishing. Will return the number of the slot if there is at leastrequiredCapacityslots available.- Returns:
- the claimed sequence value
- Throws:
InsufficientCapacityException- thrown if there is no space available in the ring buffer.- See Also:
-
tryNext
Description copied from interface:SequencedAttempt to claim the next n events in sequence for publishing. Will return the highest numbered slot if there is at leastrequiredCapacityslots available. Have a look atSequenced.next()for a description on how to use this method.- Parameters:
n- the number of sequences to claim- Returns:
- the claimed sequence value
- Throws:
InsufficientCapacityException- thrown if there is no space available in the ring buffer.- See Also:
-
remainingCapacity
public long remainingCapacity()Description copied from interface:SequencedGet the remaining capacity for this sequencer.- Returns:
- The number of slots remaining.
- See Also:
-
claim
public void claim(long sequence) Description copied from interface:SequencerClaim a specific sequence. Only used if initialising the ring buffer to a specific value.- Parameters:
sequence- The sequence to initialise too.- See Also:
-
publish
public void publish(long sequence) Description copied from interface:SequencedPublishes a sequence. Call when the event has been filled.- Parameters:
sequence- the sequence to be published.- See Also:
-
publish
public void publish(long lo, long hi) Description copied from interface:SequencedBatch publish sequences. Called when all of the events have been filled.- Parameters:
lo- first sequence number to publishhi- last sequence number to publish- See Also:
-
isAvailable
public boolean isAvailable(long sequence) Description copied from interface:SequencerConfirms if a sequence is published and the event is available for use; non-blocking.- Parameters:
sequence- of the buffer to check- Returns:
- true if the sequence is available for use, false if not
- See Also:
-
getHighestPublishedSequence
public long getHighestPublishedSequence(long lowerBound, long availableSequence) Description copied from interface:SequencerGet the highest sequence number that can be safely read from the ring buffer. Depending on the implementation of the Sequencer this call may need to scan a number of values in the Sequencer. The scan will range from nextSequence to availableSequence. If there are no available values>= nextSequencethe return value will benextSequence - 1. To work correctly a consumer should pass a value that is 1 higher than the last sequence that was successfully processed.- Parameters:
lowerBound- The sequence to start scanning from.availableSequence- The sequence to scan to.- Returns:
- The highest value that can be safely read, will be at least
nextSequence - 1.
-