I
- Type of the input elements.O
- Type of the output elements.@PublicEvolving public interface ProcessFunction<I,O> extends Function
The function will be called for every element in the input stream and can produce zero or more output. The function can also query the time and set timers. When reacting to the firing of set timers the function can emit yet more elements.
The function will be called for every element in the input stream and can produce
zero or more output elements. Contrary to the
FlatMapFunction
, this function can also query
the time (both event and processing) and set timers, through the provided ProcessFunction.Context
.
When reacting to the firing of set timers the function can directly emit a result, and/or
register a timer that will trigger an action in the future.
Modifier and Type | Interface and Description |
---|---|
static interface |
ProcessFunction.Context
Information available in an invocation of
processElement(Object, Context, Collector)
or onTimer(long, OnTimerContext, Collector) . |
static interface |
ProcessFunction.OnTimerContext
Information available in an invocation of
onTimer(long, OnTimerContext, Collector) . |
Modifier and Type | Method and Description |
---|---|
void |
onTimer(long timestamp,
ProcessFunction.OnTimerContext ctx,
Collector<O> out)
Called when a timer set using
TimerService fires. |
void |
processElement(I value,
ProcessFunction.Context ctx,
Collector<O> out)
Process one element from the input stream.
|
void processElement(I value, ProcessFunction.Context ctx, Collector<O> out) throws Exception
This function can output zero or more elements using the Collector
parameter
and also update internal state or set timers using the ProcessFunction.Context
parameter.
value
- The input value.ctx
- A ProcessFunction.Context
that allows querying the timestamp of the element and getting
a TimerService
for registering timers and querying the time. The
context is only valid during the invocation of this method, do not store it.out
- The collector for returning result values.Exception
- This method may throw exceptions. Throwing an exception will cause the operation
to fail and may trigger recovery.void onTimer(long timestamp, ProcessFunction.OnTimerContext ctx, Collector<O> out) throws Exception
TimerService
fires.timestamp
- The timestamp of the firing timer.ctx
- An ProcessFunction.OnTimerContext
that allows querying the timestamp of the firing timer,
querying the TimeDomain
of the firing timer and getting a
TimerService
for registering timers and querying the time.
The context is only valid during the invocation of this method, do not store it.out
- The collector for returning result values.Exception
- This method may throw exceptions. Throwing an exception will cause the operation
to fail and may trigger recovery.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.