E
- implementation storing the data for sharing during exchange or parallel coordination of an event.public final class RingBuffer<E> extends Object implements Cursored, DataProvider<E>
EventProcessor
s.Modifier and Type | Field and Description |
---|---|
static long |
INITIAL_CURSOR_VALUE |
Modifier and Type | Method and Description |
---|---|
void |
addGatingSequences(Sequence... gatingSequences)
Add the specified gating sequences to this instance of the Disruptor.
|
E |
claimAndGetPreallocated(long sequence)
Sets the cursor to a specific sequence and returns the preallocated entry that is stored there.
|
static <E> RingBuffer<E> |
create(ProducerType producerType,
EventFactory<E> factory,
int bufferSize,
WaitStrategy waitStrategy)
Create a new Ring Buffer with the specified producer type (SINGLE or MULTI)
|
static <E> RingBuffer<E> |
createMultiProducer(EventFactory<E> factory,
int bufferSize)
Create a new multiple producer RingBuffer using the default wait strategy
BlockingWaitStrategy . |
static <E> RingBuffer<E> |
createMultiProducer(EventFactory<E> factory,
int bufferSize,
WaitStrategy waitStrategy)
Create a new multiple producer RingBuffer with the specified wait strategy.
|
static <E> RingBuffer<E> |
createSingleProducer(EventFactory<E> factory,
int bufferSize)
Create a new single producer RingBuffer using the default wait strategy
BlockingWaitStrategy . |
static <E> RingBuffer<E> |
createSingleProducer(EventFactory<E> factory,
int bufferSize,
WaitStrategy waitStrategy)
Create a new single producer RingBuffer with the specified wait strategy.
|
E |
get(long sequence)
Get the event for a given sequence in the RingBuffer.
|
int |
getBufferSize()
The size of the buffer.
|
long |
getCursor()
Get the current cursor value for the ring buffer.
|
long |
getMinimumGatingSequence()
Get the minimum sequence value from all of the gating sequences
added to this ringBuffer.
|
E |
getPreallocated(long sequence)
Deprecated.
Use
get(long) |
E |
getPublished(long sequence)
Deprecated.
Use
get(long) |
boolean |
hasAvailableCapacity(int requiredCapacity)
Given specified requiredCapacity determines if that amount of space
is available.
|
boolean |
isPublished(long sequence)
Determines if a particular entry has been published.
|
SequenceBarrier |
newBarrier(Sequence... sequencesToTrack)
Create a new SequenceBarrier to be used by an EventProcessor to track which messages
are available to be read from the ring buffer given a list of sequences to track.
|
long |
next()
Increment and return the next sequence for the ring buffer.
|
long |
next(int n)
The same functionality as
next() , but allows the caller to claim
the next n sequences. |
void |
publish(long sequence)
Publish the specified sequence.
|
void |
publish(long lo,
long hi)
Publish the specified sequences.
|
void |
publishEvent(EventTranslator<E> translator)
Publishes an event to the ring buffer.
|
<A> void |
publishEvent(EventTranslatorOneArg<E,A> translator,
A arg0)
Allows one user supplied argument.
|
<A,B,C> void |
publishEvent(EventTranslatorThreeArg<E,A,B,C> translator,
A arg0,
B arg1,
C arg2)
Allows three user supplied arguments
|
<A,B> void |
publishEvent(EventTranslatorTwoArg<E,A,B> translator,
A arg0,
B arg1)
Allows two user supplied arguments.
|
void |
publishEvent(EventTranslatorVararg<E> translator,
Object... args)
Allows a variable number of user supplied arguments
|
void |
publishEvents(EventTranslator<E>[] translators)
Publishes multiple events to the ring buffer.
|
void |
publishEvents(EventTranslator<E>[] translators,
int batchStartsAt,
int batchSize)
Publishes multiple events to the ring buffer.
|
<A> void |
publishEvents(EventTranslatorOneArg<E,A> translator,
A[] arg0)
Allows one user supplied argument per event.
|
<A> void |
publishEvents(EventTranslatorOneArg<E,A> translator,
int batchStartsAt,
int batchSize,
A[] arg0)
Allows one user supplied argument per event.
|
<A,B,C> void |
publishEvents(EventTranslatorThreeArg<E,A,B,C> translator,
A[] arg0,
B[] arg1,
C[] arg2)
Allows three user supplied arguments per event.
|
<A,B,C> void |
publishEvents(EventTranslatorThreeArg<E,A,B,C> translator,
int batchStartsAt,
int batchSize,
A[] arg0,
B[] arg1,
C[] arg2)
Allows three user supplied arguments per event.
|
<A,B> void |
publishEvents(EventTranslatorTwoArg<E,A,B> translator,
A[] arg0,
B[] arg1)
Allows two user supplied arguments per event.
|
<A,B> void |
publishEvents(EventTranslatorTwoArg<E,A,B> translator,
int batchStartsAt,
int batchSize,
A[] arg0,
B[] arg1)
Allows two user supplied arguments per event.
|
void |
publishEvents(EventTranslatorVararg<E> translator,
int batchStartsAt,
int batchSize,
Object[]... args)
Allows a variable number of user supplied arguments per event.
|
void |
publishEvents(EventTranslatorVararg<E> translator,
Object[]... args)
Allows a variable number of user supplied arguments per event.
|
long |
remainingCapacity()
Get the remaining capacity for this ringBuffer.
|
boolean |
removeGatingSequence(Sequence sequence)
Remove the specified sequence from this ringBuffer.
|
void |
resetTo(long sequence)
Resets the cursor to a specific value.
|
long |
tryNext()
Increment and return the next sequence for the ring buffer.
|
long |
tryNext(int n)
The same functionality as
tryNext() , but allows the caller to attempt
to claim the next n sequences. |
boolean |
tryPublishEvent(EventTranslator<E> translator)
Attempts to publish an event to the ring buffer.
|
<A> boolean |
tryPublishEvent(EventTranslatorOneArg<E,A> translator,
A arg0)
Allows one user supplied argument.
|
<A,B,C> boolean |
tryPublishEvent(EventTranslatorThreeArg<E,A,B,C> translator,
A arg0,
B arg1,
C arg2)
Allows three user supplied arguments
|
<A,B> boolean |
tryPublishEvent(EventTranslatorTwoArg<E,A,B> translator,
A arg0,
B arg1)
Allows two user supplied arguments.
|
boolean |
tryPublishEvent(EventTranslatorVararg<E> translator,
Object... args)
Allows a variable number of user supplied arguments
|
boolean |
tryPublishEvents(EventTranslator<E>[] translators)
Attempts to publish multiple events to the ring buffer.
|
boolean |
tryPublishEvents(EventTranslator<E>[] translators,
int batchStartsAt,
int batchSize)
Attempts to publish multiple events to the ring buffer.
|
<A> boolean |
tryPublishEvents(EventTranslatorOneArg<E,A> translator,
A[] arg0)
Allows one user supplied argument.
|
<A> boolean |
tryPublishEvents(EventTranslatorOneArg<E,A> translator,
int batchStartsAt,
int batchSize,
A[] arg0)
Allows one user supplied argument.
|
<A,B,C> boolean |
tryPublishEvents(EventTranslatorThreeArg<E,A,B,C> translator,
A[] arg0,
B[] arg1,
C[] arg2)
Allows three user supplied arguments per event.
|
<A,B,C> boolean |
tryPublishEvents(EventTranslatorThreeArg<E,A,B,C> translator,
int batchStartsAt,
int batchSize,
A[] arg0,
B[] arg1,
C[] arg2)
Allows three user supplied arguments per event.
|
<A,B> boolean |
tryPublishEvents(EventTranslatorTwoArg<E,A,B> translator,
A[] arg0,
B[] arg1)
Allows two user supplied arguments per event.
|
<A,B> boolean |
tryPublishEvents(EventTranslatorTwoArg<E,A,B> translator,
int batchStartsAt,
int batchSize,
A[] arg0,
B[] arg1)
Allows two user supplied arguments per event.
|
boolean |
tryPublishEvents(EventTranslatorVararg<E> translator,
int batchStartsAt,
int batchSize,
Object[]... args)
Allows a variable number of user supplied arguments per event.
|
boolean |
tryPublishEvents(EventTranslatorVararg<E> translator,
Object[]... args)
Allows a variable number of user supplied arguments per event.
|
public static final long INITIAL_CURSOR_VALUE
public static <E> RingBuffer<E> createMultiProducer(EventFactory<E> factory, int bufferSize, WaitStrategy waitStrategy)
factory
- used to create the events within the ring buffer.bufferSize
- number of elements to create within the ring buffer.waitStrategy
- used to determine how to wait for new elements to become available.IllegalArgumentException
- if bufferSize is less than 1 or not a power of 2MultiProducerSequencer
public static <E> RingBuffer<E> createMultiProducer(EventFactory<E> factory, int bufferSize)
BlockingWaitStrategy
.factory
- used to create the events within the ring buffer.bufferSize
- number of elements to create within the ring buffer.IllegalArgumentException
- if bufferSize is less than 1 or not a power of 2MultiProducerSequencer
public static <E> RingBuffer<E> createSingleProducer(EventFactory<E> factory, int bufferSize, WaitStrategy waitStrategy)
factory
- used to create the events within the ring buffer.bufferSize
- number of elements to create within the ring buffer.waitStrategy
- used to determine how to wait for new elements to become available.IllegalArgumentException
- if bufferSize is less than 1 or not a power of 2SingleProducerSequencer
public static <E> RingBuffer<E> createSingleProducer(EventFactory<E> factory, int bufferSize)
BlockingWaitStrategy
.factory
- used to create the events within the ring buffer.bufferSize
- number of elements to create within the ring buffer.IllegalArgumentException
- if bufferSize is less than 1 or not a power of 2MultiProducerSequencer
public static <E> RingBuffer<E> create(ProducerType producerType, EventFactory<E> factory, int bufferSize, WaitStrategy waitStrategy)
producerType
- producer type to use ProducerType
.factory
- used to create events within the ring buffer.bufferSize
- number of elements to create within the ring buffer.waitStrategy
- used to determine how to wait for new elements to become available.IllegalArgumentException
- if bufferSize is less than 1 or not a power of 2public E get(long sequence)
Get the event for a given sequence in the RingBuffer.
This call has 2 uses. Firstly use this call when publishing to a ring buffer.
After calling next()
use this call to get hold of the
preallocated event to fill with data before calling publish(long)
.
Secondly use this call when consuming data from the ring buffer. After calling
SequenceBarrier.waitFor(long)
call this method with any value greater than
that your current consumer sequence and less than or equal to the value returned from
the SequenceBarrier.waitFor(long)
method.
get
in interface DataProvider<E>
sequence
- for the event@Deprecated public E getPreallocated(long sequence)
get(long)
@Deprecated public E getPublished(long sequence)
get(long)
public long next()
long sequence = ringBuffer.next(); try { Event e = ringBuffer.get(sequence); // Do some work with the event. } finally { ringBuffer.publish(sequence); }
publish(long)
,
get(long)
public long next(int n)
next()
, but allows the caller to claim
the next n sequences.n
- number of slots to claimSequencer.next(int)
public long tryNext() throws InsufficientCapacityException
Increment and return the next sequence for the ring buffer. Calls of this method should ensure that they always publish the sequence afterward. E.g.
long sequence = ringBuffer.next(); try { Event e = ringBuffer.get(sequence); // Do some work with the event. } finally { ringBuffer.publish(sequence); }
This method will not block if there is not space available in the ring
buffer, instead it will throw an InsufficientCapacityException
.
InsufficientCapacityException
- if the necessary space in the ring buffer is not availablepublish(long)
,
get(long)
public long tryNext(int n) throws InsufficientCapacityException
tryNext()
, but allows the caller to attempt
to claim the next n sequences.n
- number of slots to claimInsufficientCapacityException
- if the necessary space in the ring buffer is not availablepublic void resetTo(long sequence)
sequence
- The sequence to reset too.IllegalStateException
- If any gating sequences have already been specified.public E claimAndGetPreallocated(long sequence)
sequence
- The sequence to claim.public boolean isPublished(long sequence)
sequence
- The sequence to identify the entry.public void addGatingSequences(Sequence... gatingSequences)
gatingSequences
- The sequences to add.public long getMinimumGatingSequence()
public boolean removeGatingSequence(Sequence sequence)
sequence
- to be removed.public SequenceBarrier newBarrier(Sequence... sequencesToTrack)
sequencesToTrack
- the additional sequences to trackSequenceBarrier
public long getCursor()
public int getBufferSize()
public boolean hasAvailableCapacity(int requiredCapacity)
next()
will not block. Especially true if this
ring buffer is set up to handle multiple producers.requiredCapacity
- The capacity to check for.public void publishEvent(EventTranslator<E> translator)
translator
- The user specified translation for the eventpublic boolean tryPublishEvent(EventTranslator<E> translator)
translator
- The user specified translation for the eventpublic <A> void publishEvent(EventTranslatorOneArg<E,A> translator, A arg0)
translator
- The user specified translation for the eventarg0
- A user supplied argument.publishEvent(EventTranslator)
public <A> boolean tryPublishEvent(EventTranslatorOneArg<E,A> translator, A arg0)
translator
- The user specified translation for the eventarg0
- A user supplied argument.tryPublishEvent(EventTranslator)
public <A,B> void publishEvent(EventTranslatorTwoArg<E,A,B> translator, A arg0, B arg1)
translator
- The user specified translation for the eventarg0
- A user supplied argument.arg1
- A user supplied argument.publishEvent(EventTranslator)
public <A,B> boolean tryPublishEvent(EventTranslatorTwoArg<E,A,B> translator, A arg0, B arg1)
translator
- The user specified translation for the eventarg0
- A user supplied argument.arg1
- A user supplied argument.tryPublishEvent(EventTranslator)
public <A,B,C> void publishEvent(EventTranslatorThreeArg<E,A,B,C> translator, A arg0, B arg1, C arg2)
translator
- The user specified translation for the eventarg0
- A user supplied argument.arg1
- A user supplied argument.arg2
- A user supplied argument.publishEvent(EventTranslator)
public <A,B,C> boolean tryPublishEvent(EventTranslatorThreeArg<E,A,B,C> translator, A arg0, B arg1, C arg2)
translator
- The user specified translation for the eventarg0
- A user supplied argument.arg1
- A user supplied argument.arg2
- A user supplied argument.publishEvent(EventTranslator)
public void publishEvent(EventTranslatorVararg<E> translator, Object... args)
translator
- The user specified translation for the eventargs
- User supplied arguments.publishEvent(EventTranslator)
public boolean tryPublishEvent(EventTranslatorVararg<E> translator, Object... args)
translator
- The user specified translation for the eventargs
- User supplied arguments.publishEvent(EventTranslator)
public void publishEvents(EventTranslator<E>[] translators)
translators
- The user specified translation for each eventpublic void publishEvents(EventTranslator<E>[] translators, int batchStartsAt, int batchSize)
translators
- The user specified translation for each eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batchpublic boolean tryPublishEvents(EventTranslator<E>[] translators)
translators
- The user specified translation for the eventpublic boolean tryPublishEvents(EventTranslator<E>[] translators, int batchStartsAt, int batchSize)
translators
- The user specified translation for the eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batchpublic <A> void publishEvents(EventTranslatorOneArg<E,A> translator, A[] arg0)
translator
- The user specified translation for the eventarg0
- A user supplied argument.publishEvents(com.lmax.disruptor.EventTranslator[])
public <A> void publishEvents(EventTranslatorOneArg<E,A> translator, int batchStartsAt, int batchSize, A[] arg0)
translator
- The user specified translation for each eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batcharg0
- An array of user supplied arguments, one element per event.publishEvents(EventTranslator[])
public <A> boolean tryPublishEvents(EventTranslatorOneArg<E,A> translator, A[] arg0)
translator
- The user specified translation for each eventarg0
- An array of user supplied arguments, one element per event.tryPublishEvents(com.lmax.disruptor.EventTranslator[])
public <A> boolean tryPublishEvents(EventTranslatorOneArg<E,A> translator, int batchStartsAt, int batchSize, A[] arg0)
translator
- The user specified translation for each eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batcharg0
- An array of user supplied arguments, one element per event.tryPublishEvents(EventTranslator[])
public <A,B> void publishEvents(EventTranslatorTwoArg<E,A,B> translator, A[] arg0, B[] arg1)
translator
- The user specified translation for the eventarg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.publishEvents(com.lmax.disruptor.EventTranslator[])
public <A,B> void publishEvents(EventTranslatorTwoArg<E,A,B> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1)
translator
- The user specified translation for the eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batch.arg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.publishEvents(EventTranslator[])
public <A,B> boolean tryPublishEvents(EventTranslatorTwoArg<E,A,B> translator, A[] arg0, B[] arg1)
translator
- The user specified translation for the eventarg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.tryPublishEvents(com.lmax.disruptor.EventTranslator[])
public <A,B> boolean tryPublishEvents(EventTranslatorTwoArg<E,A,B> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1)
translator
- The user specified translation for the eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batch.arg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.tryPublishEvents(EventTranslator[])
public <A,B,C> void publishEvents(EventTranslatorThreeArg<E,A,B,C> translator, A[] arg0, B[] arg1, C[] arg2)
translator
- The user specified translation for the eventarg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.arg2
- An array of user supplied arguments, one element per event.publishEvents(com.lmax.disruptor.EventTranslator[])
public <A,B,C> void publishEvents(EventTranslatorThreeArg<E,A,B,C> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1, C[] arg2)
translator
- The user specified translation for the eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The number of elements in the batch.arg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.arg2
- An array of user supplied arguments, one element per event.publishEvents(EventTranslator[])
public <A,B,C> boolean tryPublishEvents(EventTranslatorThreeArg<E,A,B,C> translator, A[] arg0, B[] arg1, C[] arg2)
translator
- The user specified translation for the eventarg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.arg2
- An array of user supplied arguments, one element per event.publishEvents(com.lmax.disruptor.EventTranslator[])
public <A,B,C> boolean tryPublishEvents(EventTranslatorThreeArg<E,A,B,C> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1, C[] arg2)
translator
- The user specified translation for the eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batch.arg0
- An array of user supplied arguments, one element per event.arg1
- An array of user supplied arguments, one element per event.arg2
- An array of user supplied arguments, one element per event.publishEvents(EventTranslator[])
public void publishEvents(EventTranslatorVararg<E> translator, Object[]... args)
translator
- The user specified translation for the eventargs
- User supplied arguments, one Object[] per event.publishEvents(com.lmax.disruptor.EventTranslator[])
public void publishEvents(EventTranslatorVararg<E> translator, int batchStartsAt, int batchSize, Object[]... args)
translator
- The user specified translation for the eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batchargs
- User supplied arguments, one Object[] per event.publishEvents(EventTranslator[])
public boolean tryPublishEvents(EventTranslatorVararg<E> translator, Object[]... args)
translator
- The user specified translation for the eventargs
- User supplied arguments, one Object[] per event.publishEvents(com.lmax.disruptor.EventTranslator[])
public boolean tryPublishEvents(EventTranslatorVararg<E> translator, int batchStartsAt, int batchSize, Object[]... args)
translator
- The user specified translation for the eventbatchStartsAt
- The first element of the array which is within the batch.batchSize
- The actual size of the batch.args
- User supplied arguments, one Object[] per event.publishEvents(EventTranslator[])
public void publish(long sequence)
sequence
- the sequence to publish.public void publish(long lo, long hi)
lo
- the lowest sequence number to be publishedhi
- the highest sequence number to be publishedSequencer.next(int)
public long remainingCapacity()
Copyright © 2015. All rights reserved.