Package io.atomix.utils.misc
Class SlidingWindowCounter
- java.lang.Object
-
- io.atomix.utils.misc.SlidingWindowCounter
-
public final class SlidingWindowCounter extends Object
Maintains a sliding window of value counts. The sliding window counter is initialized with a number of window slots. Calls to #incrementCount() will increment the value in the current window slot. Periodically the window slides and the oldest value count is dropped. Calls to #get() will get the total count for the last N window slots.
-
-
Constructor Summary
Constructors Constructor Description SlidingWindowCounter(int windowSlots)SlidingWindowCounter(int windowSlots, ThreadContext context)Creates a new sliding window counter with the given total number of window slots.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Releases resources used by the SlidingWindowCounter.longget(int slots)Gets the total count for the last N window slots.voidincrementCount()Increments the count of the current window slot by 1.voidincrementCount(long value)Increments the count of the current window slot by the given value.
-
-
-
Constructor Detail
-
SlidingWindowCounter
public SlidingWindowCounter(int windowSlots)
-
SlidingWindowCounter
public SlidingWindowCounter(int windowSlots, ThreadContext context)Creates a new sliding window counter with the given total number of window slots.- Parameters:
windowSlots- total number of window slots
-
-
Method Detail
-
destroy
public void destroy()
Releases resources used by the SlidingWindowCounter.
-
incrementCount
public void incrementCount()
Increments the count of the current window slot by 1.
-
incrementCount
public void incrementCount(long value)
Increments the count of the current window slot by the given value.- Parameters:
value- value to increment by
-
get
public long get(int slots)
Gets the total count for the last N window slots.- Parameters:
slots- number of slots to include in the count- Returns:
- total count for last N slots
-
-