Interface TaskExecutor<T,V>

Type Parameters:
T - the type of progress updates passed during task execution
V - the type of the result produced by the background task

public interface TaskExecutor<T,V>
The TaskExecutor interface provides methods for managing the lifecycle of a background task. It allows tasks to be started, canceled, tracked for progress, and finalized upon completion. The interface ensures thread-safe operations and UI integration for updating or interacting with the user interface during task execution.
  • Method Details

    • startExecution

      void startExecution()
      Executes background task.
    • cancelExecution

      boolean cancelExecution()
      Cancels the execution and removes task form BackgroundTaskWatchDog and from BackgroundTaskManager.
      Returns:
      true if the canceling was successful
    • getResult

      @Nullable V getResult()
      Joins task thread to current and waits if task is not finished.
      Returns:
      result of the task
    • getTask

      BackgroundTask<T,V> getTask()
      Returns:
      the task
    • isCancelled

      boolean isCancelled()
      Checks whether the background task is cancelled.
      Returns:
      true if the task is cancelled, false otherwise.
    • isDone

      boolean isDone()
      Checks whether the background task is completed.
      Returns:
      true if the task is finished, false otherwise.
    • inProgress

      boolean inProgress()
      Checks whether the background task is currently in progress.
      Returns:
      true if the task is in progress, false otherwise.
    • setFinalizer

      void setFinalizer(Runnable finalizer)
      Sets done handler for clear resources.
      Parameters:
      finalizer - Runnable handler
    • getFinalizer

      Runnable getFinalizer()
      Returns the finalizer runnable that is responsible for resource cleanup or post-task actions once the execution of a background task is complete.
      Returns:
      the finalizer runnable, or null if no finalizer has been set
    • handleProgress

      void handleProgress(T... changes)
      Handles changes from working thread.
      Parameters:
      changes - Changes