OUT
- OP
- @Internal public abstract class StreamTask<OUT,OP extends StreamOperator<OUT>> extends AbstractInvokable implements StatefulTask, AsyncExceptionHandler
StreamOperator
s which form
the Task's operator chain. Operators that are chained together execute synchronously in the
same thread and hence on the same stream partition. A common case for these chains
are successive map/flatmap/filter tasks.
The task chain contains one "head" operator and multiple chained operators. The StreamTask is specialized for the type of the head operator: one-input and two-input tasks, as well as for sources, iteration heads and iteration tails.
The Task class deals with the setup of the streams read by the head operator, and the streams produced by the operators at the ends of the operator chain. Note that the chain may fork and thus have multiple ends. The life cycle of the task is set up as follows:
-- setInitialState -> provides state of all operators in the chain
-- invoke()
|
+----> Create basic utils (config, etc) and load the chain of operators
+----> operators.setup()
+----> task specific init()
+----> initialize-operator-states()
+----> open-operators()
+----> run()
+----> close-operators()
+----> dispose-operators()
+----> common cleanup
+----> task specific cleanup()
The StreamTask
has a lock object called lock
. All calls to methods on a
StreamOperator
must be synchronized on this lock object to ensure that no methods
are called concurrently.
Modifier and Type | Field and Description |
---|---|
protected OP |
headOperator
the head operator that consumes the input streams of this task
|
static ThreadGroup |
TRIGGER_THREAD_GROUP
The thread group that holds all trigger timer threads
|
Constructor and Description |
---|
StreamTask() |
Modifier and Type | Method and Description |
---|---|
void |
abortCheckpointOnBarrier(long checkpointId,
Throwable cause) |
void |
cancel() |
protected abstract void |
cancelTask() |
protected abstract void |
cleanup() |
CheckpointStreamFactory |
createCheckpointStreamFactory(StreamOperator<?> operator)
This is only visible because
GenericWriteAheadSink uses the
checkpoint stream factory to write write-ahead logs. |
<K> AbstractKeyedStateBackend<K> |
createKeyedStateBackend(TypeSerializer<K> keySerializer,
int numberOfKeyGroups,
KeyGroupRange keyGroupRange) |
OperatorStateBackend |
createOperatorStateBackend(StreamOperator<?> op,
Collection<OperatorStateHandle> restoreStateHandles) |
protected void |
finalize()
The finalize method shuts down the timer.
|
Map<String,Accumulator<?,?>> |
getAccumulatorMap() |
ExecutorService |
getAsyncOperationsThreadPool() |
CloseableRegistry |
getCancelables() |
Object |
getCheckpointLock()
Gets the lock object on which all operations that involve data and state mutation have to lock.
|
StreamConfig |
getConfiguration() |
String |
getName()
Gets the name of the task, in the form "taskname (2/5)".
|
ProcessingTimeService |
getProcessingTimeService()
Returns the
ProcessingTimeService responsible for telling the current
processing time and registering timers. |
void |
handleAsyncException(String message,
Throwable exception)
Handles an exception thrown by another thread (e.g.
|
protected abstract void |
init() |
void |
invoke() |
boolean |
isCanceled() |
boolean |
isRunning() |
void |
notifyCheckpointComplete(long checkpointId) |
protected abstract void |
run() |
void |
setInitialState(TaskStateHandles taskStateHandles) |
void |
setProcessingTimeService(ProcessingTimeService timeProvider)
Allows the user to specify his own
TimerServiceProvider . |
String |
toString() |
boolean |
triggerCheckpoint(CheckpointMetaData checkpointMetaData) |
void |
triggerCheckpointOnBarrier(CheckpointMetaData checkpointMetaData) |
getCurrentNumberOfSubtasks, getEnvironment, getExecutionConfig, getIndexInSubtaskGroup, getJobConfiguration, getTaskConfiguration, getUserCodeClassLoader, setEnvironment
public static final ThreadGroup TRIGGER_THREAD_GROUP
protected OP extends StreamOperator<OUT> headOperator
public void setProcessingTimeService(ProcessingTimeService timeProvider)
TimerServiceProvider
.
By default a DefaultTimerService
is going to be provided.
Changing it can be useful for testing processing time functionality, such as
WindowAssigners
and Triggers
.public final void invoke() throws Exception
invoke
in class AbstractInvokable
Exception
public final void cancel() throws Exception
cancel
in class AbstractInvokable
Exception
public final boolean isRunning()
public final boolean isCanceled()
protected void finalize() throws Throwable
This should not be relied upon! It will cause shutdown to happen much later than if manual shutdown is attempted, and cause threads to linger for longer than needed.
public String getName()
public Object getCheckpointLock()
public StreamConfig getConfiguration()
public Map<String,Accumulator<?,?>> getAccumulatorMap()
public void setInitialState(TaskStateHandles taskStateHandles)
setInitialState
in interface StatefulTask
public boolean triggerCheckpoint(CheckpointMetaData checkpointMetaData) throws Exception
triggerCheckpoint
in interface StatefulTask
Exception
public void triggerCheckpointOnBarrier(CheckpointMetaData checkpointMetaData) throws Exception
triggerCheckpointOnBarrier
in interface StatefulTask
Exception
public void abortCheckpointOnBarrier(long checkpointId, Throwable cause) throws Exception
abortCheckpointOnBarrier
in interface StatefulTask
Exception
public ExecutorService getAsyncOperationsThreadPool()
public void notifyCheckpointComplete(long checkpointId) throws Exception
notifyCheckpointComplete
in interface StatefulTask
Exception
public OperatorStateBackend createOperatorStateBackend(StreamOperator<?> op, Collection<OperatorStateHandle> restoreStateHandles) throws Exception
Exception
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(TypeSerializer<K> keySerializer, int numberOfKeyGroups, KeyGroupRange keyGroupRange) throws Exception
Exception
public CheckpointStreamFactory createCheckpointStreamFactory(StreamOperator<?> operator) throws IOException
GenericWriteAheadSink
uses the
checkpoint stream factory to write write-ahead logs. This should not be used for
anything else.IOException
public ProcessingTimeService getProcessingTimeService()
ProcessingTimeService
responsible for telling the current
processing time and registering timers.public void handleAsyncException(String message, Throwable exception)
This method never blocks.
handleAsyncException
in interface AsyncExceptionHandler
public CloseableRegistry getCancelables()
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.