T
- The type of elements on which this Trigger
works.W
- The type of Windows
on which this Trigger
can operate.@PublicEvolving public abstract class Trigger<T,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 (assigned by the
KeySelector
) and same Window
. An element can
be in multiple panes of it was assigned to multiple windows by the
WindowAssigner
. 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.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 |
---|---|
void |
clear(W window,
Trigger.TriggerContext ctx)
Clears any state that the trigger might still hold for the given window.
|
abstract TriggerResult |
onElement(T element,
long timestamp,
W window,
Trigger.TriggerContext ctx)
Called for every element that gets added to a pane.
|
abstract TriggerResult |
onEventTime(long time,
W window,
Trigger.TriggerContext ctx)
Called when an event-time timer that was set using the trigger context fires.
|
abstract TriggerResult |
onProcessingTime(long time,
W window,
Trigger.TriggerContext ctx)
Called when a processing-time timer that was set using the trigger context fires.
|
public abstract TriggerResult onElement(T element, long timestamp, W window, Trigger.TriggerContext ctx) throws Exception
element
- The element that arrived.timestamp
- The timestamp of the element that arrived.window
- The window to which this pane belongs.ctx
- A context object that can be used to register timer callbacks.Exception
public abstract TriggerResult onProcessingTime(long time, W window, Trigger.TriggerContext ctx) throws Exception
time
- The timestamp at which the timer fired.ctx
- A context object that can be used to register timer callbacks.Exception
public abstract TriggerResult onEventTime(long time, W window, Trigger.TriggerContext ctx) throws Exception
time
- The timestamp at which the timer fired.ctx
- A context object that can be used to register timer callbacks.Exception
public void clear(W window, Trigger.TriggerContext ctx) throws Exception
Trigger.TriggerContext.registerEventTimeTimer(long)
and Trigger.TriggerContext.registerProcessingTimeTimer(long)
should be deleted here as
well as state acquired using Trigger.TriggerContext.getPartitionedState(StateDescriptor)
.
By default, this method does nothing.
Exception
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.