Class 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 unique LabelSet 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 as AggregatorHandle and resets the current value in this Aggregator.
      boolean acquire()
      Acquires this Aggregator for use.
      protected abstract T doAccumulateThenReset()
      Implementation of the accumulateThenReset.
      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 recorded double value.
      void recordLong​(long value)
      Updates the current aggregator with a newly recorded long value.
      void release()
      Release this Aggregator.
      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.
    • Constructor Detail

      • AggregatorHandle

        protected AggregatorHandle()
    • Method Detail

      • acquire

        public final boolean acquire()
        Acquires this Aggregator for use. Returns true if the entry is still mapped and increases the reference usages, if unmapped returns false.
        Returns:
        true if successful.
      • release

        public final void release()
        Release this Aggregator. 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 as AggregatorHandle and resets the current value in this Aggregator.
      • doAccumulateThenReset

        protected abstract T doAccumulateThenReset()
        Implementation of the accumulateThenReset.
      • recordLong

        public final void recordLong​(long value)
        Updates the current aggregator with a newly recorded long value.
        Parameters:
        value - the new long 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 recorded double value.
        Parameters:
        value - the new double value to be added.
      • doRecordDouble

        protected void doRecordDouble​(double value)
        Concrete Aggregator instances should implement this method in order support recordings of double values.