Package com.lmax.disruptor
Class Sequence
- java.lang.Object
-
- com.lmax.disruptor.Sequence
-
- Direct Known Subclasses:
FixedSequenceGroup,SequenceGroup
public class Sequence extends Object
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
Fields Modifier and Type Field Description protected longp1protected longp10protected longp11protected longp12protected longp13protected longp14protected longp15protected longp2protected longp3protected longp4protected longp5protected longp6protected longp7protected longp9protected longvalue
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddAndGet(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.longincrementAndGet()Atomically 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.StringtoString()
-
-
-
Field Detail
-
p9
protected long p9
-
p10
protected long p10
-
p11
protected long p11
-
p12
protected long p12
-
p13
protected long p13
-
p14
protected long p14
-
p15
protected long p15
-
value
protected volatile long value
-
p1
protected long p1
-
p2
protected long p2
-
p3
protected long p3
-
p4
protected long p4
-
p5
protected long p5
-
p6
protected long p6
-
p7
protected long p7
-
-
Method Detail
-
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.
-
-