Class SimpleTaskContext

java.lang.Object
dev.getelements.elements.rt.SimpleTaskContext
All Implemented Interfaces:
TaskContext

public class SimpleTaskContext extends Object implements TaskContext
  • Constructor Details

    • SimpleTaskContext

      public SimpleTaskContext()
  • Method Details

    • start

      public void start()
      Description copied from interface: TaskContext
      Starts this TaskContext.
      Specified by:
      start in interface TaskContext
    • stop

      public void stop()
      Description copied from interface: TaskContext
      Stops this TaskContext.
      Specified by:
      stop in interface TaskContext
    • register

      public void register(TaskId taskId, Consumer<Object> consumer, Consumer<Throwable> throwableTConsumer)
      Description copied from interface: TaskContext
      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.
      Specified by:
      register in interface TaskContext
      Parameters:
      taskId - the task ID
      consumer -
      throwableTConsumer -
    • finishWithResult

      public boolean finishWithResult(TaskId taskId, Object result)
      Description copied from interface: TaskContext
      Finishes the task with associated TaskId with the provided result. Consumers previously registered with the TaskContext.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.
      Specified by:
      finishWithResult in interface TaskContext
      Parameters:
      taskId -
      Returns:
      true if the task was finished, false if otherwise
    • finishWithError

      public boolean finishWithError(TaskId taskId, Throwable error)
      Description copied from interface: TaskContext
      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.
      Specified by:
      finishWithError in interface TaskContext
      Parameters:
      taskId - the TaskId
      Returns:
      true if the task was finished, false if otherwise
    • getTaskService

      public TaskService getTaskService()
    • setTaskService

      @Inject public void setTaskService(TaskService taskService)