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 TaskInvokableAn 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 toinvoke(). 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::newalmost like a factory lambda.- See Also:
CheckpointableTask,CoordinatedTask,AbstractInvokable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancel()This method is called when a task is canceled either as a result of a user abort or an execution failure.voidcleanUp(Throwable throwable)voidinvoke()Starts the execution.booleanisUsingNonBlockingInput()voidmaybeInterruptOnCancel(Thread toInterrupt, String taskName, Long timeout)Checks whether the task should be interrupted during cancellation and if so, execute the specifiedRunnable interruptAction.voidrestore()This method can be called beforeinvoke()to restore an invokable object for the last valid state, if it has it.
-
-
-
Method Detail
-
invoke
void invoke() throws ExceptionStarts 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 ExceptionThis method can be called beforeinvoke()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 callingcleanUp(Throwable)()} after the method returns.- Throws:
Exception
-
cleanUp
void cleanUp(@Nullable Throwable throwable) throws ExceptionCleanup any resources used ininvoke()ORrestore(). This method must be called regardless whether the aforementioned calls succeeded or failed.- Parameters:
throwable- iff failure happened during the execution ofrestore()orinvoke(), null otherwise.ATTENTION:
CancelTaskExceptionshould not be treated as a failure.- Throws:
Exception
-
cancel
void cancel() throws ExceptionThis 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 toInputGate.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 specifiedRunnable interruptAction.- Parameters:
toInterrupt-taskName- optional taskName to log stack tracetimeout- optional timeout to log stack trace
-
-