public abstract class AbstractInvokable extends Object
The TaskManager invokes the invoke()
method when executing a
task. All operations of the task happen in this method (setting up input
output stream readers and writers as well as the task's core operation).
All classes that extend must offer a constructor MyTask(Environment, TaskStateSnapshot)
.
Tasks that are always stateless can, for convenience, also only implement the constructor
MyTask(Environment)
.
Developer note: While constructors cannot be enforced at compile time, we did not yet venture
on the endeavor of introducing factories (it is only an internal API after all, and with Java 8,
one can use Class::new
almost like a factory lambda.
NOTE: There is no constructor that accepts and initial task state snapshot and stores it in a variable. That is on purpose, because the AbstractInvokable itself does not need the state snapshot (only subclasses such as StreamTask do need the state) and we do not want to store a reference indefinitely, thus preventing cleanup of the initial state structure by the Garbage Collector.
Any subclass that supports recoverable state and participates in
checkpointing needs to override triggerCheckpoint(CheckpointMetaData, CheckpointOptions)
,
triggerCheckpointOnBarrier(CheckpointMetaData, CheckpointOptions, CheckpointMetrics)
,
abortCheckpointOnBarrier(long, Throwable)
and notifyCheckpointComplete(long)
.
Constructor and Description |
---|
AbstractInvokable(Environment environment)
Create an Invokable task and set its environment.
|
Modifier and Type | Method and Description |
---|---|
void |
abortCheckpointOnBarrier(long checkpointId,
Throwable cause)
Aborts a checkpoint as the result of receiving possibly some checkpoint barriers,
but at least one
CancelCheckpointMarker . |
void |
cancel()
This method is called when a task is canceled either as a result of a user abort or an execution failure.
|
int |
getCurrentNumberOfSubtasks()
Returns the current number of subtasks the respective task is split into.
|
Environment |
getEnvironment()
Returns the environment of this task.
|
ExecutionConfig |
getExecutionConfig()
Returns the global ExecutionConfig.
|
int |
getIndexInSubtaskGroup()
Returns the index of this subtask in the subtask group.
|
Configuration |
getJobConfiguration()
Returns the job configuration object which was attached to the original
JobGraph . |
Configuration |
getTaskConfiguration()
Returns the task configuration object which was attached to the original
JobVertex . |
ClassLoader |
getUserCodeClassLoader()
Returns the user code class loader of this invokable.
|
abstract void |
invoke()
Starts the execution.
|
void |
notifyCheckpointComplete(long checkpointId)
Invoked when a checkpoint has been completed, i.e., when the checkpoint coordinator has received
the notification from all participating tasks.
|
boolean |
triggerCheckpoint(CheckpointMetaData checkpointMetaData,
CheckpointOptions checkpointOptions)
This method is called to trigger a checkpoint, asynchronously by the checkpoint
coordinator.
|
void |
triggerCheckpointOnBarrier(CheckpointMetaData checkpointMetaData,
CheckpointOptions checkpointOptions,
CheckpointMetrics checkpointMetrics)
This method is called when a checkpoint is triggered as a result of receiving checkpoint
barriers on all input streams.
|
public AbstractInvokable(Environment environment)
environment
- The environment assigned to this invokable.public abstract void invoke() throws Exception
Must be overwritten by the concrete task implementation. This method is called by the task manager when the actual execution of the task starts.
All resources should be cleaned up when the method returns. Make sure
to guard the code with try-finally
blocks where necessary.
Exception
- Tasks may forward their exceptions for the TaskManager to handle through failure/recovery.public void cancel() throws Exception
Exception
- thrown if any exception occurs during the execution of the user codepublic Environment getEnvironment()
public ClassLoader getUserCodeClassLoader()
public int getCurrentNumberOfSubtasks()
public int getIndexInSubtaskGroup()
public Configuration getTaskConfiguration()
JobVertex
.JobVertex
public Configuration getJobConfiguration()
JobGraph
.JobGraph
public ExecutionConfig getExecutionConfig()
public boolean triggerCheckpoint(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions) throws Exception
This method is called for tasks that start the checkpoints by injecting the initial barriers,
i.e., the source tasks. In contrast, checkpoints on downstream operators, which are the result of
receiving checkpoint barriers, invoke the triggerCheckpointOnBarrier(CheckpointMetaData, CheckpointOptions, CheckpointMetrics)
method.
checkpointMetaData
- Meta data for about this checkpointcheckpointOptions
- Options for performing this checkpointfalse
if the checkpoint can not be carried out, true
otherwiseException
public void triggerCheckpointOnBarrier(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions, CheckpointMetrics checkpointMetrics) throws Exception
checkpointMetaData
- Meta data for about this checkpointcheckpointOptions
- Options for performing this checkpointcheckpointMetrics
- Metrics about this checkpointException
- Exceptions thrown as the result of triggering a checkpoint are forwarded.public void abortCheckpointOnBarrier(long checkpointId, Throwable cause) throws Exception
CancelCheckpointMarker
.
This requires implementing tasks to forward a
CancelCheckpointMarker
to their outputs.
checkpointId
- The ID of the checkpoint to be aborted.cause
- The reason why the checkpoint was aborted during alignmentException
public void notifyCheckpointComplete(long checkpointId) throws Exception
checkpointId
- The ID of the checkpoint that is complete..Exception
- The notification method may forward its exceptions.Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.