-
public class TimeBasedSlidingWindow<T extends Object>Maintain a queue of values which fall inside the given window size.
Eviction is done after adding an element in add, and can be forced via forceEviction. Any time an element is evicted, the evictionHandler method is called with the evicted value. Forcing eviction before any access is done is required, as it's possible there are stale values in the collection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classTimeBasedSlidingWindow.TimeEntry
-
Constructor Summary
Constructors Constructor Description TimeBasedSlidingWindow(Duration windowSize, Function1<T, Unit> evictionHandler, Clock clock)
-
Method Summary
Modifier and Type Method Description final Unitadd(T value)final UnitforceEviction()Force the eviction process to run. final Collection<T>values()-
-
Method Detail
-
forceEviction
final Unit forceEviction()
Force the eviction process to run. It's important this be invoked if there's a chance values have gone out of the window since the last call to add.
-
values
final Collection<T> values()
-
-
-
-