I
- Type of the input elements.O
- Type of the output elements.@PublicEvolving public abstract class ProcessFunction<I,O> extends AbstractRichFunction
For every element in the input stream processElement(Object, Context, Collector)
is
invoked. This can produce zero or more elements as output. Implementations can also query the
time and set timers through the provided ProcessFunction.Context
. For firing timers onTimer(long,
OnTimerContext, Collector)
will be invoked. This can again produce zero or more elements as
output and register further timers.
NOTE: Access to keyed state and timers (which are also scoped to a key) is only
available if the ProcessFunction
is applied on a KeyedStream
.
NOTE: A ProcessFunction
is always a RichFunction
. Therefore, access to the RuntimeContext
is always available and setup and teardown
methods can be implemented. See RichFunction.open(OpenContext)
and RichFunction.close()
.
Modifier and Type | Class and Description |
---|---|
class |
ProcessFunction.Context
Information available in an invocation of
processElement(Object, Context, Collector)
or onTimer(long, OnTimerContext, Collector) . |
class |
ProcessFunction.OnTimerContext
Information available in an invocation of
onTimer(long, OnTimerContext, Collector) . |
Constructor and Description |
---|
ProcessFunction() |
Modifier and Type | Method and Description |
---|---|
void |
onTimer(long timestamp,
ProcessFunction.OnTimerContext ctx,
Collector<O> out)
Called when a timer set using
TimerService fires. |
abstract void |
processElement(I value,
ProcessFunction.Context ctx,
Collector<O> out)
Process one element from the input stream.
|
close, getIterationRuntimeContext, getRuntimeContext, open, setRuntimeContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
open
public abstract 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.public 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–2024 The Apache Software Foundation. All rights reserved.