Interface TaskContext

All Known Implementing Classes:
SimpleTaskContext

public interface TaskContext
Manages the global state of currently operating tasks. This allows a callers to listen for tasks as they are running and receive callbacks that the task has completed. While each Resource is responsible for managing tasks, this is the hub through which all tasks are managed.
  • Method Details

    • start

      default void start()
      Starts this TaskContext.
    • stop

      default void stop()
      Stops this TaskContext.
    • register

      void register(TaskId taskId, Consumer<Object> tConsumer, Consumer<Throwable> throwableTConsumer)
      Registers the supplied TaskId, result Consumer, and Consumer<Throwable> for the associated task. The TaskContext will store the associated result consumers internally and at some point later invoke either the result or failure consumer. However, it is advisable to account for scenarios where neither consumer may be called. This may happen in the event the remote service has been restarted and in-memory consumers were lost. The calling code should have a strategy to account for timeouts where appropriate.
      Parameters:
      taskId - the task ID
      tConsumer -
      throwableTConsumer -
      Throws:
      DuplicateTaskException - if the supplied TaskId was already registered.
    • finishWithResult

      boolean finishWithResult(TaskId taskId, Object result)
      Finishes the task with associated TaskId with the provided result. Consumers previously registered with the register(TaskId, Consumer, Consumer) call will be processed. As not all tasks are registered with a set of listeners, this may simply return false indicating that no listeners were notified.
      Parameters:
      taskId -
      Returns:
      true if the task was finished, false if otherwise
    • finishWithError

      boolean finishWithError(TaskId taskId, Throwable error)
      Finishes the task with associated TaskId with the provided Throwable error. As not all tasks are registered with a set of listeners, this may simply return false indicating that no listeners were notified.
      Parameters:
      taskId - the TaskId
      Returns:
      true if the task was finished, false if otherwise