Class CountEvictionPolicy<T>

  • Type Parameters:
    T - the type of event tracked by this policy.
    All Implemented Interfaces:
    EvictionPolicy<T,​java.lang.Long>

    public class CountEvictionPolicy<T>
    extends java.lang.Object
    implements EvictionPolicy<T,​java.lang.Long>
    An eviction policy that tracks event counts and can evict based on a threshold count.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.atomic.AtomicLong currentCount  
      protected int threshold  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      EvictionPolicy.Action evict​(Event<T> event)
      Decides if an event should be expired from the window, processed in the current window or kept for later processing.
      EvictionContext getContext()
      Returns the current context that is part of this eviction policy.
      java.lang.Long getState()
      Return runtime state to be checkpointed by the framework for restoring the eviction policy in case of failures.
      void reset()
      Resets the eviction policy.
      void restoreState​(java.lang.Long state)
      Restore the eviction policy from the state that was earlier checkpointed by the framework.
      void setContext​(EvictionContext context)
      Sets a context in the eviction policy that can be used while evicting the events.
      java.lang.String toString()  
      void track​(Event<T> event)
      Tracks the event to later decide whether EvictionPolicy.evict(Event) should evict it or not.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • threshold

        protected final int threshold
      • currentCount

        protected final java.util.concurrent.atomic.AtomicLong currentCount
    • Constructor Detail

      • CountEvictionPolicy

        public CountEvictionPolicy​(int count)
    • Method Detail

      • evict

        public EvictionPolicy.Action evict​(Event<T> event)
        Description copied from interface: EvictionPolicy
        Decides if an event should be expired from the window, processed in the current window or kept for later processing.
        Specified by:
        evict in interface EvictionPolicy<T,​java.lang.Long>
        Parameters:
        event - the input event
        Returns:
        the EvictionPolicy.Action to be taken based on the input event
      • setContext

        public void setContext​(EvictionContext context)
        Description copied from interface: EvictionPolicy
        Sets a context in the eviction policy that can be used while evicting the events. E.g. For TimeEvictionPolicy, this could be used to set the reference timestamp.
        Specified by:
        setContext in interface EvictionPolicy<T,​java.lang.Long>
        Parameters:
        context - the eviction context
      • getContext

        public EvictionContext getContext()
        Description copied from interface: EvictionPolicy
        Returns the current context that is part of this eviction policy.
        Specified by:
        getContext in interface EvictionPolicy<T,​java.lang.Long>
        Returns:
        the eviction context
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • reset

        public void reset()
        Description copied from interface: EvictionPolicy
        Resets the eviction policy.
        Specified by:
        reset in interface EvictionPolicy<T,​java.lang.Long>
      • getState

        public java.lang.Long getState()
        Description copied from interface: EvictionPolicy
        Return runtime state to be checkpointed by the framework for restoring the eviction policy in case of failures.
        Specified by:
        getState in interface EvictionPolicy<T,​java.lang.Long>
        Returns:
        the state
      • restoreState

        public void restoreState​(java.lang.Long state)
        Description copied from interface: EvictionPolicy
        Restore the eviction policy from the state that was earlier checkpointed by the framework.
        Specified by:
        restoreState in interface EvictionPolicy<T,​java.lang.Long>
        Parameters:
        state - the state