public class CountersManager extends CountersReader
This class in not threadsafe. Counters should be centrally managed.
Values Buffer
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Counter Value | | | +---------------------------------------------------------------+ | 120 bytes of padding ... ... | +---------------------------------------------------------------+ | Repeats to end of buffer ... | | ... | +---------------------------------------------------------------+
Meta Data Buffer
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Record State | +---------------------------------------------------------------+ | Type Id | +---------------------------------------------------------------+ | Free-for-reuse Deadline | | | +---------------------------------------------------------------+ | 112 bytes for key ... ... | +-+-------------------------------------------------------------+ |R| Label Length | +-+-------------------------------------------------------------+ | 380 bytes of Label ... ... | +---------------------------------------------------------------+ | Repeats to end of buffer ... | | ... | +---------------------------------------------------------------+
CountersReader.CounterConsumer, CountersReader.MetaData
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_TYPE_ID
Default type id of a counter when none is supplied.
|
COUNTER_LENGTH, FREE_FOR_REUSE_DEADLINE_OFFSET, FULL_LABEL_LENGTH, KEY_OFFSET, LABEL_OFFSET, labelCharset, MAX_KEY_LENGTH, MAX_LABEL_LENGTH, maxCounterId, METADATA_LENGTH, metaDataBuffer, NOT_FREE_TO_REUSE, NULL_COUNTER_ID, RECORD_ALLOCATED, RECORD_RECLAIMED, RECORD_UNUSED, TYPE_ID_OFFSET, valuesBuffer
Constructor and Description |
---|
CountersManager(AtomicBuffer metaDataBuffer,
AtomicBuffer valuesBuffer)
Create a new counter buffer manager over two buffers.
|
CountersManager(AtomicBuffer metaDataBuffer,
AtomicBuffer valuesBuffer,
java.nio.charset.Charset labelCharset)
Create a new counter buffer manager over two buffers.
|
CountersManager(AtomicBuffer metaDataBuffer,
AtomicBuffer valuesBuffer,
java.nio.charset.Charset labelCharset,
EpochClock epochClock,
long freeToReuseTimeoutMs)
Create a new counter buffer manager over two buffers.
|
Modifier and Type | Method and Description |
---|---|
int |
allocate(int typeId,
DirectBuffer keyBuffer,
int keyOffset,
int keyLength,
DirectBuffer labelBuffer,
int labelOffset,
int labelLength)
Allocate a counter with the minimum of allocation by allowing the label an key to be provided and copied.
|
int |
allocate(java.lang.String label)
Allocate a new counter with a given label with a default type of
DEFAULT_TYPE_ID . |
int |
allocate(java.lang.String label,
int typeId)
Allocate a new counter with a given label and type.
|
int |
allocate(java.lang.String label,
int typeId,
java.util.function.Consumer<MutableDirectBuffer> keyFunc)
Allocate a new counter with a given label.
|
void |
free(int counterId)
Free the counter identified by counterId.
|
AtomicCounter |
newCounter(int typeId,
DirectBuffer keyBuffer,
int keyOffset,
int keyLength,
DirectBuffer labelBuffer,
int labelOffset,
int labelLength)
Allocate a counter record and wrap it with a new
AtomicCounter for use. |
AtomicCounter |
newCounter(java.lang.String label)
Allocate a counter record and wrap it with a new
AtomicCounter for use with a default type
of DEFAULT_TYPE_ID . |
AtomicCounter |
newCounter(java.lang.String label,
int typeId)
Allocate a counter record and wrap it with a new
AtomicCounter for use. |
AtomicCounter |
newCounter(java.lang.String label,
int typeId,
java.util.function.Consumer<MutableDirectBuffer> keyFunc)
Allocate a counter record and wrap it with a new
AtomicCounter for use. |
void |
setCounterValue(int counterId,
long value)
Set an
AtomicCounter value based on counterId. |
counterOffset, forEach, forEach, forEach, getCounterLabel, getCounterState, getCounterValue, getFreeForReuseDeadline, labelCharset, maxCounterId, metaDataBuffer, metaDataOffset, valuesBuffer
public static final int DEFAULT_TYPE_ID
public CountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer, java.nio.charset.Charset labelCharset, EpochClock epochClock, long freeToReuseTimeoutMs)
metaDataBuffer
- containing the types, keys, and labels for the counters.valuesBuffer
- containing the values of the counters themselves.labelCharset
- for the label encoding.epochClock
- to use for determining time for keep counter from being reused after being freed.freeToReuseTimeoutMs
- timeout (in milliseconds) to keep counter from being reused after being freed.public CountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer)
metaDataBuffer
- containing the types, keys, and labels for the counters.valuesBuffer
- containing the values of the counters themselves.public CountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer, java.nio.charset.Charset labelCharset)
metaDataBuffer
- containing the types, keys, and labels for the counters.valuesBuffer
- containing the values of the counters themselves.labelCharset
- for the label encoding.public int allocate(java.lang.String label)
DEFAULT_TYPE_ID
.label
- to describe the counter.public int allocate(java.lang.String label, int typeId)
label
- to describe the counter.typeId
- for the type of counter.public int allocate(java.lang.String label, int typeId, java.util.function.Consumer<MutableDirectBuffer> keyFunc)
The key function will be called with a buffer with the exact length of available key space in the record for the user to store what they want for the key. No offset is required.
label
- to describe the counter.typeId
- for the type of counter.keyFunc
- for setting the key value for the counter.public int allocate(int typeId, DirectBuffer keyBuffer, int keyOffset, int keyLength, DirectBuffer labelBuffer, int labelOffset, int labelLength)
If the keyBuffer is null then a copy of the key is not attempted.
typeId
- for the counter.keyBuffer
- containing the optional key for the counter.keyOffset
- within the keyBuffer at which the key begins.keyLength
- of the key in the keyBuffer.labelBuffer
- containing the mandatory label for the counter.labelOffset
- within the labelBuffer at which the label begins.labelLength
- of the label in the labelBuffer.public AtomicCounter newCounter(java.lang.String label)
AtomicCounter
for use with a default type
of DEFAULT_TYPE_ID
.label
- to describe the counter.AtomicCounter
public AtomicCounter newCounter(java.lang.String label, int typeId)
AtomicCounter
for use.label
- to describe the counter.typeId
- for the type of counter.AtomicCounter
public AtomicCounter newCounter(java.lang.String label, int typeId, java.util.function.Consumer<MutableDirectBuffer> keyFunc)
AtomicCounter
for use.label
- to describe the counter.typeId
- for the type of counter.keyFunc
- for setting the key value for the counter.AtomicCounter
public AtomicCounter newCounter(int typeId, DirectBuffer keyBuffer, int keyOffset, int keyLength, DirectBuffer labelBuffer, int labelOffset, int labelLength)
AtomicCounter
for use.
If the keyBuffer is null then a copy of the key is not attempted.
typeId
- for the counter.keyBuffer
- containing the optional key for the counter.keyOffset
- within the keyBuffer at which the key begins.keyLength
- of the key in the keyBuffer.labelBuffer
- containing the mandatory label for the counter.labelOffset
- within the labelBuffer at which the label begins.labelLength
- of the label in the labelBuffer.public void free(int counterId)
counterId
- the counter to freedpublic void setCounterValue(int counterId, long value)
AtomicCounter
value based on counterId.counterId
- to be set.value
- to set for the counter.Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.