Class AbstractAsyncStateUdfStreamOperator<OUT,F extends Function>
- java.lang.Object
-
- org.apache.flink.streaming.api.operators.AbstractStreamOperator<OUT>
-
- org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateStreamOperator<OUT>
-
- org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateUdfStreamOperator<OUT,F>
-
- Type Parameters:
OUT
- The output type of the operatorF
- The type of the user function
- All Implemented Interfaces:
Serializable
,CheckpointListener
,KeyContext
,KeyContextHandler
,OutputTypeConfigurable<OUT>
,StreamOperator<OUT>
,StreamOperatorStateHandler.CheckpointedStreamOperator
,UserFunctionProvider<F>
,YieldingOperator<OUT>
,AsyncStateProcessing
,AsyncStateProcessingOperator
@Internal public abstract class AbstractAsyncStateUdfStreamOperator<OUT,F extends Function> extends AbstractAsyncStateStreamOperator<OUT> implements OutputTypeConfigurable<OUT>, UserFunctionProvider<F>
This is used as the base class for operators that have a user-defined function. This class handles the opening and closing of the user-defined functions, as part of the operator life cycle. This class is nearly identical withAbstractUdfStreamOperator
, but extending fromAbstractAsyncStateStreamOperator
to integrate with asynchronous state access. Another difference is this class is internal.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected F
userFunction
The user function.-
Fields inherited from class org.apache.flink.streaming.api.operators.AbstractStreamOperator
config, lastRecordAttributes1, lastRecordAttributes2, latencyStats, metrics, output, processingTimeService, stateHandler, stateKeySelector1, stateKeySelector2, timeServiceManager
-
-
Constructor Summary
Constructors Constructor Description AbstractAsyncStateUdfStreamOperator(F userFunction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
This method is called at the very end of the operator's life, both in the case of a successful completion of the operation, and in the case of a failure and canceling.void
finish()
This method is called at the end of data processing.F
getUserFunction()
Gets the user function executed in this operator.void
initializeState(StateInitializationContext context)
Stream operators with state which can be restored need to override this hook method.void
notifyCheckpointAborted(long checkpointId)
This method is called as a notification once a distributed checkpoint has been aborted.void
notifyCheckpointComplete(long checkpointId)
Notifies the listener that the checkpoint with the givencheckpointId
completed and was committed.void
open()
This method is called immediately before any elements are processed, it should contain the operator's initialization logic, e.g. state initialization.void
setOutputType(TypeInformation<OUT> outTypeInfo, ExecutionConfig executionConfig)
Is called by theorg.apache.flink.streaming.api.graph.StreamGraph#addOperator(Integer, String, StreamOperator, TypeInformation, TypeInformation, String)
method when theorg.apache.flink.streaming.api.graph.StreamGraph
is generated.protected void
setup(StreamTask<?,?> containingTask, StreamConfig config, Output<StreamRecord<OUT>> output)
void
snapshotState(StateSnapshotContext context)
Stream operators with state, which want to participate in a snapshot need to override this hook method.-
Methods inherited from class org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateStreamOperator
asyncProcessWithKey, getCurrentKey, getElementOrder, getInternalTimerService, getOrCreateKeyedState, getRecordProcessor, initializeState, isAsyncStateProcessingEnabled, postProcessElement, prepareSnapshotPreBarrier, preserveRecordOrderAndProcess, processWatermark, processWatermarkStatus, setAsyncKeyedContextElement, setKeyContextElement1, setKeyContextElement2, snapshotState
-
Methods inherited from class org.apache.flink.streaming.api.operators.AbstractStreamOperator
getContainingTask, getExecutionConfig, getKeyedStateBackend, getKeyedStateStore, getMetricGroup, getOperatorConfig, getOperatorID, getOperatorName, getOperatorStateBackend, getOrCreateKeyedState, getPartitionedState, getPartitionedState, getProcessingTimeService, getRuntimeContext, getStateKeySelector1, getStateKeySelector2, getTimeServiceManager, getUserCodeClassloader, hasKeyContext1, hasKeyContext2, isUsingCustomRawKeyedState, processLatencyMarker, processLatencyMarker1, processLatencyMarker2, processRecordAttributes, processRecordAttributes1, processRecordAttributes2, processWatermark1, processWatermark2, processWatermarkStatus1, processWatermarkStatus2, reportOrForwardLatencyMarker, setCurrentKey, setMailboxExecutor, setProcessingTimeService, useSplittableTimers
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.streaming.api.operators.KeyContextHandler
hasKeyContext
-
Methods inherited from interface org.apache.flink.streaming.api.operators.StreamOperator
getOperatorAttributes
-
-
-
-
Constructor Detail
-
AbstractAsyncStateUdfStreamOperator
public AbstractAsyncStateUdfStreamOperator(F userFunction)
-
-
Method Detail
-
getUserFunction
public F getUserFunction()
Gets the user function executed in this operator.- Specified by:
getUserFunction
in interfaceUserFunctionProvider<OUT>
- Returns:
- The user function of this operator.
-
setup
protected void setup(StreamTask<?,?> containingTask, StreamConfig config, Output<StreamRecord<OUT>> output)
- Overrides:
setup
in classAbstractStreamOperator<OUT>
-
snapshotState
public void snapshotState(StateSnapshotContext context) throws Exception
Description copied from class:AbstractStreamOperator
Stream operators with state, which want to participate in a snapshot need to override this hook method.- Specified by:
snapshotState
in interfaceStreamOperatorStateHandler.CheckpointedStreamOperator
- Overrides:
snapshotState
in classAbstractStreamOperator<OUT>
- Parameters:
context
- context that provides information and means required for taking a snapshot- Throws:
Exception
-
initializeState
public void initializeState(StateInitializationContext context) throws Exception
Description copied from class:AbstractStreamOperator
Stream operators with state which can be restored need to override this hook method.- Specified by:
initializeState
in interfaceStreamOperatorStateHandler.CheckpointedStreamOperator
- Overrides:
initializeState
in classAbstractStreamOperator<OUT>
- Parameters:
context
- context that allows to register different states.- Throws:
Exception
-
open
public void open() throws Exception
Description copied from class:AbstractStreamOperator
This method is called immediately before any elements are processed, it should contain the operator's initialization logic, e.g. state initialization.The default implementation does nothing.
- Specified by:
open
in interfaceStreamOperator<OUT>
- Overrides:
open
in classAbstractStreamOperator<OUT>
- Throws:
Exception
- An exception in this method causes the operator to fail.
-
finish
public void finish() throws Exception
Description copied from interface:StreamOperator
This method is called at the end of data processing.The method is expected to flush all remaining buffered data. Exceptions during this flushing of buffered data should be propagated, in order to cause the operation to be recognized as failed, because the last data items are not processed properly.
After this method is called, no more records can be produced for the downstream operators.
WARNING: It is not safe to use this method to commit any transactions or other side effects! You can use this method to flush any buffered data that can later on be committed e.g. in a
CheckpointListener.notifyCheckpointComplete(long)
.NOTE:This method does not need to close any resources. You should release external resources in the
StreamOperator.close()
method.- Specified by:
finish
in interfaceStreamOperator<OUT>
- Overrides:
finish
in classAbstractAsyncStateStreamOperator<OUT>
- Throws:
Exception
- An exception in this method causes the operator to fail.
-
close
public void close() throws Exception
Description copied from interface:StreamOperator
This method is called at the very end of the operator's life, both in the case of a successful completion of the operation, and in the case of a failure and canceling.This method is expected to make a thorough effort to release all resources that the operator has acquired.
NOTE:It can not emit any records! If you need to emit records at the end of processing, do so in the
StreamOperator.finish()
method.- Specified by:
close
in interfaceStreamOperator<OUT>
- Overrides:
close
in classAbstractAsyncStateStreamOperator<OUT>
- Throws:
Exception
-
notifyCheckpointComplete
public void notifyCheckpointComplete(long checkpointId) throws Exception
Description copied from interface:CheckpointListener
Notifies the listener that the checkpoint with the givencheckpointId
completed and was committed.These notifications are "best effort", meaning they can sometimes be skipped. To behave properly, implementers need to follow the "Checkpoint Subsuming Contract". Please see the
class-level JavaDocs
for details.Please note that checkpoints may generally overlap, so you cannot assume that the
notifyCheckpointComplete()
call is always for the latest prior checkpoint (or snapshot) that was taken on the function/operator implementing this interface. It might be for a checkpoint that was triggered earlier. Implementing the "Checkpoint Subsuming Contract" (see above) properly handles this situation correctly as well.Please note that throwing exceptions from this method will not cause the completed checkpoint to be revoked. Throwing exceptions will typically cause task/job failure and trigger recovery.
- Specified by:
notifyCheckpointComplete
in interfaceCheckpointListener
- Overrides:
notifyCheckpointComplete
in classAbstractStreamOperator<OUT>
- Parameters:
checkpointId
- The ID of the checkpoint that has been completed.- Throws:
Exception
- This method can propagate exceptions, which leads to a failure/recovery for the task. Note that this will NOT lead to the checkpoint being revoked.
-
notifyCheckpointAborted
public void notifyCheckpointAborted(long checkpointId) throws Exception
Description copied from interface:CheckpointListener
This method is called as a notification once a distributed checkpoint has been aborted.Important: The fact that a checkpoint has been aborted does NOT mean that the data and artifacts produced between the previous checkpoint and the aborted checkpoint are to be discarded. The expected behavior is as if this checkpoint was never triggered in the first place, and the next successful checkpoint simply covers a longer time span. See the "Checkpoint Subsuming Contract" in the
class-level JavaDocs
for details.These notifications are "best effort", meaning they can sometimes be skipped.
This method is very rarely necessary to implement. The "best effort" guarantee, together with the fact that this method should not result in discarding any data (per the "Checkpoint Subsuming Contract") means it is mainly useful for earlier cleanups of auxiliary resources. One example is to pro-actively clear a local per-checkpoint state cache upon checkpoint failure.
- Specified by:
notifyCheckpointAborted
in interfaceCheckpointListener
- Overrides:
notifyCheckpointAborted
in classAbstractStreamOperator<OUT>
- Parameters:
checkpointId
- The ID of the checkpoint that has been aborted.- Throws:
Exception
- This method can propagate exceptions, which leads to a failure/recovery for the task or job.
-
setOutputType
public void setOutputType(TypeInformation<OUT> outTypeInfo, ExecutionConfig executionConfig)
Description copied from interface:OutputTypeConfigurable
Is called by theorg.apache.flink.streaming.api.graph.StreamGraph#addOperator(Integer, String, StreamOperator, TypeInformation, TypeInformation, String)
method when theorg.apache.flink.streaming.api.graph.StreamGraph
is generated. The method is called with the outputTypeInformation
which is also used for theorg.apache.flink.streaming.runtime.tasks.StreamTask
output serializer.- Specified by:
setOutputType
in interfaceOutputTypeConfigurable<OUT>
- Parameters:
outTypeInfo
- Output type information of theorg.apache.flink.streaming.runtime.tasks.StreamTask
executionConfig
- Execution configuration
-
-