@Internal public interface TaskInvokable
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.
CheckpointableTask
,
CoordinatedTask
,
AbstractInvokable
Modifier and Type | Method and Description |
---|---|
void |
cancel()
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)
|
void |
invoke()
Starts the execution.
|
boolean |
isUsingNonBlockingInput() |
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 |
restore()
This method can be called before
invoke() to restore an invokable object for the
last valid state, if it has it. |
void invoke() throws Exception
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.
Exception
void restore() throws Exception
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.
Exception
void cleanUp(@Nullable Throwable throwable) throws Exception
invoke()
OR restore()
. This method must be
called regardless whether the aforementioned calls succeeded or failed.throwable
- iff failure happened during the execution of restore()
or invoke()
, null otherwise.
ATTENTION: CancelTaskException
should not be treated as a failure.
Exception
void cancel() throws Exception
Exception
boolean isUsingNonBlockingInput()
InputGate.getNext()
is used (as opposed to
InputGate.pollNext()
. To be removed together with the DataSet API.void maybeInterruptOnCancel(Thread toInterrupt, @Nullable String taskName, @Nullable Long timeout)
Runnable interruptAction
.toInterrupt
- taskName
- optional taskName to log stack tracetimeout
- optional timeout to log stack traceCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.