Package io.grpc.rls
Class AdaptiveThrottler.TimeBasedAccumulator
- java.lang.Object
-
- io.grpc.rls.AdaptiveThrottler.TimeBasedAccumulator
-
- Enclosing class:
- AdaptiveThrottler
static final class AdaptiveThrottler.TimeBasedAccumulator extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AdaptiveThrottler.TimeBasedAccumulator.Slot
Holds the data for each slot (amount and end timestamp).
-
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()
-
-
-
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
-
slots
private final java.util.concurrent.atomic.AtomicReferenceArray<AdaptiveThrottler.TimeBasedAccumulator.Slot> slots
The array of slots.
-
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 asynchronized(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
-
getSlot
private AdaptiveThrottler.TimeBasedAccumulator.Slot getSlot(long now)
Gets the current slot.
-
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 classjava.lang.Object
-
-