Package com.lmax.disruptor
Class SingleProducerSequencer
- java.lang.Object
-
- com.lmax.disruptor.AbstractSequencer
-
- com.lmax.disruptor.SingleProducerSequencer
-
public final class SingleProducerSequencer extends AbstractSequencer
Coordinator for claiming sequences for access to a data structure while tracking dependentSequences. Not safe for use from multiple threads as it does not implement any barriers.* Note on
Cursored.getCursor(): With this sequencer the cursor value is updated after the call toSequenced.publish(long)is made.
-
-
Field Summary
Fields Modifier and Type Field Description protected 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 bytep77-
Fields inherited from class com.lmax.disruptor.AbstractSequencer
bufferSize, cursor, gatingSequences, waitStrategy
-
Fields inherited from interface com.lmax.disruptor.Sequencer
INITIAL_CURSOR_VALUE
-
-
Constructor Summary
Constructors Constructor Description SingleProducerSequencer(int bufferSize, WaitStrategy waitStrategy)Construct a Sequencer with the selected wait strategy and buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclaim(long sequence)Claim a specific sequence.longgetHighestPublishedSequence(long lowerBound, long availableSequence)Get the highest sequence number that can be safely read from the ring buffer.booleanhasAvailableCapacity(int requiredCapacity)Has the buffer got capacity to allocate another sequence.booleanisAvailable(long sequence)Confirms if a sequence is published and the event is available for use; non-blocking.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.longremainingCapacity()Get the remaining capacity for this sequencer.java.lang.StringtoString()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.-
Methods inherited from class com.lmax.disruptor.AbstractSequencer
addGatingSequences, getBufferSize, getCursor, getMinimumSequence, newBarrier, newPoller, removeGatingSequence
-
-
-
-
Field Detail
-
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
-
-
Constructor Detail
-
SingleProducerSequencer
public SingleProducerSequencer(int bufferSize, WaitStrategy waitStrategy)Construct a Sequencer with the selected wait strategy and buffer size.- Parameters:
bufferSize- the size of the buffer that this will sequence over.waitStrategy- for those waiting on sequences.
-
-
Method Detail
-
hasAvailableCapacity
public boolean hasAvailableCapacity(int requiredCapacity)
Description copied from interface:SequencedHas 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.
- See Also:
Sequenced.hasAvailableCapacity(int)
-
next
public long next()
Description copied from interface:SequencedClaim the next event in sequence for publishing.- Returns:
- the claimed sequence value
- See Also:
Sequenced.next()
-
next
public long next(int n)
Description copied from interface:SequencedClaim 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
- See Also:
Sequenced.next(int)
-
tryNext
public long tryNext() throws InsufficientCapacityExceptionDescription copied from interface:SequencedAttempt 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.- See Also:
Sequenced.tryNext()
-
tryNext
public long tryNext(int n) throws InsufficientCapacityExceptionDescription copied from interface:SequencedAttempt 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 atSequenced.next()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.- See Also:
Sequenced.tryNext(int)
-
remainingCapacity
public long remainingCapacity()
Description copied from interface:SequencedGet the remaining capacity for this sequencer.- Returns:
- The number of slots remaining.
- See Also:
Sequenced.remainingCapacity()
-
claim
public void claim(long sequence)
Description copied from interface:SequencerClaim a specific sequence. Only used if initialising the ring buffer to a specific value.- Parameters:
sequence- The sequence to initialise too.- See Also:
Sequencer.claim(long)
-
publish
public void publish(long sequence)
Description copied from interface:SequencedPublishes a sequence. Call when the event has been filled.- Parameters:
sequence- the sequence to be published.- See Also:
Sequenced.publish(long)
-
publish
public void publish(long lo, long hi)Description copied from interface:SequencedBatch publish sequences. Called when all of the events have been filled.- Parameters:
lo- first sequence number to publishhi- last sequence number to publish- See Also:
Sequenced.publish(long, long)
-
isAvailable
public boolean isAvailable(long sequence)
Description copied from interface:SequencerConfirms if a sequence is published and the event is available for use; non-blocking.- Parameters:
sequence- of the buffer to check- Returns:
- true if the sequence is available for use, false if not
- See Also:
Sequencer.isAvailable(long)
-
getHighestPublishedSequence
public long getHighestPublishedSequence(long lowerBound, long availableSequence)Description copied from interface:SequencerGet the highest sequence number that can be safely read from the ring buffer. Depending on the implementation of the Sequencer this call may need to scan a number of values in the Sequencer. The scan will range from nextSequence to availableSequence. If there are no available values>= nextSequencethe return value will benextSequence - 1. To work correctly a consumer should pass a value that is 1 higher than the last sequence that was successfully processed.- Parameters:
lowerBound- The sequence to start scanning from.availableSequence- The sequence to scan to.- Returns:
- The highest value that can be safely read, will be at least
nextSequence - 1.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractSequencer
-
-