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 | +---------------------------------------------------------------+ | 120 bytes for key ... ... | +-+-------------------------------------------------------------+ |R| Label Length | +-+-------------------------------------------------------------+ | 380 bytes of Label ... ... | +---------------------------------------------------------------+ | Repeats to end of buffer ... | | ... | +---------------------------------------------------------------+
Modifier and Type | Class and Description |
---|---|
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 |
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 int |
RECORD_ALLOCATED
Record currently allocated for use..
|
static int |
RECORD_LINGERING
Record was active and now lingering before being reclaimed.
|
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.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.
|
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 RECORD_UNUSED
public static final int RECORD_ALLOCATED
public static final int RECORD_RECLAIMED
public static final int RECORD_LINGERING
public static final int TYPE_ID_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.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_LINGERING
,
RECORD_RECLAIMED
public java.lang.String getCounterLabel(int counterId)
counterId
- to be read.Copyright © 2014-2017 Real Logic Ltd. All Rights Reserved.