E
- implementation storing the data for sharing during exchange or parallel coordination of an event.public final class RingBuffer<E> extends java.lang.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.
|
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)
Get the object that is preallocated within the ring buffer.
|
E |
getPublished(long sequence)
Get the event for a given sequence in the RingBuffer.
|
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.
|
void |
publish(long sequence)
Publish the specified sequence.
|
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,
java.lang.Object... args)
Allows a variable number of user supplied arguments
|
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.
|
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,
java.lang.Object... args)
Allows a variable number of user supplied arguments
|
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.java.lang.IllegalArgumentException
- if bufferSize is less than 1 and 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.java.lang.IllegalArgumentException
- if bufferSize is less than 1 and 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.java.lang.IllegalArgumentException
- if bufferSize is less than 1 and 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.java.lang.IllegalArgumentException
- if bufferSize is less than 1 and 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.java.lang.IllegalArgumentException
- if bufferSize is less than 1 and not a power of 2public E getPublished(long sequence)
Get the event for a given sequence in the RingBuffer. This method will wait until the
value is published before returning. This method should only be used by EventProcessor
s
that are reading values out of the ring buffer. Publishing code should use the
getPreallocated(long)
call to get a handle onto the preallocated event.
The call implements the appropriate load fence to ensure that the data within the event is visible after this call completes.
getPublished
in interface DataProvider<E>
sequence
- for the eventpublic long next()
long sequence = ringBuffer.next(); try { Event e = ringBuffer.getPreallocated(sequence); // Do some work with the event. } finally { ringBuffer.publish(sequence); }
publish(long)
,
getPreallocated(long)
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.getPreallocated(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
publish(long)
,
getPreallocated(long)
public void resetTo(long sequence)
sequence
- The sequence to reset too.java.lang.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
- SequenceBarrier
public final 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, java.lang.Object... args)
translator
- The user specified translation for the eventargs
- User supplied arguments.publishEvent(EventTranslator)
public boolean tryPublishEvent(EventTranslatorVararg<E> translator, java.lang.Object... args)
translator
- The user specified translation for the eventargs
- User supplied arguments.publishEvent(EventTranslator)
public E getPreallocated(long sequence)
getPublished(long)
\
in that is does not wait until the publisher indicates that object is available. This method should only be used
by the publishing thread to get a handle on the preallocated event in order to fill it with data.sequence
- for the eventpublic void publish(long sequence)
sequence
- the sequence to publish.public long remainingCapacity()
Copyright © 2011 - 2013 LMAX Ltd. All Rights Reserved.