Class AbstractAsyncStateStreamOperator<OUT>
- java.lang.Object
-
- org.apache.flink.streaming.api.operators.AbstractStreamOperator<OUT>
-
- org.apache.flink.streaming.runtime.operators.asyncprocessing.AbstractAsyncStateStreamOperator<OUT>
-
- All Implemented Interfaces:
Serializable,org.apache.flink.api.common.state.CheckpointListener,KeyContext,KeyContextHandler,SetupableStreamOperator<OUT>,StreamOperator<OUT>,StreamOperatorStateHandler.CheckpointedStreamOperator,YieldingOperator<OUT>,AsyncStateProcessing,AsyncStateProcessingOperator
- Direct Known Subclasses:
AbstractAsyncStateUdfStreamOperator
@Internal public abstract class AbstractAsyncStateStreamOperator<OUT> extends AbstractStreamOperator<OUT> implements AsyncStateProcessingOperator
This operator is an abstract class that give theAbstractStreamOperatorthe ability to performAsyncStateProcessing. The aim is to make any subclass ofAbstractStreamOperatorcould manipulate async state with only a change of base class.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.flink.streaming.api.operators.AbstractStreamOperator
chainingStrategy, config, lastRecordAttributes1, lastRecordAttributes2, latencyStats, LOG, metrics, output, processingTimeService, stateHandler, stateKeySelector1, stateKeySelector2, timeServiceManager
-
-
Constructor Summary
Constructors Constructor Description AbstractAsyncStateStreamOperator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectgetCurrentKey()ElementOrdergetElementOrder()Get theElementOrderof this operator.<K,N>
InternalTimerService<N>getInternalTimerService(String name, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, Triggerable<K,N> triggerable)Returns aInternalTimerServicethat can be used to query current processing time and event time and to set timers.<T> org.apache.flink.util.function.ThrowingConsumer<StreamRecord<T>,Exception>getRecordProcessor(int inputId)Get the record processor that could process record from input, which is the only entry for async processing.voidinitializeState(StreamTaskStateInitializer streamTaskStateManager)Initialize necessary state components forAbstractStreamOperator.booleanisAsyncStateProcessingEnabled()Get if the async state processing is enabled for this input/operator.voidpostProcessElement()A callback that will be triggered after an element finishesprocessElement.voidpreserveRecordOrderAndProcess(org.apache.flink.util.function.ThrowingRunnable<Exception> processing)Check the order of same-key record, and then process the record.voidprocessWatermark(Watermark mark)voidprocessWatermarkStatus(WatermarkStatus watermarkStatus)<T> voidsetAsyncKeyedContextElement(StreamRecord<T> record, org.apache.flink.api.java.functions.KeySelector<T,?> keySelector)Set key context for async state processing.voidsetKeyContextElement1(StreamRecord record)voidsetKeyContextElement2(StreamRecord record)OperatorSnapshotFuturessnapshotState(long checkpointId, long timestamp, org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions, org.apache.flink.runtime.state.CheckpointStreamFactory factory)Called to draw a state snapshot from the operator.-
Methods inherited from class org.apache.flink.streaming.api.operators.AbstractStreamOperator
close, finish, getChainingStrategy, getContainingTask, getExecutionConfig, getKeyedStateBackend, getKeyedStateStore, getMetricGroup, getOperatorConfig, getOperatorID, getOperatorName, getOperatorStateBackend, getOrCreateKeyedState, getPartitionedState, getPartitionedState, getProcessingTimeService, getRuntimeContext, getStateKeySelector1, getStateKeySelector2, getTimeServiceManager, getUserCodeClassloader, hasKeyContext1, hasKeyContext2, initializeState, isUsingCustomRawKeyedState, notifyCheckpointAborted, notifyCheckpointComplete, open, prepareSnapshotPreBarrier, processLatencyMarker, processLatencyMarker1, processLatencyMarker2, processRecordAttributes, processRecordAttributes1, processRecordAttributes2, processWatermark1, processWatermark2, processWatermarkStatus1, processWatermarkStatus2, reportOrForwardLatencyMarker, setChainingStrategy, setCurrentKey, setMailboxExecutor, setProcessingTimeService, setup, snapshotState, 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
-
-
-
-
Method Detail
-
initializeState
public void initializeState(StreamTaskStateInitializer streamTaskStateManager) throws Exception
Initialize necessary state components forAbstractStreamOperator.- Specified by:
initializeStatein interfaceStreamOperator<OUT>- Overrides:
initializeStatein classAbstractStreamOperator<OUT>- Throws:
Exception
-
isAsyncStateProcessingEnabled
public boolean isAsyncStateProcessingEnabled()
Description copied from interface:AsyncStateProcessingGet if the async state processing is enabled for this input/operator.- Specified by:
isAsyncStateProcessingEnabledin interfaceAsyncStateProcessing- Returns:
- ture if async state processing is enabled.
-
getElementOrder
public ElementOrder getElementOrder()
Description copied from interface:AsyncStateProcessingOperatorGet theElementOrderof this operator.- Specified by:
getElementOrderin interfaceAsyncStateProcessingOperator
-
setAsyncKeyedContextElement
public final <T> void setAsyncKeyedContextElement(StreamRecord<T> record, org.apache.flink.api.java.functions.KeySelector<T,?> keySelector) throws Exception
Description copied from interface:AsyncStateProcessingOperatorSet key context for async state processing.- Specified by:
setAsyncKeyedContextElementin interfaceAsyncStateProcessingOperator- Type Parameters:
T- the type of the record.- Parameters:
record- the record.keySelector- the key selector to select a key from record.- Throws:
Exception
-
postProcessElement
public final void postProcessElement()
Description copied from interface:AsyncStateProcessingOperatorA callback that will be triggered after an element finishesprocessElement.- Specified by:
postProcessElementin interfaceAsyncStateProcessingOperator
-
preserveRecordOrderAndProcess
public final void preserveRecordOrderAndProcess(org.apache.flink.util.function.ThrowingRunnable<Exception> processing)
Description copied from interface:AsyncStateProcessingOperatorCheck the order of same-key record, and then process the record. Mainly used when theAsyncStateProcessingOperator.getElementOrder()returnsElementOrder.RECORD_ORDER.- Specified by:
preserveRecordOrderAndProcessin interfaceAsyncStateProcessingOperator- Parameters:
processing- the record processing logic.
-
getRecordProcessor
public final <T> org.apache.flink.util.function.ThrowingConsumer<StreamRecord<T>,Exception> getRecordProcessor(int inputId)
Description copied from interface:AsyncStateProcessingGet the record processor that could process record from input, which is the only entry for async processing.- Specified by:
getRecordProcessorin interfaceAsyncStateProcessing- Parameters:
inputId- the input identifier, start from 1. Borrow the design fromorg.apache.flink.streaming.api.operators.AbstractInput#inputId. This is only relevant if there is multiple inputs for the instance.
-
snapshotState
public final OperatorSnapshotFutures snapshotState(long checkpointId, long timestamp, org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions, org.apache.flink.runtime.state.CheckpointStreamFactory factory) throws Exception
Description copied from interface:StreamOperatorCalled to draw a state snapshot from the operator.- Specified by:
snapshotStatein interfaceStreamOperator<OUT>- Overrides:
snapshotStatein classAbstractStreamOperator<OUT>- Returns:
- a runnable future to the state handle that points to the snapshotted state. For synchronous implementations, the runnable might already be finished.
- Throws:
Exception- exception that happened during snapshotting.
-
getInternalTimerService
public <K,N> InternalTimerService<N> getInternalTimerService(String name, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, Triggerable<K,N> triggerable)
Returns aInternalTimerServicethat can be used to query current processing time and event time and to set timers. An operator can have several timer services, where each has its own namespace serializer. Timer services are differentiated by the string key that is given when requesting them, if you call this method with the same key multiple times you will get the same timer service instance in subsequent requests.Timers are always scoped to a key, the currently active key of a keyed stream operation. When a timer fires, this key will also be set as the currently active key.
Each timer has attached metadata, the namespace. Different timer services can have a different namespace type. If you don't need namespace differentiation you can use
VoidNamespaceSerializeras the namespace serializer.- Overrides:
getInternalTimerServicein classAbstractStreamOperator<OUT>- Type Parameters:
N- The type of the timer namespace.- Parameters:
name- The name of the requested timer service. If no service exists under the given name a new one will be created and returned.namespaceSerializer-TypeSerializerfor the timer namespace.triggerable- TheTriggerablethat should be invoked when timers fire
-
setKeyContextElement1
public void setKeyContextElement1(StreamRecord record) throws Exception
- Specified by:
setKeyContextElement1in interfaceStreamOperator<OUT>- Overrides:
setKeyContextElement1in classAbstractStreamOperator<OUT>- Throws:
Exception
-
setKeyContextElement2
public void setKeyContextElement2(StreamRecord record) throws Exception
- Specified by:
setKeyContextElement2in interfaceStreamOperator<OUT>- Overrides:
setKeyContextElement2in classAbstractStreamOperator<OUT>- Throws:
Exception
-
getCurrentKey
public Object getCurrentKey()
- Specified by:
getCurrentKeyin interfaceKeyContext- Overrides:
getCurrentKeyin classAbstractStreamOperator<OUT>
-
processWatermark
public void processWatermark(Watermark mark) throws Exception
- Overrides:
processWatermarkin classAbstractStreamOperator<OUT>- Throws:
Exception
-
processWatermarkStatus
public void processWatermarkStatus(WatermarkStatus watermarkStatus) throws Exception
- Overrides:
processWatermarkStatusin classAbstractStreamOperator<OUT>- Throws:
Exception
-
-