Package dev.getelements.elements.rt
Class SimpleTaskContext
java.lang.Object
dev.getelements.elements.rt.SimpleTaskContext
- All Implemented Interfaces:
TaskContext
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanfinishWithError(TaskId taskId, Throwable error) booleanfinishWithResult(TaskId taskId, Object result) Finishes the task with associatedTaskIdwith the provided result.voidvoidsetTaskService(TaskService taskService) voidstart()Starts thisTaskContext.voidstop()Stops thisTaskContext.
-
Constructor Details
-
SimpleTaskContext
public SimpleTaskContext()
-
-
Method Details
-
start
public void start()Description copied from interface:TaskContextStarts thisTaskContext.- Specified by:
startin interfaceTaskContext
-
stop
public void stop()Description copied from interface:TaskContextStops thisTaskContext.- Specified by:
stopin interfaceTaskContext
-
register
public void register(TaskId taskId, Consumer<Object> consumer, Consumer<Throwable> throwableTConsumer) Description copied from interface:TaskContextRegisters the suppliedTaskId, resultConsumer, andConsumer<Throwable>for the associated task. TheTaskContextwill 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:
registerin interfaceTaskContext- Parameters:
taskId- the task IDconsumer-throwableTConsumer-
-
finishWithResult
Description copied from interface:TaskContextFinishes the task with associatedTaskIdwith the provided result. Consumers previously registered with theTaskContext.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:
finishWithResultin interfaceTaskContext- Parameters:
taskId-- Returns:
- true if the task was finished, false if otherwise
-
finishWithError
Description copied from interface:TaskContextFinishes the task with associatedTaskIdwith the providedThrowableerror. As not all tasks are registered with a set of listeners, this may simply return false indicating that no listeners were notified.- Specified by:
finishWithErrorin interfaceTaskContext- Parameters:
taskId- theTaskId- Returns:
- true if the task was finished, false if otherwise
-
getTaskService
-
setTaskService
-