Class AggregatorHandle<T>
- java.lang.Object
-
- io.opentelemetry.sdk.metrics.aggregator.AggregatorHandle<T>
-
@ThreadSafe public abstract class AggregatorHandle<T> extends Object
Aggregator represents the abstract class that is used for synchronous instruments. It must be thread-safe and avoid locking when possible, because values are recorded synchronously on the calling thread.An
AggregatorHandle
must be created for every uniqueLabelSet
recorded, and can be referenced by the bound instruments.It atomically counts the number of references (usages) while also keeping a state of mapped/unmapped into an external map. It uses an atomic value where the least significant bit is used to keep the state of mapping ('1' is used for unmapped and '0' is for mapped) and the rest of the bits are used for reference (usage) counting.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AggregatorHandle()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
accumulateThenReset()
Returns the current value into asAggregatorHandle
and resets the current value in thisAggregator
.boolean
acquire()
Acquires thisAggregator
for use.protected abstract T
doAccumulateThenReset()
Implementation of theaccumulateThenReset
.protected void
doRecordDouble(double value)
Concrete Aggregator instances should implement this method in order support recordings of double values.protected void
doRecordLong(long value)
Concrete Aggregator instances should implement this method in order support recordings of long values.void
recordDouble(double value)
Updates the current aggregator with a newly recordeddouble
value.void
recordLong(long value)
Updates the current aggregator with a newly recordedlong
value.void
release()
Release thisAggregator
.boolean
tryUnmap()
Flips the mapped bit to "unmapped" state and returns true if both of the following conditions are true upon entry to this function: 1) There are no active references; 2) The mapped bit is in "mapped" state; otherwise no changes are done to mapped bit and false is returned.
-
-
-
Method Detail
-
acquire
public final boolean acquire()
Acquires thisAggregator
for use. Returnstrue
if the entry is still mapped and increases the reference usages, if unmapped returnsfalse
.- Returns:
true
if successful.
-
release
public final void release()
Release thisAggregator
. It decreases the reference usage.
-
tryUnmap
public final boolean tryUnmap()
Flips the mapped bit to "unmapped" state and returns true if both of the following conditions are true upon entry to this function: 1) There are no active references; 2) The mapped bit is in "mapped" state; otherwise no changes are done to mapped bit and false is returned.- Returns:
true
if successful.
-
accumulateThenReset
@Nullable public final T accumulateThenReset()
Returns the current value into asAggregatorHandle
and resets the current value in thisAggregator
.
-
doAccumulateThenReset
protected abstract T doAccumulateThenReset()
Implementation of theaccumulateThenReset
.
-
recordLong
public final void recordLong(long value)
Updates the current aggregator with a newly recordedlong
value.- Parameters:
value
- the newlong
value to be added.
-
doRecordLong
protected void doRecordLong(long value)
Concrete Aggregator instances should implement this method in order support recordings of long values.
-
recordDouble
public final void recordDouble(double value)
Updates the current aggregator with a newly recordeddouble
value.- Parameters:
value
- the newdouble
value to be added.
-
doRecordDouble
protected void doRecordDouble(double value)
Concrete Aggregator instances should implement this method in order support recordings of double values.
-
-