public class TimeEvictionPolicy<T> extends Object implements EvictionPolicy<T,EvictionContext>
Eviction policy that evicts events based on time duration.
EvictionPolicy.Action
Modifier and Type | Field and Description |
---|---|
protected EvictionContext |
evictionContext |
Constructor and Description |
---|
TimeEvictionPolicy(int windowLength)
Constructs a TimeEvictionPolicy that evicts events older than the given window length in millis.
|
Modifier and Type | Method and 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.
|
EvictionContext |
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(EvictionContext 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.
|
String |
toString() |
void |
track(Event<T> event)
Tracks the event to later decide whether
EvictionPolicy.evict(Event) should evict it or not. |
protected volatile EvictionContext evictionContext
public TimeEvictionPolicy(int windowLength)
Constructs a TimeEvictionPolicy that evicts events older than the given window length in millis.
windowLength
- the duration in millisecondspublic 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.
evict
in interface EvictionPolicy<T,EvictionContext>
event
- the input eventEvictionPolicy.Action
to be taken based on the input eventpublic void track(Event<T> event)
EvictionPolicy
Tracks the event to later decide whether EvictionPolicy.evict(Event)
should evict it or not.
track
in interface EvictionPolicy<T,EvictionContext>
event
- the input event to be trackedpublic EvictionContext getContext()
EvictionPolicy
Returns the current context that is part of this eviction policy.
getContext
in interface EvictionPolicy<T,EvictionContext>
public void setContext(EvictionContext context)
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.
setContext
in interface EvictionPolicy<T,EvictionContext>
context
- the eviction contextpublic void reset()
EvictionPolicy
Resets the eviction policy.
reset
in interface EvictionPolicy<T,EvictionContext>
public EvictionContext getState()
EvictionPolicy
Return runtime state to be checkpointed by the framework for restoring the eviction policy in case of failures.
getState
in interface EvictionPolicy<T,EvictionContext>
public void restoreState(EvictionContext state)
EvictionPolicy
Restore the eviction policy from the state that was earlier checkpointed by the framework.
restoreState
in interface EvictionPolicy<T,EvictionContext>
state
- the stateCopyright © 2020 The Apache Software Foundation. All rights reserved.