Package 

Class TimeBasedSlidingWindow


  • 
    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.

    • Method Summary

      Modifier and Type Method Description
      final Unit add(T value)
      final Unit forceEviction() Force the eviction process to run.
      final Collection<T> values()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TimeBasedSlidingWindow

        TimeBasedSlidingWindow(Duration windowSize, Function1<T, Unit> evictionHandler, Clock clock)
    • 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.