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
AggregatorHandlemust be created for every uniqueLabelSetrecorded, 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 protectedAggregatorHandle()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description TaccumulateThenReset()Returns the current value into asAggregatorHandleand resets the current value in thisAggregator.booleanacquire()Acquires thisAggregatorfor use.protected abstract TdoAccumulateThenReset()Implementation of theaccumulateThenReset.protected voiddoRecordDouble(double value)Concrete Aggregator instances should implement this method in order support recordings of double values.protected voiddoRecordLong(long value)Concrete Aggregator instances should implement this method in order support recordings of long values.voidrecordDouble(double value)Updates the current aggregator with a newly recordeddoublevalue.voidrecordLong(long value)Updates the current aggregator with a newly recordedlongvalue.voidrelease()Release thisAggregator.booleantryUnmap()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 thisAggregatorfor use. Returnstrueif the entry is still mapped and increases the reference usages, if unmapped returnsfalse.- Returns:
trueif 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:
trueif successful.
-
accumulateThenReset
@Nullable public final T accumulateThenReset()
Returns the current value into asAggregatorHandleand 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 recordedlongvalue.- Parameters:
value- the newlongvalue 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 recordeddoublevalue.- Parameters:
value- the newdoublevalue to be added.
-
doRecordDouble
protected void doRecordDouble(double value)
Concrete Aggregator instances should implement this method in order support recordings of double values.
-
-