Package com.lmax.disruptor
Class Sequence
java.lang.Object
com.lmax.disruptor.LhsPadding
com.lmax.disruptor.Value
com.lmax.disruptor.RhsPadding
com.lmax.disruptor.Sequence
- Direct Known Subclasses:
FixedSequenceGroup,NoOpEventProcessor.SequencerFollowingSequence,SequenceGroup
Concurrent sequence class used for tracking the progress of
the ring buffer and event processors. Support a number
of concurrent operations including CAS and order writes.
Also attempts to be more efficient with regards to false sharing by adding padding around the volatile field.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final longprivate static final VarHandleFields inherited from class com.lmax.disruptor.RhsPadding
p100, p101, p102, p103, p104, p105, p106, p107, p110, p111, p112, p113, p114, p115, p116, p117, p120, p121, p122, p123, p124, p125, p126, p127, p130, p131, p132, p133, p134, p135, p136, p137, p140, p141, p142, p143, p144, p145, p146, p147, p150, p151, p152, p153, p154, p155, p156, p157, p90, p91, p92, p93, p94, p95, p96, p97Fields inherited from class com.lmax.disruptor.LhsPadding
p10, p11, p12, p13, p14, p15, p16, p17, p20, p21, p22, p23, p24, p25, p26, p27, p30, p31, p32, p33, p34, p35, p36, p37, p40, p41, p42, p43, p44, p45, p46, p47, p50, p51, p52, p53, p54, p55, p56, p57, p60, p61, p62, p63, p64, p65, p66, p67, p70, p71, p72, p73, p74, p75, p76, p77 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongaddAndGet(long increment) Atomically add the supplied value.booleancompareAndSet(long expectedValue, long newValue) Perform a compare and set operation on the sequence.longget()Perform a volatile read of this sequence's value.longgetAndAdd(long increment) Perform an atomic getAndAdd operation on the sequence.longAtomically increment the sequence by one.voidset(long value) Perform an ordered write of this sequence.voidsetVolatile(long value) Performs a volatile write of this sequence.toString()
-
Field Details
-
INITIAL_VALUE
static final long INITIAL_VALUE- See Also:
-
VALUE_FIELD
-
-
Constructor Details
-
Sequence
public Sequence()Create a sequence initialised to -1. -
Sequence
public Sequence(long initialValue) Create a sequence with a specified initial value.- Parameters:
initialValue- The initial value for this sequence.
-
-
Method Details
-
get
public long get()Perform a volatile read of this sequence's value.- Returns:
- The current value of the sequence.
-
set
public void set(long value) Perform an ordered write of this sequence. The intent is a Store/Store barrier between this write and any previous store.- Parameters:
value- The new value for the sequence.
-
setVolatile
public void setVolatile(long value) Performs a volatile write of this sequence. The intent is a Store/Store barrier between this write and any previous write and a Store/Load barrier between this write and any subsequent volatile read.- Parameters:
value- The new value for the sequence.
-
compareAndSet
public boolean compareAndSet(long expectedValue, long newValue) Perform a compare and set operation on the sequence.- Parameters:
expectedValue- The expected current value.newValue- The value to update to.- Returns:
- true if the operation succeeds, false otherwise.
-
incrementAndGet
public long incrementAndGet()Atomically increment the sequence by one.- Returns:
- The value after the increment
-
addAndGet
public long addAndGet(long increment) Atomically add the supplied value.- Parameters:
increment- The value to add to the sequence.- Returns:
- The value after the increment.
-
getAndAdd
public long getAndAdd(long increment) Perform an atomic getAndAdd operation on the sequence.- Parameters:
increment- The value to add to the sequence.- Returns:
- the value before increment
-
toString
-