Package org.agrona.concurrent.status
Class ConcurrentCountersManager
java.lang.Object
org.agrona.concurrent.status.CountersReader
org.agrona.concurrent.status.CountersManager
org.agrona.concurrent.status.ConcurrentCountersManager
A thread safe extension of
CountersManager which allows intra-process read and write access to the same
counters buffer. Note that inter-process access is not catered for.-
Nested Class Summary
Nested classes/interfaces inherited from class org.agrona.concurrent.status.CountersReader
CountersReader.CounterConsumer, CountersReader.MetaData -
Field Summary
Fields inherited from class org.agrona.concurrent.status.CountersReader
COUNTER_LENGTH, DEFAULT_OWNER_ID, DEFAULT_REFERENCE_ID, DEFAULT_REGISTRATION_ID, DEFAULT_TYPE_ID, 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, OWNER_ID_OFFSET, RECORD_ALLOCATED, RECORD_RECLAIMED, RECORD_UNUSED, REFERENCE_ID_OFFSET, REGISTRATION_ID_OFFSET, TYPE_ID_OFFSET, valuesBuffer -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentCountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer) Construct a counter manager over buffers containing the values and associated metadata.ConcurrentCountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer, Charset labelCharset) Construct a counter manager over buffers containing the values and associated metadata.ConcurrentCountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer, Charset labelCharset, EpochClock epochClock, long freeToReuseTimeoutMs) Create a new counter manager over buffers containing the values and associated metadata. -
Method Summary
Modifier and TypeMethodDescriptionintallocate(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 a key to be provided and copied.intAllocate a new counter with a given label and type.intallocate(String label, int typeId, Consumer<MutableDirectBuffer> keyFunc) Allocate a new counter with a given label.voidappendToLabel(int counterId, String label) Set anAtomicCounterlabel based on counter id.intNumber of counters available to be allocated which is a function ofCountersManager.capacity()minus the number already allocated.voidfree(int counterId) Free the counter identified by counterId.voidsetCounterKey(int counterId, Consumer<MutableDirectBuffer> keyFunc) Set anAtomicCounterkey by on counter id, using a consumer callback to update the key metadata buffer.voidsetCounterKey(int counterId, DirectBuffer keyBuffer, int offset, int length) Set anAtomicCounterkey by on counter id, copying the key metadata from the supplied buffer.voidsetCounterLabel(int counterId, String label) Set anAtomicCounterlabel by counter id.voidsetCounterOwnerId(int counterId, long ownerId) Set anAtomicCounterowner id for a counter id.voidsetCounterReferenceId(int counterId, long referenceId) Set anAtomicCounterreference id for a counter id.voidsetCounterRegistrationId(int counterId, long registrationId) Set anAtomicCounterregistration id for a counter id with ordered memory ordering.voidsetCounterValue(int counterId, long value) Set anAtomicCountervalue based for a counter id with ordered memory ordering.toString()Methods inherited from class org.agrona.concurrent.status.CountersManager
allocate, capacity, newCounter, newCounter, newCounter, newCounterMethods inherited from class org.agrona.concurrent.status.CountersReader
counterOffset, findByRegistrationId, findByTypeIdAndRegistrationId, forEach, forEach, forEach, getCounterLabel, getCounterOwnerId, getCounterReferenceId, getCounterRegistrationId, getCounterState, getCounterTypeId, getCounterValue, getFreeForReuseDeadline, labelCharset, maxCounterId, metaDataBuffer, metaDataOffset, validateCounterId, valuesBuffer
-
Constructor Details
-
ConcurrentCountersManager
Construct a counter manager over buffers containing the values and associated metadata.Counter labels default to
StandardCharsets.UTF_8.- Parameters:
metaDataBuffer- containing the counter metadata.valuesBuffer- containing the counter values.
-
ConcurrentCountersManager
public ConcurrentCountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer, Charset labelCharset) Construct a counter manager over buffers containing the values and associated metadata.- Parameters:
metaDataBuffer- containing the counter metadata.valuesBuffer- containing the counter values.labelCharset- for the label encoding.
-
ConcurrentCountersManager
public ConcurrentCountersManager(AtomicBuffer metaDataBuffer, AtomicBuffer valuesBuffer, Charset labelCharset, EpochClock epochClock, long freeToReuseTimeoutMs) Create a new counter manager over buffers containing the values and associated metadata.- Parameters:
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.
-
-
Method Details
-
available
public int available()Number of counters available to be allocated which is a function ofCountersManager.capacity()minus the number already allocated.- Overrides:
availablein classCountersManager- Returns:
- the number of counter available to be allocated.
-
allocate
Allocate a new counter with a given label and type.- Overrides:
allocatein classCountersManager- Parameters:
label- to describe the counter.typeId- for the type of counter.- Returns:
- the id allocated for the counter.
-
allocate
Allocate a new counter with a given label.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.
- Overrides:
allocatein classCountersManager- Parameters:
label- to describe the counter.typeId- for the type of counter.keyFunc- for setting the key value for the counter.- Returns:
- the id allocated for the counter.
-
allocate
public 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 a key to be provided and copied.If the keyBuffer is null then a copy of the key is not attempted.
- Overrides:
allocatein classCountersManager- Parameters:
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.- Returns:
- the id allocated for the counter.
-
free
public void free(int counterId) Free the counter identified by counterId.- Overrides:
freein classCountersManager- Parameters:
counterId- the counter to freed
-
setCounterValue
public void setCounterValue(int counterId, long value) Set anAtomicCountervalue based for a counter id with ordered memory ordering.- Overrides:
setCounterValuein classCountersManager- Parameters:
counterId- to be set.value- to set for the counter.
-
setCounterRegistrationId
public void setCounterRegistrationId(int counterId, long registrationId) Set anAtomicCounterregistration id for a counter id with ordered memory ordering.- Overrides:
setCounterRegistrationIdin classCountersManager- Parameters:
counterId- to be set.registrationId- to set for the counter.
-
setCounterOwnerId
public void setCounterOwnerId(int counterId, long ownerId) Set anAtomicCounterowner id for a counter id.- Overrides:
setCounterOwnerIdin classCountersManager- Parameters:
counterId- to be set.ownerId- to set for the counter.
-
setCounterReferenceId
public void setCounterReferenceId(int counterId, long referenceId) Set anAtomicCounterreference id for a counter id.- Overrides:
setCounterReferenceIdin classCountersManager- Parameters:
counterId- to be set.referenceId- to set for the counter.
-
setCounterLabel
Set anAtomicCounterlabel by counter id.- Overrides:
setCounterLabelin classCountersManager- Parameters:
counterId- to be set.label- to set for the counter.
-
setCounterKey
Set anAtomicCounterkey by on counter id, using a consumer callback to update the key metadata buffer.- Overrides:
setCounterKeyin classCountersManager- Parameters:
counterId- to be set.keyFunc- callback used to set the key.
-
setCounterKey
Set anAtomicCounterkey by on counter id, copying the key metadata from the supplied buffer.- Overrides:
setCounterKeyin classCountersManager- Parameters:
counterId- to be set.keyBuffer- containing the updated key.offset- offset into buffer.length- length of data to copy.
-
appendToLabel
Set anAtomicCounterlabel based on counter id.- Overrides:
appendToLabelin classCountersManager- Parameters:
counterId- to be set.label- to set for the counter.
-
toString
- Overrides:
toStringin classCountersManager
-