W - The type of Windows on which this Trigger can operate.public abstract class Trigger<W extends Window> extends Object implements Serializable
Trigger determines 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 the GroupWindowAssigner. These panes all have their own instance of the Trigger.
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Trigger.OnMergeContext
Extension of
Trigger.TriggerContext that is given to onMerge(Window,
OnMergeContext). |
static interface |
Trigger.TriggerContext
A context object that is given to
Trigger methods to allow them to register timer
callbacks and deal with state. |
| Constructor and Description |
|---|
Trigger() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canMerge()
Returns true if this trigger supports merging of trigger state and can therefore.
|
abstract void |
clear(W window)
Clears any state that the trigger might still hold for the given window.
|
abstract boolean |
onElement(Object element,
long timestamp,
W window)
Called for every element that gets added to a pane.
|
abstract boolean |
onEventTime(long time,
W window)
Called when an event-time timer that was set using the trigger context fires.
|
void |
onMerge(W window,
Trigger.OnMergeContext mergeContext)
Called when several windows have been merged into one window by the
org.apache.flink.streaming.api.windowing.assigners.WindowAssigner. |
abstract boolean |
onProcessingTime(long time,
W window)
Called when a processing-time timer that was set using the trigger context fires.
|
abstract void |
open(Trigger.TriggerContext ctx)
Initialization method for the trigger.
|
public abstract void open(Trigger.TriggerContext ctx) throws Exception
ctx - A context object that can be used to get states.Exceptionpublic abstract boolean onElement(Object element, long timestamp, W window) throws Exception
element - The element that arrived.timestamp - The timestamp of the element that arrived.window - The window to which the element is being added.Exceptionpublic abstract boolean onProcessingTime(long time,
W window)
throws Exception
Note: This method is not called in case the window does not contain any elements. Thus, if
you return PURGE from 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.
time - The timestamp at which the timer fired.window - The window for which the timer fired.Exceptionpublic abstract boolean onEventTime(long time,
W window)
throws Exception
Note: This method is not called in case the window does not contain any elements. Thus, if
you return PURGE from 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.
time - The timestamp at which the timer fired.window - The window for which the timer fired.Exceptionpublic boolean canMerge()
If this returns true you must properly implement onMerge(Window,
OnMergeContext)
public void onMerge(W window, Trigger.OnMergeContext mergeContext) throws Exception
org.apache.flink.streaming.api.windowing.assigners.WindowAssigner.window - The new window that results from the merge.Exceptionpublic abstract void clear(W window) throws Exception
Trigger.TriggerContext.registerEventTimeTimer(long) and
Trigger.TriggerContext.registerProcessingTimeTimer(long) should be deleted here as well as
state acquired using TriggerContext#getPartitionedState(StateDescriptor).ExceptionCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.