Package org.onlab.util
Class SlidingWindowCounter
- java.lang.Object
-
- org.onlab.util.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)Creates a new sliding window counter with the given total number of window slots.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Clears the counter.voiddestroy()Releases resources used by the SlidingWindowCounter.longget(int slots)Deprecated.since 1.12longgetOverallCount()Returns the overall number of increments.doublegetOverallRate()Returns the overall rate.longgetWindowCount()Gets the total count for all slots.longgetWindowCount(int slots)Gets the total count for the last N window slots.doublegetWindowRate()Returns the average rate over the window.doublegetWindowRate(int slots)Returns the average rate over the given window.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.
-
-
-
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
@Deprecated public long get(int slots)
Deprecated.since 1.12Gets 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
-
getWindowCount
public long getWindowCount()
Gets the total count for all slots.- Returns:
- total count for all slots
-
getWindowCount
public long getWindowCount(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
-
getWindowRate
public double getWindowRate()
Returns the average rate over the window.- Returns:
- the average rate over the window
-
getWindowRate
public double getWindowRate(int slots)
Returns the average rate over the given window.- Parameters:
slots- the number of slots to include in the window- Returns:
- the average rate over the given window
-
getOverallCount
public long getOverallCount()
Returns the overall number of increments.- Returns:
- the overall number of increments
-
getOverallRate
public double getOverallRate()
Returns the overall rate.- Returns:
- the overall rate
-
clear
public void clear()
Clears the counter.
-
-