Package io.grpc.rls

Class AdaptiveThrottler.TimeBasedAccumulator

  • Enclosing class:
    AdaptiveThrottler

    static final class AdaptiveThrottler.TimeBasedAccumulator
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int currentIndex
      The current index into the slot array.
      private long interval
      The time interval this statistic is concerned with.
      private static int NUM_SLOTS
      The number of slots.
      private long slotNanos
      The number of nanoseconds in each slot.
      private java.util.concurrent.atomic.AtomicReferenceArray<AdaptiveThrottler.TimeBasedAccumulator.Slot> slots
      The array of slots.
      private com.google.common.base.Ticker ticker  
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeBasedAccumulator​(long internalNanos, com.google.common.base.Ticker ticker)
      Interval constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) long get​(long now)
      Returns the count of the statistic using the specified time value as the current time.
      (package private) long getInterval()
      Returns the interval used by this statistic.
      private AdaptiveThrottler.TimeBasedAccumulator.Slot getSlot​(long now)
      Gets the current slot.
      private long getSlotEndTime​(long time)
      Computes the end boundary since the last bucket can be partial size.
      (package private) void increment​(long now)
      Increments the count of the statistic by the specified amount for the specified time.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • NUM_SLOTS

        private static final int NUM_SLOTS
        The number of slots. This value determines the accuracy of the get() method to interval / NUM_SLOTS.
        See Also:
        Constant Field Values
      • interval

        private final long interval
        The time interval this statistic is concerned with.
      • slotNanos

        private final long slotNanos
        The number of nanoseconds in each slot.
      • currentIndex

        private volatile int currentIndex
        The current index into the slot array. currentIndex may be safely read without synchronization, but all writes must be performed inside of a synchronized(this){} block.
      • ticker

        private final com.google.common.base.Ticker ticker
    • Constructor Detail

      • TimeBasedAccumulator

        TimeBasedAccumulator​(long internalNanos,
                             com.google.common.base.Ticker ticker)
        Interval constructor.
        Parameters:
        internalNanos - is the stat interval in nanoseconds
        Throws:
        java.lang.IllegalArgumentException - if the supplied interval is too small to be effective
    • Method Detail

      • getSlotEndTime

        private long getSlotEndTime​(long time)
        Computes the end boundary since the last bucket can be partial size.
        Parameters:
        time - the time for which to find the nearest slot boundary
        Returns:
        the nearest slot boundary in nanos
      • getInterval

        long getInterval()
        Returns the interval used by this statistic.
        Returns:
        the interval
      • increment

        void increment​(long now)
        Increments the count of the statistic by the specified amount for the specified time.
        Parameters:
        now - is the time used to increment the count
      • get

        long get​(long now)
        Returns the count of the statistic using the specified time value as the current time.
        Parameters:
        now - the current time
        Returns:
        the statistic count
      • toString

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