Interface TaskInvokable

All Known Implementing Classes:
AbstractInvokable, AbstractIterativeTask, AbstractTwoInputStreamTask, BatchTask, DataSinkTask, DataSourceTask, IterationHeadTask, IterationIntermediateTask, IterationSynchronizationSinkTask, IterationTailTask, MultipleInputStreamTask, OneInputStreamTask, SourceOperatorStreamTask, SourceStreamTask, StreamIterationHead, StreamIterationTail, StreamTask, TwoInputStreamTask

@Internal public interface TaskInvokable
An invokable part of the task.

The TaskManager first calls the restore() method when executing a task. If the call succeeds and the task isn't cancelled then TM proceeds to invoke(). All operations of the task happen in these two methods (setting up input output stream readers and writers as well as the task's core operation).

After that, cleanUp(Throwable) is called (regardless of an failures or cancellations during the above calls).

Implementations must have a constructor with a single argument of type 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.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method is called when a task is canceled either as a result of a user abort or an execution failure.
    void
    cleanUp(Throwable throwable)
    Cleanup any resources used in invoke() OR restore().
    void
    Starts the execution.
    boolean
     
    void
    maybeInterruptOnCancel(Thread toInterrupt, String taskName, Long timeout)
    Checks whether the task should be interrupted during cancellation and if so, execute the specified Runnable interruptAction.
    void
    This method can be called before invoke() to restore an invokable object for the last valid state, if it has it.
  • Method Details

    • invoke

      void invoke() throws Exception
      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 cleanUp(Throwable) after the method returns.

      Throws:
      Exception
    • restore

      void restore() throws Exception
      This method can be called before invoke() to restore an invokable object for the last valid state, if it has it.

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

      Throws:
      Exception
    • cleanUp

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

      ATTENTION: CancelTaskException should not be treated as a failure.

      Throws:
      Exception
    • cancel

      void cancel() throws Exception
      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.
      Throws:
      Exception
    • isUsingNonBlockingInput

      boolean isUsingNonBlockingInput()
      Returns:
      true if blocking input such as InputGate.getNext() is used (as opposed to InputGate.pollNext(). To be removed together with the DataSet API.
    • maybeInterruptOnCancel

      void maybeInterruptOnCancel(Thread toInterrupt, @Nullable String taskName, @Nullable Long timeout)
      Checks whether the task should be interrupted during cancellation and if so, execute the specified Runnable interruptAction.
      Parameters:
      toInterrupt -
      taskName - optional taskName to log stack trace
      timeout - optional timeout to log stack trace