Package com.lmax.disruptor
Interface Sequenced
- All Known Subinterfaces:
EventSequencer<T>,Sequencer
- All Known Implementing Classes:
AbstractSequencer,MultiProducerSequencer,RingBuffer,SingleProducerSequencer,SingleProducerSequencerFields,SingleProducerSequencerPad
public interface Sequenced
-
Method Summary
Modifier and TypeMethodDescriptionintThe capacity of the data structure to hold entries.booleanhasAvailableCapacity(int requiredCapacity) Has the buffer got capacity to allocate another sequence.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.
-
Method Details
-
getBufferSize
int getBufferSize()The capacity of the data structure to hold entries.- Returns:
- the size of the RingBuffer.
-
hasAvailableCapacity
boolean hasAvailableCapacity(int requiredCapacity) 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:
requiredCapacity- in the buffer- Returns:
- true if the buffer has the capacity to allocate the next sequence otherwise false.
-
remainingCapacity
long remainingCapacity()Get the remaining capacity for this sequencer.- Returns:
- The number of slots remaining.
-
next
long next()Claim the next event in sequence for publishing.- Returns:
- the claimed sequence value
-
next
long next(int n) Claim 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
-
tryNext
Attempt 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.
-
tryNext
Attempt 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 atnext()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.
-
publish
void publish(long sequence) Publishes a sequence. Call when the event has been filled.- Parameters:
sequence- the sequence to be published.
-
publish
void publish(long lo, long hi) Batch publish sequences. Called when all of the events have been filled.- Parameters:
lo- first sequence number to publishhi- last sequence number to publish
-