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>

public static interface ProgressWorker.Handler

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 Details

    • onStarted

      default void onStarted()
      Called using the Dispatcher before the background task executes.
    • onDone

      default void onDone()
      Called using the Dispatcher when the task is done, successfully or not, before the result is processed.
    • onWorking

      default void onWorking(boolean working)
      Called using the Dispatcher with true before onStarted() and with false after onDone(), that is, before the result, exception or cancellation is handled. Only called with false in case it was called with true, which is not the case for a task cancelled before it started.
      Parameters:
      working - true when the task is about to start, false when it is done
    • onSuccess

      default void onSuccess()
      Called using the Dispatcher after a successful task execution, before ProgressWorker.ResultTaskHandler.onResult(Object) or ProgressWorker.ProgressResultTaskHandler.onResult(Object) for result-producing tasks.
    • onException

      default void onException(Exception exception)
      Called using the Dispatcher if 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 the Dispatcher if the background task was cancelled.
    • onInterrupted

      default void onInterrupted()
      Called using the Dispatcher if the background task was interrupted.

      The default implementation simply calls Thread.currentThread().interrupt().