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 void
clear()
Clears the counter.void
destroy()
Releases resources used by the SlidingWindowCounter.long
get(int slots)
Deprecated.since 1.12long
getOverallCount()
Returns the overall number of increments.double
getOverallRate()
Returns the overall rate.long
getWindowCount()
Gets the total count for all slots.long
getWindowCount(int slots)
Gets the total count for the last N window slots.double
getWindowRate()
Returns the average rate over the window.double
getWindowRate(int slots)
Returns the average rate over the given window.void
incrementCount()
Increments the count of the current window slot by 1.void
incrementCount(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.
-
-