Interface ProgressWorker.Handler
- All Known Subinterfaces:
ProgressWorker.ProgressHandler<V>,ProgressWorker.ProgressResultTaskHandler<T,,V> ProgressWorker.ProgressTaskHandler<V>,ProgressWorker.ResultTaskHandler<T>,ProgressWorker.TaskHandler
- All Known Implementing Classes:
DomainGeneratorModel.PopulateTask
- Enclosing class:
ProgressWorker<T,V>
Provides default handler methods for the ProgressWorker lifecycle.
All handler methods are called using the Dispatcher.
Combined with a task interface (via ProgressWorker.TaskHandler, ProgressWorker.ResultTaskHandler, etc.),
this allows a single class to encapsulate both the background task and its handlers.
Handler methods from this interface are automatically wired when the task is passed to
ProgressWorker.BuilderFactory.task(Task), and called first. Any handlers added via the ProgressWorker.Builder
are called after, in the order they were added.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidCalled using theDispatcherif the background task was cancelled.default voidonDone()Called using theDispatcherwhen the task is done, successfully or not, before the result is processed.default voidonException(Exception exception) Called using theDispatcherif an exception occurred during the background task.default voidCalled using theDispatcherif the background task was interrupted.default voidCalled using theDispatcherbefore the background task executes.default voidCalled using theDispatcherafter a successful task execution, beforeProgressWorker.ResultTaskHandler.onResult(Object)orProgressWorker.ProgressResultTaskHandler.onResult(Object)for result-producing tasks.
-
Method Details
-
onStarted
default void onStarted()Called using theDispatcherbefore the background task executes. -
onDone
default void onDone()Called using theDispatcherwhen the task is done, successfully or not, before the result is processed. -
onSuccess
default void onSuccess()Called using theDispatcherafter a successful task execution, beforeProgressWorker.ResultTaskHandler.onResult(Object)orProgressWorker.ProgressResultTaskHandler.onResult(Object)for result-producing tasks. -
onException
Called using theDispatcherif an exception occurred during the background task.The default implementation rethrows the exception as a
RuntimeException. Override to handle the exception, for example by displaying it.- Parameters:
exception- the exception
-
onCancelled
default void onCancelled()Called using theDispatcherif the background task was cancelled. -
onInterrupted
default void onInterrupted()Called using theDispatcherif the background task was interrupted.The default implementation simply calls
Thread.currentThread().interrupt().
-