Class Trigger<W extends Window>
- java.lang.Object
-
- org.apache.flink.table.runtime.operators.window.groupwindow.triggers.Trigger<W>
-
- Type Parameters:
W- The type ofWindowson which thisTriggercan operate.
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ElementTriggers.CountElement,ElementTriggers.EveryElement,WindowTrigger
public abstract class Trigger<W extends Window> extends Object implements Serializable
ATriggerdetermines when a pane of a window should be evaluated to emit the results for that part of the window.A pane is the bucket of elements that have the same key and same
Window. An element can be in multiple panes if it was assigned to multiple windows by theGroupWindowAssigner. These panes all have their own instance of theTrigger.Triggers must not maintain state internally since they can be re-created or reused for different keys. All necessary state should be persisted using the state abstraction available on the
Trigger.TriggerContext.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTrigger.OnMergeContextExtension ofTrigger.TriggerContextthat is given toonMerge(Window, OnMergeContext).static interfaceTrigger.TriggerContextA context object that is given toTriggermethods to allow them to register timer callbacks and deal with state.
-
Constructor Summary
Constructors Constructor Description Trigger()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancanMerge()Returns true if this trigger supports merging of trigger state and can therefore.abstract voidclear(W window)Clears any state that the trigger might still hold for the given window.abstract booleanonElement(Object element, long timestamp, W window)Called for every element that gets added to a pane.abstract booleanonEventTime(long time, W window)Called when an event-time timer that was set using the trigger context fires.voidonMerge(W window, Trigger.OnMergeContext mergeContext)Called when several windows have been merged into one window by theWindowAssigner.abstract booleanonProcessingTime(long time, W window)Called when a processing-time timer that was set using the trigger context fires.abstract voidopen(Trigger.TriggerContext ctx)Initialization method for the trigger.
-
-
-
Method Detail
-
open
public abstract void open(Trigger.TriggerContext ctx) throws Exception
Initialization method for the trigger. Creates states in this method.- Parameters:
ctx- A context object that can be used to get states.- Throws:
Exception
-
onElement
public abstract boolean onElement(Object element, long timestamp, W window) throws Exception
Called for every element that gets added to a pane. The result of this will determine whether the pane is evaluated to emit results.- Parameters:
element- The element that arrived.timestamp- The timestamp of the element that arrived.window- The window to which the element is being added.- Returns:
- true for firing the window, false for no action
- Throws:
Exception
-
onProcessingTime
public abstract boolean onProcessingTime(long time, W window) throws ExceptionCalled when a processing-time timer that was set using the trigger context fires.Note: This method is not called in case the window does not contain any elements. Thus, if you return
PURGEfrom a trigger method and you expect to do cleanup in a future invocation of a timer callback it might be wise to clean any state that you would clean in the timer callback.- Parameters:
time- The timestamp at which the timer fired.window- The window for which the timer fired.- Returns:
- true for firing the window, false for no action
- Throws:
Exception
-
onEventTime
public abstract boolean onEventTime(long time, W window) throws ExceptionCalled when an event-time timer that was set using the trigger context fires.Note: This method is not called in case the window does not contain any elements. Thus, if you return
PURGEfrom a trigger method and you expect to do cleanup in a future invocation of a timer callback it might be wise to clean any state that you would clean in the timer callback.- Parameters:
time- The timestamp at which the timer fired.window- The window for which the timer fired.- Returns:
- true for firing the window, false for no action
- Throws:
Exception
-
canMerge
public boolean canMerge()
Returns true if this trigger supports merging of trigger state and can therefore.If this returns
trueyou must properly implementonMerge(Window, OnMergeContext)
-
onMerge
public void onMerge(W window, Trigger.OnMergeContext mergeContext) throws Exception
Called when several windows have been merged into one window by theWindowAssigner.- Parameters:
window- The new window that results from the merge.- Throws:
Exception
-
clear
public abstract void clear(W window) throws Exception
Clears any state that the trigger might still hold for the given window. This is called when a window is purged. Timers set usingTrigger.TriggerContext.registerEventTimeTimer(long)andTrigger.TriggerContext.registerProcessingTimeTimer(long)should be deleted here as well as state acquired usingTriggerContext#getPartitionedState(StateDescriptor).- Throws:
Exception
-
-