public class CountersReader
extends java.lang.Object
This class is threadsafe and can be used across threads.
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 ... | | ... | +---------------------------------------------------------------+
Modifier and Type | Class and Description |
---|---|
static interface |
CountersReader.CounterConsumer
Callback function for consuming basic counter details and value.
|
static interface |
CountersReader.MetaData
Callback function for consuming metadata records of counters.
|
Modifier and Type | Field and Description |
---|---|
static int |
COUNTER_LENGTH
Length of the space allocated to a counter that includes padding to avoid false sharing.
|
static int |
FREE_FOR_REUSE_DEADLINE_OFFSET
Offset in the record at which the deadline (in milliseconds) for when counter may be reused.
|
static int |
FULL_LABEL_LENGTH
Length of a counter label length including length prefix.
|
static int |
KEY_OFFSET
Offset in the record at which the key is stored.
|
static int |
LABEL_OFFSET
Offset in the record at which the label is stored.
|
protected java.nio.charset.Charset |
labelCharset |
static int |
MAX_KEY_LENGTH
Maximum length a key can be.
|
static int |
MAX_LABEL_LENGTH
Maximum length of a label not including its length prefix.
|
protected int |
maxCounterId |
static int |
METADATA_LENGTH
Length of a meta data record in bytes.
|
protected AtomicBuffer |
metaDataBuffer |
static long |
NOT_FREE_TO_REUSE
Deadline to indicate counter is not free to be reused.
|
static int |
NULL_COUNTER_ID
Can be used to representing a null counter id when passed as a argument.
|
static int |
RECORD_ALLOCATED
Record currently allocated for use.
|
static int |
RECORD_RECLAIMED
Record was active and now has been reclaimed.
|
static int |
RECORD_UNUSED
Record has not been used.
|
static int |
TYPE_ID_OFFSET
Offset in the record at which the type id field is stored.
|
protected AtomicBuffer |
valuesBuffer |
Constructor and Description |
---|
CountersReader(AtomicBuffer metaDataBuffer,
AtomicBuffer valuesBuffer)
Construct a reader over buffers containing the values and associated metadata.
|
CountersReader(AtomicBuffer metaDataBuffer,
AtomicBuffer valuesBuffer,
java.nio.charset.Charset labelCharset)
Construct a reader over buffers containing the values and associated metadata.
|
Modifier and Type | Method and Description |
---|---|
static int |
counterOffset(int counterId)
The offset in the counter buffer for a given counterId.
|
void |
forEach(CountersReader.CounterConsumer consumer)
Iterate over the counters and provide the value and basic metadata.
|
void |
forEach(CountersReader.MetaData metaData)
Iterate over all the metadata in the buffer.
|
void |
forEach(IntObjConsumer<java.lang.String> consumer)
Iterate over all labels in the label buffer.
|
java.lang.String |
getCounterLabel(int counterId)
Get the label for a given counter id.
|
int |
getCounterState(int counterId)
Get the state for a given counter id as a volatile read.
|
long |
getCounterValue(int counterId)
Get the value for a given counter id as a volatile read.
|
long |
getFreeForReuseDeadline(int counterId)
Get the deadline (in milliseconds) for when a given counter id may be reused.
|
java.nio.charset.Charset |
labelCharset()
The
Charset used for the encoded label. |
int |
maxCounterId()
Get the maximum counter id which can be supported given the length of the values buffer.
|
AtomicBuffer |
metaDataBuffer()
Get the buffer containing the metadata for the counters.
|
static int |
metaDataOffset(int counterId)
The offset in the metadata buffer for a given id.
|
AtomicBuffer |
valuesBuffer()
Get the buffer containing the values for the counters.
|
public static final int NULL_COUNTER_ID
public static final int RECORD_UNUSED
public static final int RECORD_ALLOCATED
public static final int RECORD_RECLAIMED
public static final long NOT_FREE_TO_REUSE
public static final int TYPE_ID_OFFSET
public static final int FREE_FOR_REUSE_DEADLINE_OFFSET
public static final int KEY_OFFSET
public static final int LABEL_OFFSET
public static final int FULL_LABEL_LENGTH
public static final int MAX_LABEL_LENGTH
public static final int MAX_KEY_LENGTH
public static final int METADATA_LENGTH
public static final int COUNTER_LENGTH
protected int maxCounterId
protected final AtomicBuffer metaDataBuffer
protected final AtomicBuffer valuesBuffer
protected final java.nio.charset.Charset labelCharset
public CountersReader(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer)
Counter labels default to StandardCharsets.UTF_8
.
metaDataBuffer
- containing the counter metadata.valuesBuffer
- containing the counter values.public CountersReader(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer, java.nio.charset.Charset labelCharset)
metaDataBuffer
- containing the counter metadata.valuesBuffer
- containing the counter values.labelCharset
- for the label encoding.public int maxCounterId()
public AtomicBuffer metaDataBuffer()
public AtomicBuffer valuesBuffer()
public java.nio.charset.Charset labelCharset()
Charset
used for the encoded label.Charset
used for the encoded label.public static int counterOffset(int counterId)
counterId
- for which the offset should be provided.public static int metaDataOffset(int counterId)
counterId
- for the record.public void forEach(IntObjConsumer<java.lang.String> consumer)
consumer
- function to be called for each label.public void forEach(CountersReader.CounterConsumer consumer)
consumer
- for each allocated counter.public void forEach(CountersReader.MetaData metaData)
metaData
- function to be called for each metadata record.public long getCounterValue(int counterId)
counterId
- to be read.public int getCounterState(int counterId)
counterId
- to be read.RECORD_UNUSED
,
RECORD_ALLOCATED
,
RECORD_RECLAIMED
public long getFreeForReuseDeadline(int counterId)
counterId
- to be read.NOT_FREE_TO_REUSE
if
currently in use.public java.lang.String getCounterLabel(int counterId)
counterId
- to be read.Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.