Class DeclaringAsyncKeyedCoProcessFunction<K,IN1,IN2,OUT>
- java.lang.Object
-
- org.apache.flink.api.common.functions.AbstractRichFunction
-
- org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction<K,IN1,IN2,OUT>
-
- org.apache.flink.runtime.asyncprocessing.functions.DeclaringAsyncKeyedCoProcessFunction<K,IN1,IN2,OUT>
-
- Type Parameters:
K
- Type of the key.IN1
- Type of the first input.IN2
- Type of the second input.OUT
- Output type.
- All Implemented Interfaces:
Serializable
,org.apache.flink.api.common.functions.Function
,org.apache.flink.api.common.functions.RichFunction
@Internal public abstract class DeclaringAsyncKeyedCoProcessFunction<K,IN1,IN2,OUT> extends KeyedCoProcessFunction<K,IN1,IN2,OUT>
A function that processes elements of two keyed streams and produces a single output stream.The function will be called for every element in the input streams and can produce zero or more output elements. Contrary to the
CoFlatMapFunction
, this function can also query the time (both event and processing) and set timers, through the providedKeyedCoProcessFunction.Context
. When reacting to the firing of timers the function can emit yet more elements.An example use case for connected streams is the application of a set of rules that change over time (
stream A
) to the elements contained in another stream (streamB
). The rules contained instream A
can be stored in the state and wait for new elements to arrive onstream B
. Upon reception of a new element onstream B
, the function can apply the previously stored rules to the element and emit a result, and/or register a timer that will trigger an action in the future.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction
KeyedCoProcessFunction.Context, KeyedCoProcessFunction.OnTimerContext
-
-
Constructor Summary
Constructors Constructor Description DeclaringAsyncKeyedCoProcessFunction()
-
Method Summary
-
-
-
Method Detail
-
processElement1
public final void processElement1(IN1 value, KeyedCoProcessFunction.Context ctx, org.apache.flink.util.Collector<OUT> out) throws Exception
Override and finalize this method. Please usedeclareProcess1(org.apache.flink.runtime.asyncprocessing.declare.DeclarationContext, org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction.Context, org.apache.flink.util.Collector<OUT>)
instead.- Specified by:
processElement1
in classKeyedCoProcessFunction<K,IN1,IN2,OUT>
- Parameters:
value
- The stream elementctx
- AKeyedCoProcessFunction.Context
that allows querying the timestamp of the element, querying theTimeDomain
of the firing timer and getting aTimerService
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 to emit resulting elements to- Throws:
Exception
- The function may throw exceptions which cause the streaming program to fail and go into recovery.
-
processElement2
public final void processElement2(IN2 value, KeyedCoProcessFunction.Context ctx, org.apache.flink.util.Collector<OUT> out) throws Exception
Override and finalize this method. Please usedeclareProcess2(org.apache.flink.runtime.asyncprocessing.declare.DeclarationContext, org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction.Context, org.apache.flink.util.Collector<OUT>)
instead.- Specified by:
processElement2
in classKeyedCoProcessFunction<K,IN1,IN2,OUT>
- Parameters:
value
- The stream elementctx
- AKeyedCoProcessFunction.Context
that allows querying the timestamp of the element, querying theTimeDomain
of the firing timer and getting aTimerService
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 to emit resulting elements to- Throws:
Exception
- The function may throw exceptions which cause the streaming program to fail and go into recovery.
-
onTimer
public final void onTimer(long timestamp, KeyedCoProcessFunction.OnTimerContext ctx, org.apache.flink.util.Collector<OUT> out) throws Exception
Override and finalize this method. Please usedeclareOnTimer(org.apache.flink.runtime.asyncprocessing.declare.DeclarationContext, org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction.OnTimerContext, org.apache.flink.util.Collector<OUT>)
instead.- Overrides:
onTimer
in classKeyedCoProcessFunction<K,IN1,IN2,OUT>
- Parameters:
timestamp
- The timestamp of the firing timer.ctx
- AnKeyedCoProcessFunction.OnTimerContext
that allows querying the timestamp of the firing timer, querying theTimeDomain
of the firing timer and getting aTimerService
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.- Throws:
Exception
- This method may throw exceptions. Throwing an exception will cause the operation to fail and may trigger recovery.
-
declareVariables
public void declareVariables(DeclarationContext context)
Declaring variables beforedeclareProcess1(org.apache.flink.runtime.asyncprocessing.declare.DeclarationContext, org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction.Context, org.apache.flink.util.Collector<OUT>)
anddeclareProcess2(org.apache.flink.runtime.asyncprocessing.declare.DeclarationContext, org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction.Context, org.apache.flink.util.Collector<OUT>)
anddeclareOnTimer(org.apache.flink.runtime.asyncprocessing.declare.DeclarationContext, org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction.OnTimerContext, org.apache.flink.util.Collector<OUT>)
.
-
declareProcess1
public abstract org.apache.flink.util.function.ThrowingConsumer<IN1,Exception> declareProcess1(DeclarationContext context, KeyedCoProcessFunction.Context ctx, org.apache.flink.util.Collector<OUT> out) throws DeclarationException
Declare a process for one element from the first of the connected streams.This function can output zero or more elements using the
Collector
parameter and also update internal state or set timers using theKeyedCoProcessFunction.Context
parameter.- Parameters:
context
- the context that provides useful methods to define named callbacks.ctx
- AKeyedCoProcessFunction.Context
that allows querying the timestamp of the element and getting aTimerService
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.- Returns:
- the whole processing logic just like
processElement
. - Throws:
DeclarationException
-
declareProcess2
public abstract org.apache.flink.util.function.ThrowingConsumer<IN2,Exception> declareProcess2(DeclarationContext context, KeyedCoProcessFunction.Context ctx, org.apache.flink.util.Collector<OUT> out) throws DeclarationException
Declare a process for one element from the second of the connected streams.This function can output zero or more elements using the
Collector
parameter and also update internal state or set timers using theKeyedCoProcessFunction.Context
parameter.- Parameters:
context
- the context that provides useful methods to define named callbacks.ctx
- AKeyedCoProcessFunction.Context
that allows querying the timestamp of the element and getting aTimerService
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.- Returns:
- the whole processing logic just like
processElement
. - Throws:
DeclarationException
-
declareOnTimer
public org.apache.flink.util.function.ThrowingConsumer<Long,Exception> declareOnTimer(DeclarationContext context, KeyedCoProcessFunction.OnTimerContext ctx, org.apache.flink.util.Collector<OUT> out) throws DeclarationException
Declare a procedure which is called when a timer set usingTimerService
fires.- Parameters:
context
- the context that provides useful methods to define named callbacks.ctx
- AnKeyedCoProcessFunction.OnTimerContext
that allows querying the timestamp, theTimeDomain
, and the key of the firing timer and getting aTimerService
for registering timers and querying the time. The context is only valid during the invocation of this method, do not store it.out
- The processor for processing timestamps.- Throws:
DeclarationException
-
-