-
- All Known Subinterfaces:
EventSequencer<T>
,Sequencer
- All Known Implementing Classes:
AbstractSequencer
,MultiProducerSequencer
,RingBuffer
,SingleProducerSequencer
public interface Sequenced
Operations related to the sequencing of items in aRingBuffer
. See the two child interfaces,Sequencer
andEventSequencer
for more details.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
getBufferSize()
The capacity of the data structure to hold entries.boolean
hasAvailableCapacity(int requiredCapacity)
Has the buffer got capacity to allocate another sequence.long
next()
Claim the next event in sequence for publishing.long
next(int n)
Claim the next n events in sequence for publishing.void
publish(long sequence)
Publishes a sequence.void
publish(long lo, long hi)
Batch publish sequences.long
remainingCapacity()
Get the remaining capacity for this sequencer.long
tryNext()
Attempt to claim the next event in sequence for publishing.long
tryNext(int n)
Attempt to claim the next n events in sequence for publishing.
-
-
-
Method Detail
-
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
long tryNext() throws InsufficientCapacityException
Attempt to claim the next event in sequence for publishing. Will return the number of the slot if there is at leastrequiredCapacity
slots available.- Returns:
- the claimed sequence value
- Throws:
InsufficientCapacityException
- thrown if there is no space available in the ring buffer.
-
tryNext
long tryNext(int n) throws InsufficientCapacityException
Attempt to claim the next n events in sequence for publishing. Will return the highest numbered slot if there is at leastrequiredCapacity
slots 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
-
-