Class AbstractInvokable

java.lang.Object
org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable
All Implemented Interfaces:
CheckpointableTask, CoordinatedTask, TaskInvokable
Direct Known Subclasses:
BatchTask, DataSinkTask, DataSourceTask, IterationSynchronizationSinkTask

public abstract class AbstractInvokable extends Object implements TaskInvokable, CheckpointableTask, CoordinatedTask
  • Constructor Details

    • AbstractInvokable

      public AbstractInvokable(Environment environment)
      Create an Invokable task and set its environment.
      Parameters:
      environment - The environment assigned to this invokable.
  • Method Details

    • invoke

      public abstract void invoke() throws Exception
      Description copied from interface: TaskInvokable
      Starts the execution.

      This method is called by the task manager when the actual execution of the task starts.

      All resources should be cleaned up by calling TaskInvokable.cleanUp(Throwable) after the method returns.

      Specified by:
      invoke in interface TaskInvokable
      Throws:
      Exception
    • cancel

      public void cancel() throws Exception
      Description copied from interface: TaskInvokable
      This method is called when a task is canceled either as a result of a user abort or an execution failure. It can be overwritten to respond to shut down the user code properly.
      Specified by:
      cancel in interface TaskInvokable
      Throws:
      Exception
    • cleanUp

      public void cleanUp(@Nullable Throwable throwable) throws Exception
      Description copied from interface: TaskInvokable
      Cleanup any resources used in TaskInvokable.invoke() OR TaskInvokable.restore(). This method must be called regardless whether the aforementioned calls succeeded or failed.
      Specified by:
      cleanUp in interface TaskInvokable
      Parameters:
      throwable - iff failure happened during the execution of TaskInvokable.restore() or TaskInvokable.invoke(), null otherwise.

      ATTENTION: CancelTaskException should not be treated as a failure.

      Throws:
      Exception
    • maybeInterruptOnCancel

      public void maybeInterruptOnCancel(Thread toInterrupt, @Nullable String taskName, @Nullable Long timeout)
      Description copied from interface: TaskInvokable
      Checks whether the task should be interrupted during cancellation and if so, execute the specified Runnable interruptAction.
      Specified by:
      maybeInterruptOnCancel in interface TaskInvokable
      taskName - optional taskName to log stack trace
      timeout - optional timeout to log stack trace
    • getEnvironment

      public final Environment getEnvironment()
      Returns the environment of this task.
      Returns:
      The environment of this task.
    • getUserCodeClassLoader

      public final ClassLoader getUserCodeClassLoader()
      Returns the user code class loader of this invokable.
      Returns:
      user code class loader of this invokable.
    • getCurrentNumberOfSubtasks

      public int getCurrentNumberOfSubtasks()
      Returns the current number of subtasks the respective task is split into.
      Returns:
      the current number of subtasks the respective task is split into
    • getIndexInSubtaskGroup

      public int getIndexInSubtaskGroup()
      Returns the index of this subtask in the subtask group.
      Returns:
      the index of this subtask in the subtask group
    • getTaskConfiguration

      public final org.apache.flink.configuration.Configuration getTaskConfiguration()
      Returns the task configuration object which was attached to the original JobVertex.
      Returns:
      the task configuration object which was attached to the original JobVertex
    • getJobConfiguration

      public org.apache.flink.configuration.Configuration getJobConfiguration()
      Returns the job configuration object which was attached to the original JobGraph.
      Returns:
      the job configuration object which was attached to the original JobGraph
    • getExecutionConfig

      public org.apache.flink.api.common.ExecutionConfig getExecutionConfig()
      Returns the global ExecutionConfig.
    • triggerCheckpointAsync

      public CompletableFuture<Boolean> triggerCheckpointAsync(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions)
      Description copied from interface: CheckpointableTask
      This method is called to trigger a checkpoint, asynchronously by the checkpoint coordinator.

      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 CheckpointableTask.triggerCheckpointOnBarrier(CheckpointMetaData, CheckpointOptions, CheckpointMetricsBuilder) method.

      Specified by:
      triggerCheckpointAsync in interface CheckpointableTask
      Parameters:
      checkpointMetaData - Meta data for about this checkpoint
      checkpointOptions - Options for performing this checkpoint
      Returns:
      future with value of false if the checkpoint was not carried out, true otherwise
    • triggerCheckpointOnBarrier

      public void triggerCheckpointOnBarrier(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions, CheckpointMetricsBuilder checkpointMetrics) throws IOException
      Description copied from interface: CheckpointableTask
      This method is called when a checkpoint is triggered as a result of receiving checkpoint barriers on all input streams.
      Specified by:
      triggerCheckpointOnBarrier in interface CheckpointableTask
      Parameters:
      checkpointMetaData - Meta data for about this checkpoint
      checkpointOptions - Options for performing this checkpoint
      checkpointMetrics - Metrics about this checkpoint
      Throws:
      IOException - Exceptions thrown as the result of triggering a checkpoint are forwarded.
    • abortCheckpointOnBarrier

      public void abortCheckpointOnBarrier(long checkpointId, CheckpointException cause) throws IOException
      Description copied from interface: CheckpointableTask
      Aborts a checkpoint as the result of receiving possibly some checkpoint barriers, but at least one CancelCheckpointMarker.

      This requires implementing tasks to forward a CancelCheckpointMarker to their outputs.

      Specified by:
      abortCheckpointOnBarrier in interface CheckpointableTask
      Parameters:
      checkpointId - The ID of the checkpoint to be aborted.
      cause - The reason why the checkpoint was aborted during alignment
      Throws:
      IOException
    • notifyCheckpointCompleteAsync

      public Future<Void> notifyCheckpointCompleteAsync(long checkpointId)
      Description copied from interface: CheckpointableTask
      Invoked when a checkpoint has been completed, i.e., when the checkpoint coordinator has received the notification from all participating tasks.
      Specified by:
      notifyCheckpointCompleteAsync in interface CheckpointableTask
      Parameters:
      checkpointId - The ID of the checkpoint that is complete.
      Returns:
      future that completes when the notification has been processed by the task.
    • notifyCheckpointAbortAsync

      public Future<Void> notifyCheckpointAbortAsync(long checkpointId, long latestCompletedCheckpointId)
      Description copied from interface: CheckpointableTask
      Invoked when a checkpoint has been aborted, i.e., when the checkpoint coordinator has received a decline message from one task and try to abort the targeted checkpoint by notification.
      Specified by:
      notifyCheckpointAbortAsync in interface CheckpointableTask
      Parameters:
      checkpointId - The ID of the checkpoint that is aborted.
      latestCompletedCheckpointId - The ID of the latest completed checkpoint.
      Returns:
      future that completes when the notification has been processed by the task.
    • notifyCheckpointSubsumedAsync

      public Future<Void> notifyCheckpointSubsumedAsync(long checkpointId)
      Description copied from interface: CheckpointableTask
      Invoked when a checkpoint has been subsumed, i.e., when the checkpoint coordinator has confirmed one checkpoint has been finished, and try to remove the first previous checkpoint.
      Specified by:
      notifyCheckpointSubsumedAsync in interface CheckpointableTask
      Parameters:
      checkpointId - The ID of the checkpoint that is subsumed.
      Returns:
      future that completes when the notification has been processed by the task.
    • dispatchOperatorEvent

      public void dispatchOperatorEvent(OperatorID operator, org.apache.flink.util.SerializedValue<OperatorEvent> event) throws org.apache.flink.util.FlinkException
      Specified by:
      dispatchOperatorEvent in interface CoordinatedTask
      Throws:
      org.apache.flink.util.FlinkException
    • restore

      public void restore() throws Exception
      Description copied from interface: TaskInvokable
      This method can be called before TaskInvokable.invoke() to restore an invokable object for the last valid state, if it has it.

      If TaskInvokable.invoke() is not called after this method for some reason (e.g. task cancellation); then all resources should be cleaned up by calling TaskInvokable.cleanUp(Throwable) ()} after the method returns.

      Specified by:
      restore in interface TaskInvokable
      Throws:
      Exception
    • isUsingNonBlockingInput

      public boolean isUsingNonBlockingInput()
      Specified by:
      isUsingNonBlockingInput in interface TaskInvokable
      Returns:
      true if blocking input such as InputGate.getNext() is used (as opposed to InputGate.pollNext(). To be removed together with the DataSet API.