Class KeyedProcessFunction<K,I,O>
- Type Parameters:
K- Type of the key.I- Type of the input elements.O- Type of the output elements.
- All Implemented Interfaces:
Serializable,org.apache.flink.api.common.functions.Function,org.apache.flink.api.common.functions.RichFunction
- Direct Known Subclasses:
DeclaringAsyncKeyedProcessFunction
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 KeyedProcessFunction<K,. 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 KeyedProcessFunction is applied on a KeyedStream.
NOTE: A KeyedProcessFunction 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().
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassInformation available in an invocation of#processElement(Object, Context, Collector)or#onTimer(long, OnTimerContext, Collector).classInformation available in an invocation of#onTimer(long, OnTimerContext, Collector). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonTimer(long timestamp, KeyedProcessFunction<K, I, O>.OnTimerContext ctx, org.apache.flink.util.Collector<O> out) Called when a timer set usingTimerServicefires.abstract voidprocessElement(I value, KeyedProcessFunction<K, I, O>.Context ctx, org.apache.flink.util.Collector<O> out) Process one element from the input stream.Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
close, getIterationRuntimeContext, getRuntimeContext, open, setRuntimeContext
-
Constructor Details
-
KeyedProcessFunction
public KeyedProcessFunction()
-
-
Method Details
-
processElement
public abstract void processElement(I value, KeyedProcessFunction<K, I, throws ExceptionO>.Context ctx, org.apache.flink.util.Collector<O> out) Process one element from the input stream.This function can output zero or more elements using the
Collectorparameter and also update internal state or set timers using theKeyedProcessFunction<K,parameter.I, O>.Context - Parameters:
value- The input value.ctx- AKeyedProcessFunction<K,that allows querying the timestamp of the element and getting aI, O>.Context TimerServicefor 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.- Throws:
Exception- This method may throw exceptions. Throwing an exception will cause the operation to fail and may trigger recovery.
-
onTimer
public void onTimer(long timestamp, KeyedProcessFunction<K, I, throws ExceptionO>.OnTimerContext ctx, org.apache.flink.util.Collector<O> out) Called when a timer set usingTimerServicefires.- Parameters:
timestamp- The timestamp of the firing timer.ctx- AnKeyedProcessFunction<K,that allows querying the timestamp, theI, O>.OnTimerContext TimeDomain, and the key of the firing timer and getting aTimerServicefor 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.- Throws:
Exception- This method may throw exceptions. Throwing an exception will cause the operation to fail and may trigger recovery.
-