public class AtomicCounter
extends java.lang.Object
implements java.lang.AutoCloseable
AtomicBuffer
that can be read across threads and processes.Constructor and Description |
---|
AtomicCounter(AtomicBuffer buffer,
int counterId)
Map a counter over a buffer.
|
AtomicCounter(AtomicBuffer buffer,
int counterId,
CountersManager countersManager)
Map a counter over a buffer.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Free the counter slot for reuse.
|
boolean |
compareAndSet(long expectedValue,
long updateValue)
Compare the current value to expected and if true then set to the update value atomically.
|
long |
get()
Get the latest value for the counter with volatile semantics.
|
long |
getAndAdd(long increment)
Add an increment to the counter that will not lose updates across threads.
|
long |
getAndAddOrdered(long increment)
Add an increment to the counter with ordered store semantics.
|
long |
getAndSet(long value)
Get the current value of a counter and atomically set it to a new value.
|
long |
getWeak()
Get the value of the counter using weak ordering semantics.
|
int |
id()
Identity for the counter within the
CountersManager . |
long |
increment()
Perform an atomic increment that will not lose updates across threads.
|
long |
incrementOrdered()
Perform an atomic increment that is not safe across threads.
|
boolean |
isClosed()
Has this counter been closed?
|
boolean |
proposeMax(long proposedValue)
Set the value to a new proposedValue if greater than the current value with memory ordering semantics.
|
boolean |
proposeMaxOrdered(long proposedValue)
Set the value to a new proposedValue if greater than the current value with memory ordering semantics.
|
void |
set(long value)
Set the counter with volatile semantics.
|
void |
setOrdered(long value)
Set the counter with ordered semantics.
|
void |
setWeak(long value)
Set the counter with normal semantics.
|
public AtomicCounter(AtomicBuffer buffer, int counterId)
buffer
- containing the counter.counterId
- identifier of the counter.public AtomicCounter(AtomicBuffer buffer, int counterId, CountersManager countersManager)
buffer
- containing the counter.counterId
- identifier for the counter.countersManager
- to be called to free the counter on close.public int id()
CountersManager
.CountersManager
.public boolean isClosed()
public long increment()
public long incrementOrdered()
public void set(long value)
value
- to be set with volatile semantics.public void setOrdered(long value)
value
- to be set with ordered semantics.public void setWeak(long value)
value
- to be set with normal semantics.public long getAndAdd(long increment)
increment
- to be added.public long getAndAddOrdered(long increment)
increment
- to be added with ordered store semantics.public long getAndSet(long value)
value
- to be set.public boolean compareAndSet(long expectedValue, long updateValue)
expectedValue
- for the counter.updateValue
- for the counter.public long get()
public long getWeak()
public boolean proposeMax(long proposedValue)
proposedValue
- for the new max.public boolean proposeMaxOrdered(long proposedValue)
proposedValue
- for the new max.public void close()
close
in interface java.lang.AutoCloseable
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.