Class RingBuffer<E>
- java.lang.Object
-
- com.lmax.disruptor.RingBuffer<E>
-
- Type Parameters:
E- implementation storing the data for sharing during exchange or parallel coordination of an event.
- All Implemented Interfaces:
Cursored,DataProvider<E>,EventSequencer<E>,EventSink<E>,Sequenced
public final class RingBuffer<E> extends java.lang.Object implements Cursored, EventSequencer<E>, EventSink<E>
Ring based store of reusable entries containing the data representing an event being exchanged between event producer andEventProcessors.
-
-
Field Summary
Fields Modifier and Type Field Description protected intbufferSizestatic longINITIAL_CURSOR_VALUEThe initial cursor valueprotected bytep10protected bytep11protected bytep12protected bytep13protected bytep14protected bytep15protected bytep16protected bytep17protected bytep20protected bytep21protected bytep22protected bytep23protected bytep24protected bytep25protected bytep26protected bytep27protected bytep30protected bytep31protected bytep32protected bytep33protected bytep34protected bytep35protected bytep36protected bytep37protected bytep40protected bytep41protected bytep42protected bytep43protected bytep44protected bytep45protected bytep46protected bytep47protected bytep50protected bytep51protected bytep52protected bytep53protected bytep54protected bytep55protected bytep56protected bytep57protected bytep60protected bytep61protected bytep62protected bytep63protected bytep64protected bytep65protected bytep66protected bytep67protected bytep70protected bytep71protected bytep72protected bytep73protected bytep74protected bytep75protected bytep76protected bytep77protected Sequencersequencer
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGatingSequences(Sequence... gatingSequences)Add the specified gating sequences to this instance of the Disruptor.EclaimAndGetPreallocated(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 strategyBlockingWaitStrategy.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 strategyBlockingWaitStrategy.static <E> RingBuffer<E>createSingleProducer(EventFactory<E> factory, int bufferSize, WaitStrategy waitStrategy)Create a new single producer RingBuffer with the specified wait strategy.protected EelementAt(long sequence)Eget(long sequence)Get the event for a given sequence in the RingBuffer.intgetBufferSize()The size of the buffer.longgetCursor()Get the current cursor value for the ring buffer.longgetMinimumGatingSequence()Get the minimum sequence value from all of the gating sequences added to this ringBuffer.booleanhasAvailableCapacity(int requiredCapacity)Given specifiedrequiredCapacitydetermines if that amount of space is available.booleanisAvailable(long sequence)Determines if the event for a given sequence is currently available.SequenceBarriernewBarrier(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.EventPoller<E>newPoller(Sequence... gatingSequences)Creates an event poller for this ring buffer gated on the supplied sequences.longnext()Increment and return the next sequence for the ring buffer.longnext(int n)The same functionality asnext(), but allows the caller to claim the next n sequences.voidpublish(long sequence)Publish the specified sequence.voidpublish(long lo, long hi)Publish the specified sequences.voidpublishEvent(EventTranslator<E> translator)Publishes an event to the ring buffer.<A> voidpublishEvent(EventTranslatorOneArg<E,A> translator, A arg0)Allows one user supplied argument.<A,B,C>
voidpublishEvent(EventTranslatorThreeArg<E,A,B,C> translator, A arg0, B arg1, C arg2)Allows three user supplied arguments<A,B>
voidpublishEvent(EventTranslatorTwoArg<E,A,B> translator, A arg0, B arg1)Allows two user supplied arguments.voidpublishEvent(EventTranslatorVararg<E> translator, java.lang.Object... args)Allows a variable number of user supplied argumentsvoidpublishEvents(EventTranslator<E>[] translators)Publishes multiple events to the ring buffer.voidpublishEvents(EventTranslator<E>[] translators, int batchStartsAt, int batchSize)Publishes multiple events to the ring buffer.<A> voidpublishEvents(EventTranslatorOneArg<E,A> translator, int batchStartsAt, int batchSize, A[] arg0)Allows one user supplied argument per event.<A> voidpublishEvents(EventTranslatorOneArg<E,A> translator, A[] arg0)Allows one user supplied argument per event.<A,B,C>
voidpublishEvents(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,C>
voidpublishEvents(EventTranslatorThreeArg<E,A,B,C> translator, A[] arg0, B[] arg1, C[] arg2)Allows three user supplied arguments per event.<A,B>
voidpublishEvents(EventTranslatorTwoArg<E,A,B> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1)Allows two user supplied arguments per event.<A,B>
voidpublishEvents(EventTranslatorTwoArg<E,A,B> translator, A[] arg0, B[] arg1)Allows two user supplied arguments per event.voidpublishEvents(EventTranslatorVararg<E> translator, int batchStartsAt, int batchSize, java.lang.Object[]... args)Allows a variable number of user supplied arguments per event.voidpublishEvents(EventTranslatorVararg<E> translator, java.lang.Object[]... args)Allows a variable number of user supplied arguments per event.longremainingCapacity()Get the remaining capacity for this ringBuffer.booleanremoveGatingSequence(Sequence sequence)Remove the specified sequence from this ringBuffer.java.lang.StringtoString()longtryNext()Increment and return the next sequence for the ring buffer.longtryNext(int n)The same functionality astryNext(), but allows the caller to attempt to claim the next n sequences.booleantryPublishEvent(EventTranslator<E> translator)Attempts to publish an event to the ring buffer.<A> booleantryPublishEvent(EventTranslatorOneArg<E,A> translator, A arg0)Allows one user supplied argument.<A,B,C>
booleantryPublishEvent(EventTranslatorThreeArg<E,A,B,C> translator, A arg0, B arg1, C arg2)Allows three user supplied arguments<A,B>
booleantryPublishEvent(EventTranslatorTwoArg<E,A,B> translator, A arg0, B arg1)Allows two user supplied arguments.booleantryPublishEvent(EventTranslatorVararg<E> translator, java.lang.Object... args)Allows a variable number of user supplied argumentsbooleantryPublishEvents(EventTranslator<E>[] translators)Attempts to publish multiple events to the ring buffer.booleantryPublishEvents(EventTranslator<E>[] translators, int batchStartsAt, int batchSize)Attempts to publish multiple events to the ring buffer.<A> booleantryPublishEvents(EventTranslatorOneArg<E,A> translator, int batchStartsAt, int batchSize, A[] arg0)Allows one user supplied argument.<A> booleantryPublishEvents(EventTranslatorOneArg<E,A> translator, A[] arg0)Allows one user supplied argument.<A,B,C>
booleantryPublishEvents(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,C>
booleantryPublishEvents(EventTranslatorThreeArg<E,A,B,C> translator, A[] arg0, B[] arg1, C[] arg2)Allows three user supplied arguments per event.<A,B>
booleantryPublishEvents(EventTranslatorTwoArg<E,A,B> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1)Allows two user supplied arguments per event.<A,B>
booleantryPublishEvents(EventTranslatorTwoArg<E,A,B> translator, A[] arg0, B[] arg1)Allows two user supplied arguments per event.booleantryPublishEvents(EventTranslatorVararg<E> translator, int batchStartsAt, int batchSize, java.lang.Object[]... args)Allows a variable number of user supplied arguments per event.booleantryPublishEvents(EventTranslatorVararg<E> translator, java.lang.Object[]... args)Allows a variable number of user supplied arguments per event.
-
-
-
Field Detail
-
INITIAL_CURSOR_VALUE
public static final long INITIAL_CURSOR_VALUE
The initial cursor value- See Also:
- Constant Field Values
-
p10
protected byte p10
-
p11
protected byte p11
-
p12
protected byte p12
-
p13
protected byte p13
-
p14
protected byte p14
-
p15
protected byte p15
-
p16
protected byte p16
-
p17
protected byte p17
-
p20
protected byte p20
-
p21
protected byte p21
-
p22
protected byte p22
-
p23
protected byte p23
-
p24
protected byte p24
-
p25
protected byte p25
-
p26
protected byte p26
-
p27
protected byte p27
-
p30
protected byte p30
-
p31
protected byte p31
-
p32
protected byte p32
-
p33
protected byte p33
-
p34
protected byte p34
-
p35
protected byte p35
-
p36
protected byte p36
-
p37
protected byte p37
-
p40
protected byte p40
-
p41
protected byte p41
-
p42
protected byte p42
-
p43
protected byte p43
-
p44
protected byte p44
-
p45
protected byte p45
-
p46
protected byte p46
-
p47
protected byte p47
-
p50
protected byte p50
-
p51
protected byte p51
-
p52
protected byte p52
-
p53
protected byte p53
-
p54
protected byte p54
-
p55
protected byte p55
-
p56
protected byte p56
-
p57
protected byte p57
-
p60
protected byte p60
-
p61
protected byte p61
-
p62
protected byte p62
-
p63
protected byte p63
-
p64
protected byte p64
-
p65
protected byte p65
-
p66
protected byte p66
-
p67
protected byte p67
-
p70
protected byte p70
-
p71
protected byte p71
-
p72
protected byte p72
-
p73
protected byte p73
-
p74
protected byte p74
-
p75
protected byte p75
-
p76
protected byte p76
-
p77
protected byte p77
-
bufferSize
protected final int bufferSize
-
sequencer
protected final Sequencer sequencer
-
-
Method Detail
-
createMultiProducer
public static <E> RingBuffer<E> createMultiProducer(EventFactory<E> factory, int bufferSize, WaitStrategy waitStrategy)
Create a new multiple producer RingBuffer with the specified wait strategy.- Type Parameters:
E- Class of the event stored in the ring buffer.- Parameters:
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.- Returns:
- a constructed ring buffer.
- Throws:
java.lang.IllegalArgumentException- if bufferSize is less than 1 or not a power of 2- See Also:
MultiProducerSequencer
-
createMultiProducer
public static <E> RingBuffer<E> createMultiProducer(EventFactory<E> factory, int bufferSize)
Create a new multiple producer RingBuffer using the default wait strategyBlockingWaitStrategy.- Type Parameters:
E- Class of the event stored in the ring buffer.- Parameters:
factory- used to create the events within the ring buffer.bufferSize- number of elements to create within the ring buffer.- Returns:
- a constructed ring buffer.
- Throws:
java.lang.IllegalArgumentException- ifbufferSizeis less than 1 or not a power of 2- See Also:
MultiProducerSequencer
-
createSingleProducer
public static <E> RingBuffer<E> createSingleProducer(EventFactory<E> factory, int bufferSize, WaitStrategy waitStrategy)
Create a new single producer RingBuffer with the specified wait strategy.- Type Parameters:
E- Class of the event stored in the ring buffer.- Parameters:
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.- Returns:
- a constructed ring buffer.
- Throws:
java.lang.IllegalArgumentException- if bufferSize is less than 1 or not a power of 2- See Also:
SingleProducerSequencer
-
createSingleProducer
public static <E> RingBuffer<E> createSingleProducer(EventFactory<E> factory, int bufferSize)
Create a new single producer RingBuffer using the default wait strategyBlockingWaitStrategy.- Type Parameters:
E- Class of the event stored in the ring buffer.- Parameters:
factory- used to create the events within the ring buffer.bufferSize- number of elements to create within the ring buffer.- Returns:
- a constructed ring buffer.
- Throws:
java.lang.IllegalArgumentException- ifbufferSizeis less than 1 or not a power of 2- See Also:
MultiProducerSequencer
-
create
public 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)- Type Parameters:
E- Class of the event stored in the ring buffer.- Parameters:
producerType- producer type to useProducerType.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.- Returns:
- a constructed ring buffer.
- Throws:
java.lang.IllegalArgumentException- if bufferSize is less than 1 or not a power of 2
-
get
public 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 callingpublish(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 theSequenceBarrier.waitFor(long)method.- Specified by:
getin interfaceDataProvider<E>- Parameters:
sequence- for the event- Returns:
- the event for the given sequence
-
next
public long next()
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); }- Specified by:
nextin interfaceSequenced- Returns:
- The next sequence to publish to.
- See Also:
publish(long),get(long)
-
next
public long next(int n)
The same functionality asnext(), but allows the caller to claim the next n sequences.- Specified by:
nextin interfaceSequenced- Parameters:
n- number of slots to claim- Returns:
- sequence number of the highest slot claimed
- See Also:
Sequenced.next(int)
-
tryNext
public long tryNext() throws InsufficientCapacityExceptionIncrement 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.- Specified by:
tryNextin interfaceSequenced- Returns:
- The next sequence to publish to.
- Throws:
InsufficientCapacityException- if the necessary space in the ring buffer is not available- See Also:
publish(long),get(long)
-
tryNext
public long tryNext(int n) throws InsufficientCapacityExceptionThe same functionality astryNext(), but allows the caller to attempt to claim the next n sequences.- Specified by:
tryNextin interfaceSequenced- Parameters:
n- number of slots to claim- Returns:
- sequence number of the highest slot claimed
- Throws:
InsufficientCapacityException- if the necessary space in the ring buffer is not available
-
claimAndGetPreallocated
public E claimAndGetPreallocated(long sequence)
Sets the cursor to a specific sequence and returns the preallocated entry that is stored there. This can cause a data race and should only be done in controlled circumstances, e.g. during initialisation.- Parameters:
sequence- The sequence to claim.- Returns:
- The preallocated event.
-
isAvailable
public boolean isAvailable(long sequence)
Determines if the event for a given sequence is currently available.Note that this does not guarantee that event will still be available on the next interaction with the RingBuffer. For example, it is not necessarily safe to write code like this:
if (ringBuffer.isAvailable(sequence)) { final E e = ringBuffer.get(sequence); // ...do something with e }because there is a race between the reading thread and the writing thread.
This method will also return false when querying for sequences that are behind the ring buffer's wrap point.
- Parameters:
sequence- The sequence to identify the entry.- Returns:
- If the event published with the given sequence number is currently available.
-
addGatingSequences
public void addGatingSequences(Sequence... gatingSequences)
Add the specified gating sequences to this instance of the Disruptor. They will safely and atomically added to the list of gating sequences.- Parameters:
gatingSequences- The sequences to add.
-
getMinimumGatingSequence
public long getMinimumGatingSequence()
Get the minimum sequence value from all of the gating sequences added to this ringBuffer.- Returns:
- The minimum gating sequence or the cursor sequence if no sequences have been added.
-
removeGatingSequence
public boolean removeGatingSequence(Sequence sequence)
Remove the specified sequence from this ringBuffer.- Parameters:
sequence- to be removed.- Returns:
trueif this sequence was found,falseotherwise.
-
newBarrier
public 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.- Parameters:
sequencesToTrack- the additional sequences to track- Returns:
- A sequence barrier that will track the specified sequences.
- See Also:
SequenceBarrier
-
newPoller
public EventPoller<E> newPoller(Sequence... gatingSequences)
Creates an event poller for this ring buffer gated on the supplied sequences.- Parameters:
gatingSequences- to be gated on.- Returns:
- A poller that will gate on this ring buffer and the supplied sequences.
-
getCursor
public long getCursor()
Get the current cursor value for the ring buffer. The actual value received will depend on the type ofSequencerthat is being used.- Specified by:
getCursorin interfaceCursored- Returns:
- current cursor value
- See Also:
MultiProducerSequencer,SingleProducerSequencer
-
getBufferSize
public int getBufferSize()
The size of the buffer.- Specified by:
getBufferSizein interfaceSequenced- Returns:
- size of buffer
-
hasAvailableCapacity
public boolean hasAvailableCapacity(int requiredCapacity)
Given specifiedrequiredCapacitydetermines if that amount of space is available. Note, you can not assume that if this method returnstruethat a call tonext()will not block. Especially true if this ring buffer is set up to handle multiple producers.- Specified by:
hasAvailableCapacityin interfaceSequenced- Parameters:
requiredCapacity- The capacity to check for.- Returns:
trueIf the specifiedrequiredCapacityis availablefalseif not.
-
publishEvent
public void publishEvent(EventTranslator<E> translator)
Description copied from interface:EventSinkPublishes an event to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring buffer and publishing the claimed sequence after translation.- Specified by:
publishEventin interfaceEventSink<E>- Parameters:
translator- The user specified translation for the event- See Also:
EventSink.publishEvent(com.lmax.disruptor.EventTranslator)
-
tryPublishEvent
public boolean tryPublishEvent(EventTranslator<E> translator)
Description copied from interface:EventSinkAttempts to publish an event to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring buffer and publishing the claimed sequence after translation. Will return false if specified capacity was not available.- Specified by:
tryPublishEventin interfaceEventSink<E>- Parameters:
translator- The user specified translation for the event- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
EventSink.tryPublishEvent(com.lmax.disruptor.EventTranslator)
-
publishEvent
public <A> void publishEvent(EventTranslatorOneArg<E,A> translator, A arg0)
Description copied from interface:EventSinkAllows one user supplied argument.- Specified by:
publishEventin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argument- Parameters:
translator- The user specified translation for the eventarg0- A user supplied argument.- See Also:
com.lmax.disruptor.EventSink#publishEvent(com.lmax.disruptor.EventTranslatorOneArg, A)
-
tryPublishEvent
public <A> boolean tryPublishEvent(EventTranslatorOneArg<E,A> translator, A arg0)
Description copied from interface:EventSinkAllows one user supplied argument.- Specified by:
tryPublishEventin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argument- Parameters:
translator- The user specified translation for the eventarg0- A user supplied argument.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvent(com.lmax.disruptor.EventTranslatorOneArg, A)
-
publishEvent
public <A,B> void publishEvent(EventTranslatorTwoArg<E,A,B> translator, A arg0, B arg1)
Description copied from interface:EventSinkAllows two user supplied arguments.- Specified by:
publishEventin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argument- Parameters:
translator- The user specified translation for the eventarg0- A user supplied argument.arg1- A user supplied argument.- See Also:
com.lmax.disruptor.EventSink#publishEvent(com.lmax.disruptor.EventTranslatorTwoArg, A, B)
-
tryPublishEvent
public <A,B> boolean tryPublishEvent(EventTranslatorTwoArg<E,A,B> translator, A arg0, B arg1)
Description copied from interface:EventSinkAllows two user supplied arguments.- Specified by:
tryPublishEventin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argument- Parameters:
translator- The user specified translation for the eventarg0- A user supplied argument.arg1- A user supplied argument.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvent(com.lmax.disruptor.EventTranslatorTwoArg, A, B)
-
publishEvent
public <A,B,C> void publishEvent(EventTranslatorThreeArg<E,A,B,C> translator, A arg0, B arg1, C arg2)
Description copied from interface:EventSinkAllows three user supplied arguments- Specified by:
publishEventin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argumentC- Class of the user supplied argument- Parameters:
translator- The user specified translation for the eventarg0- A user supplied argument.arg1- A user supplied argument.arg2- A user supplied argument.- See Also:
com.lmax.disruptor.EventSink#publishEvent(com.lmax.disruptor.EventTranslatorThreeArg, A, B, C)
-
tryPublishEvent
public <A,B,C> boolean tryPublishEvent(EventTranslatorThreeArg<E,A,B,C> translator, A arg0, B arg1, C arg2)
Description copied from interface:EventSinkAllows three user supplied arguments- Specified by:
tryPublishEventin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argumentC- Class of the user supplied argument- Parameters:
translator- The user specified translation for the eventarg0- A user supplied argument.arg1- A user supplied argument.arg2- A user supplied argument.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvent(com.lmax.disruptor.EventTranslatorThreeArg, A, B, C)
-
publishEvent
public void publishEvent(EventTranslatorVararg<E> translator, java.lang.Object... args)
Description copied from interface:EventSinkAllows a variable number of user supplied arguments- Specified by:
publishEventin interfaceEventSink<E>- Parameters:
translator- The user specified translation for the eventargs- User supplied arguments.- See Also:
EventSink.publishEvent(com.lmax.disruptor.EventTranslatorVararg, java.lang.Object...)
-
tryPublishEvent
public boolean tryPublishEvent(EventTranslatorVararg<E> translator, java.lang.Object... args)
Description copied from interface:EventSinkAllows a variable number of user supplied arguments- Specified by:
tryPublishEventin interfaceEventSink<E>- Parameters:
translator- The user specified translation for the eventargs- User supplied arguments.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
EventSink.tryPublishEvent(com.lmax.disruptor.EventTranslatorVararg, java.lang.Object...)
-
publishEvents
public void publishEvents(EventTranslator<E>[] translators)
Description copied from interface:EventSinkPublishes multiple events to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring buffer and publishing the claimed sequence after translation.
With this call the data that is to be inserted into the ring buffer will be a field (either explicitly or captured anonymously), therefore this call will require an instance of the translator for each value that is to be inserted into the ring buffer.
- Specified by:
publishEventsin interfaceEventSink<E>- Parameters:
translators- The user specified translation for each event- See Also:
EventSink.publishEvents(com.lmax.disruptor.EventTranslator[])
-
publishEvents
public void publishEvents(EventTranslator<E>[] translators, int batchStartsAt, int batchSize)
Description copied from interface:EventSinkPublishes multiple events to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring buffer and publishing the claimed sequence after translation.
With this call the data that is to be inserted into the ring buffer will be a field (either explicitly or captured anonymously), therefore this call will require an instance of the translator for each value that is to be inserted into the ring buffer.
- Specified by:
publishEventsin interfaceEventSink<E>- Parameters:
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 batch- See Also:
EventSink.publishEvents(com.lmax.disruptor.EventTranslator[], int, int)
-
tryPublishEvents
public boolean tryPublishEvents(EventTranslator<E>[] translators)
Description copied from interface:EventSinkAttempts to publish multiple events to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring buffer and publishing the claimed sequence after translation. Will return false if specified capacity was not available.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Parameters:
translators- The user specified translation for the event- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
EventSink.tryPublishEvents(com.lmax.disruptor.EventTranslator[])
-
tryPublishEvents
public boolean tryPublishEvents(EventTranslator<E>[] translators, int batchStartsAt, int batchSize)
Description copied from interface:EventSinkAttempts to publish multiple events to the ring buffer. It handles claiming the next sequence, getting the current (uninitialised) event from the ring buffer and publishing the claimed sequence after translation. Will return false if specified capacity was not available.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Parameters:
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 batch- Returns:
- true if all the values were published, false if there was insufficient capacity.
- See Also:
EventSink.tryPublishEvents(com.lmax.disruptor.EventTranslator[], int, int)
-
publishEvents
public <A> void publishEvents(EventTranslatorOneArg<E,A> translator, A[] arg0)
Description copied from interface:EventSinkAllows one user supplied argument per event.- Specified by:
publishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argument- Parameters:
translator- The user specified translation for the eventarg0- A user supplied argument.- See Also:
com.lmax.disruptor.EventSink#publishEvents(com.lmax.disruptor.EventTranslatorOneArg, A[])
-
publishEvents
public <A> void publishEvents(EventTranslatorOneArg<E,A> translator, int batchStartsAt, int batchSize, A[] arg0)
Description copied from interface:EventSinkAllows one user supplied argument per event.- Specified by:
publishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argument- Parameters:
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.- See Also:
com.lmax.disruptor.EventSink#publishEvents(com.lmax.disruptor.EventTranslatorOneArg, int, int, A[])
-
tryPublishEvents
public <A> boolean tryPublishEvents(EventTranslatorOneArg<E,A> translator, A[] arg0)
Description copied from interface:EventSinkAllows one user supplied argument.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argument- Parameters:
translator- The user specified translation for each eventarg0- An array of user supplied arguments, one element per event.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvents(com.lmax.disruptor.EventTranslatorOneArg, A[])
-
tryPublishEvents
public <A> boolean tryPublishEvents(EventTranslatorOneArg<E,A> translator, int batchStartsAt, int batchSize, A[] arg0)
Description copied from interface:EventSinkAllows one user supplied argument.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argument- Parameters:
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.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvents(com.lmax.disruptor.EventTranslatorOneArg, int, int, A[])
-
publishEvents
public <A,B> void publishEvents(EventTranslatorTwoArg<E,A,B> translator, A[] arg0, B[] arg1)
Description copied from interface:EventSinkAllows two user supplied arguments per event.- Specified by:
publishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argument- Parameters:
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.- See Also:
com.lmax.disruptor.EventSink#publishEvents(com.lmax.disruptor.EventTranslatorTwoArg, A[], B[])
-
publishEvents
public <A,B> void publishEvents(EventTranslatorTwoArg<E,A,B> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1)
Description copied from interface:EventSinkAllows two user supplied arguments per event.- Specified by:
publishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argument- Parameters:
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.- See Also:
com.lmax.disruptor.EventSink#publishEvents(com.lmax.disruptor.EventTranslatorTwoArg, int, int, A[], B[])
-
tryPublishEvents
public <A,B> boolean tryPublishEvents(EventTranslatorTwoArg<E,A,B> translator, A[] arg0, B[] arg1)
Description copied from interface:EventSinkAllows two user supplied arguments per event.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argument- Parameters:
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.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvents(com.lmax.disruptor.EventTranslatorTwoArg, A[], B[])
-
tryPublishEvents
public <A,B> boolean tryPublishEvents(EventTranslatorTwoArg<E,A,B> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1)
Description copied from interface:EventSinkAllows two user supplied arguments per event.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argument- Parameters:
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.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvents(com.lmax.disruptor.EventTranslatorTwoArg, int, int, A[], B[])
-
publishEvents
public <A,B,C> void publishEvents(EventTranslatorThreeArg<E,A,B,C> translator, A[] arg0, B[] arg1, C[] arg2)
Description copied from interface:EventSinkAllows three user supplied arguments per event.- Specified by:
publishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argumentC- Class of the user supplied argument- Parameters:
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.- See Also:
com.lmax.disruptor.EventSink#publishEvents(com.lmax.disruptor.EventTranslatorThreeArg, A[], B[], C[])
-
publishEvents
public <A,B,C> void publishEvents(EventTranslatorThreeArg<E,A,B,C> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1, C[] arg2)
Description copied from interface:EventSinkAllows three user supplied arguments per event.- Specified by:
publishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argumentC- Class of the user supplied argument- Parameters:
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.- See Also:
com.lmax.disruptor.EventSink#publishEvents(com.lmax.disruptor.EventTranslatorThreeArg, int, int, A[], B[], C[])
-
tryPublishEvents
public <A,B,C> boolean tryPublishEvents(EventTranslatorThreeArg<E,A,B,C> translator, A[] arg0, B[] arg1, C[] arg2)
Description copied from interface:EventSinkAllows three user supplied arguments per event.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argumentC- Class of the user supplied argument- Parameters:
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.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvents(com.lmax.disruptor.EventTranslatorThreeArg, A[], B[], C[])
-
tryPublishEvents
public <A,B,C> boolean tryPublishEvents(EventTranslatorThreeArg<E,A,B,C> translator, int batchStartsAt, int batchSize, A[] arg0, B[] arg1, C[] arg2)
Description copied from interface:EventSinkAllows three user supplied arguments per event.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Type Parameters:
A- Class of the user supplied argumentB- Class of the user supplied argumentC- Class of the user supplied argument- Parameters:
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.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
com.lmax.disruptor.EventSink#tryPublishEvents(com.lmax.disruptor.EventTranslatorThreeArg, int, int, A[], B[], C[])
-
publishEvents
public void publishEvents(EventTranslatorVararg<E> translator, java.lang.Object[]... args)
Description copied from interface:EventSinkAllows a variable number of user supplied arguments per event.- Specified by:
publishEventsin interfaceEventSink<E>- Parameters:
translator- The user specified translation for the eventargs- User supplied arguments, one Object[] per event.- See Also:
EventSink.publishEvents(com.lmax.disruptor.EventTranslatorVararg, java.lang.Object[][])
-
publishEvents
public void publishEvents(EventTranslatorVararg<E> translator, int batchStartsAt, int batchSize, java.lang.Object[]... args)
Description copied from interface:EventSinkAllows a variable number of user supplied arguments per event.- Specified by:
publishEventsin interfaceEventSink<E>- Parameters:
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.- See Also:
EventSink.publishEvents(com.lmax.disruptor.EventTranslatorVararg, int, int, java.lang.Object[][])
-
tryPublishEvents
public boolean tryPublishEvents(EventTranslatorVararg<E> translator, java.lang.Object[]... args)
Description copied from interface:EventSinkAllows a variable number of user supplied arguments per event.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Parameters:
translator- The user specified translation for the eventargs- User supplied arguments, one Object[] per event.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
EventSink.tryPublishEvents(com.lmax.disruptor.EventTranslatorVararg, java.lang.Object[][])
-
tryPublishEvents
public boolean tryPublishEvents(EventTranslatorVararg<E> translator, int batchStartsAt, int batchSize, java.lang.Object[]... args)
Description copied from interface:EventSinkAllows a variable number of user supplied arguments per event.- Specified by:
tryPublishEventsin interfaceEventSink<E>- Parameters:
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.- Returns:
- true if the value was published, false if there was insufficient capacity.
- See Also:
EventSink.tryPublishEvents(com.lmax.disruptor.EventTranslatorVararg, int, int, java.lang.Object[][])
-
publish
public void publish(long sequence)
Publish the specified sequence. This action marks this particular message as being available to be read.
-
publish
public void publish(long lo, long hi)Publish the specified sequences. This action marks these particular messages as being available to be read.- Specified by:
publishin interfaceSequenced- Parameters:
lo- the lowest sequence number to be publishedhi- the highest sequence number to be published- See Also:
Sequenced.next(int)
-
remainingCapacity
public long remainingCapacity()
Get the remaining capacity for this ringBuffer.- Specified by:
remainingCapacityin interfaceSequenced- Returns:
- The number of slots remaining.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
elementAt
protected final E elementAt(long sequence)
-
-