Interface TaskInvokable
- All Known Implementing Classes:
AbstractInvokable,AbstractIterativeTask,AbstractTwoInputStreamTask,BatchTask,DataSinkTask,DataSourceTask,IterationHeadTask,IterationIntermediateTask,IterationSynchronizationSinkTask,IterationTailTask,MultipleInputStreamTask,OneInputStreamTask,SourceOperatorStreamTask,SourceStreamTask,StreamIterationHead,StreamIterationTail,StreamTask,TwoInputStreamTask
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()This method is called when a task is canceled either as a result of a user abort or an execution failure.voidvoidinvoke()Starts the execution.booleanvoidmaybeInterruptOnCancel(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 Details
-
invoke
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
This 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
Cleanup 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
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 toInputGate.pollNext(). To be removed together with the DataSet API.
-
maybeInterruptOnCancel
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
-