public class CountersReader extends 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 | | | +---------------------------------------------------------------+ | Registration Id | | | +---------------------------------------------------------------+ | Owner Id | | | +---------------------------------------------------------------+ | 104 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 (ms) | | | +---------------------------------------------------------------+ | 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 long |
DEFAULT_OWNER_ID
Default owner id of a counter when none is set.
|
static long |
DEFAULT_REGISTRATION_ID
Default registration id of a counter when none is set.
|
static int |
DEFAULT_TYPE_ID
Default type id of a counter when none is supplied.
|
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 Charset |
labelCharset
Charset for the label.
|
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
Max counter Id.
|
static int |
METADATA_LENGTH
Length of a meta data record in bytes.
|
protected AtomicBuffer |
metaDataBuffer
Meta-data buffer.
|
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 |
OWNER_ID_OFFSET
Offset in the record at which the owner id field is stored.
|
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 |
REGISTRATION_ID_OFFSET
Offset in the record at which the registration id field is stored.
|
static int |
TYPE_ID_OFFSET
Offset in the record at which the type id field is stored.
|
protected AtomicBuffer |
valuesBuffer
Values buffer.
|
Constructor and Description |
---|
CountersReader(AtomicBuffer metaDataBuffer,
AtomicBuffer valuesBuffer)
Construct a reader over buffers containing the values and associated metadata.
|
CountersReader(AtomicBuffer metaDataBuffer,
AtomicBuffer valuesBuffer,
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.
|
int |
findByRegistrationId(long registrationId)
Iterate over allocated counters and find the first matching a given registration id.
|
int |
findByTypeIdAndRegistrationId(int typeId,
long registrationId)
Iterate over allocated counters and find the first matching a given type id and registration id.
|
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<String> consumer)
Iterate over all labels in the label buffer.
|
String |
getCounterLabel(int counterId)
Get the label for a given counter id.
|
long |
getCounterOwnerId(int counterId)
Get the owner id for a given counter id as a normal read.
|
long |
getCounterRegistrationId(int counterId)
Get the registration id for a given counter id as a volatile read.
|
int |
getCounterState(int counterId)
Get the state for a given counter id as a volatile read.
|
int |
getCounterTypeId(int counterId)
Get the type id for a given counter id.
|
long |
getCounterValue(int counterId)
Get the value for a given counter id as a volatile read.
|
long |
getFreeForReuseDeadline(int counterId)
Get the deadline (ms) for when a given counter id may be reused as a volatile read.
|
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.
|
protected void |
validateCounterId(int counterId)
Validate if counter Id is valid.
|
AtomicBuffer |
valuesBuffer()
Get the buffer containing the values for the counters.
|
public static final int DEFAULT_TYPE_ID
public static final long DEFAULT_REGISTRATION_ID
public static final long DEFAULT_OWNER_ID
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 REGISTRATION_ID_OFFSET
public static final int OWNER_ID_OFFSET
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 final int maxCounterId
protected final AtomicBuffer metaDataBuffer
protected final AtomicBuffer valuesBuffer
protected final 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, 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 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<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 int findByRegistrationId(long registrationId)
registrationId
- to find.NULL_COUNTER_ID
.public int findByTypeIdAndRegistrationId(int typeId, long registrationId)
typeId
- to find.registrationId
- to find.NULL_COUNTER_ID
.public long getCounterValue(int counterId)
counterId
- to be read.public long getCounterRegistrationId(int counterId)
counterId
- to be read.DEFAULT_REGISTRATION_ID
public long getCounterOwnerId(int counterId)
counterId
- to be read.DEFAULT_OWNER_ID
public int getCounterState(int counterId)
counterId
- to be read.RECORD_UNUSED
,
RECORD_ALLOCATED
,
RECORD_RECLAIMED
public int getCounterTypeId(int counterId)
counterId
- to be read.DEFAULT_TYPE_ID
public long getFreeForReuseDeadline(int counterId)
counterId
- to be read.NOT_FREE_TO_REUSE
if currently
in use.public String getCounterLabel(int counterId)
counterId
- to be read.protected void validateCounterId(int counterId)
counterId
- to validate.IllegalArgumentException
- if counterId < 0 || counterId > maxCounterId
.Copyright © 2014-2021 Real Logic Limited. All Rights Reserved.