public class AtomicCounter extends Object implements 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 |
---|---|
AtomicCounter |
appendToLabel(String suffix)
Append to the label for a counter constructed with a
CountersManager . |
void |
close()
Close counter and free the counter slot for reuse of connected to
CountersManager . |
boolean |
compareAndSet(long expectedValue,
long updateValue)
Compare the current value to expected and if true then set to the update value atomically.
|
long |
decrement()
Perform an atomic decrement that will not lose updates across threads.
|
long |
decrementOrdered()
Perform an atomic decrement that is not safe across threads.
|
void |
disconnectCountersManager()
Disconnect from
CountersManager if allocated so it can be closed without freeing the slot. |
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?
|
String |
label()
Return the label for the counter within the
CountersManager . |
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.
|
String |
toString() |
void |
updateKey(Consumer<MutableDirectBuffer> keyFunc)
Update the key for a counter constructed with a
CountersManager . |
void |
updateKey(DirectBuffer keyBuffer,
int offset,
int length)
Update the key for a counter constructed with a
CountersManager . |
void |
updateLabel(String newLabel)
Update the label for the counter constructed with a
CountersManager . |
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 void disconnectCountersManager()
CountersManager
if allocated so it can be closed without freeing the slot.public void close()
CountersManager
.close
in interface AutoCloseable
public boolean isClosed()
public String label()
CountersManager
.CountersManager
.public void updateLabel(String newLabel)
CountersManager
.newLabel
- for the counter with a CountersManager
.IllegalStateException
- is not constructed CountersManager
.public AtomicCounter appendToLabel(String suffix)
CountersManager
.suffix
- for the counter within a CountersManager
.IllegalStateException
- is not constructed CountersManager
.public void updateKey(Consumer<MutableDirectBuffer> keyFunc)
CountersManager
.keyFunc
- callback to use to update the counter's keyIllegalStateException
- is not constructed CountersManager
.public void updateKey(DirectBuffer keyBuffer, int offset, int length)
CountersManager
.keyBuffer
- contains key data to be copied into the counter.offset
- start of the key data within the keyBufferlength
- length of the data within the keyBuffer (must be <= CountersReader.MAX_KEY_LENGTH
)IllegalStateException
- is not constructed CountersManager
.public long increment()
public long incrementOrdered()
public long decrement()
public long decrementOrdered()
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.Copyright © 2014-2021 Real Logic Limited. All Rights Reserved.