Class DefaultCounter

  • All Implemented Interfaces:
    Counter

    public class DefaultCounter
    extends java.lang.Object
    implements Counter
    A default Counter implementation that uses an AtomicLong to count events.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Counter NOOP  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void increment()
      Increment the counter by 1.
      void increment​(long amount)
      Increment the counter by the provided amount.
      java.lang.String toString()  
      MetricsContext.Unit unit()
      The unit of the counter.
      long value()
      Reports the current count.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NOOP

        public static final Counter NOOP
    • Method Detail

      • increment

        public void increment()
        Description copied from interface: Counter
        Increment the counter by 1.
        Specified by:
        increment in interface Counter
      • increment

        public void increment​(long amount)
        Description copied from interface: Counter
        Increment the counter by the provided amount.

        Implementations may skip the overflow check for better write throughput.

        Specified by:
        increment in interface Counter
        Parameters:
        amount - to be incremented.
      • value

        public long value()
        Description copied from interface: Counter
        Reports the current count.
        Specified by:
        value in interface Counter
        Returns:
        The current count.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • unit

        public MetricsContext.Unit unit()
        Description copied from interface: Counter
        The unit of the counter.
        Specified by:
        unit in interface Counter
        Returns:
        The unit of the counter.