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 TypeMethodDescriptionboolean
finishWithError
(TaskId taskId, Throwable error) boolean
finishWithResult
(TaskId taskId, Object result) Finishes the task with associatedTaskId
with the provided result.void
void
setTaskService
(TaskService taskService) void
start()
Starts thisTaskContext
.void
stop()
Stops thisTaskContext
.
-
Constructor Details
-
SimpleTaskContext
public SimpleTaskContext()
-
-
Method Details
-
start
public void start()Description copied from interface:TaskContext
Starts thisTaskContext
.- Specified by:
start
in interfaceTaskContext
-
stop
public void stop()Description copied from interface:TaskContext
Stops thisTaskContext
.- Specified by:
stop
in interfaceTaskContext
-
register
public void register(TaskId taskId, Consumer<Object> consumer, Consumer<Throwable> throwableTConsumer) Description copied from interface:TaskContext
Registers the suppliedTaskId
, resultConsumer
, andConsumer<Throwable>
for the associated task. TheTaskContext
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 interfaceTaskContext
- Parameters:
taskId
- the task IDconsumer
-throwableTConsumer
-
-
finishWithResult
Description copied from interface:TaskContext
Finishes the task with associatedTaskId
with 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:
finishWithResult
in interfaceTaskContext
- Parameters:
taskId
-- Returns:
- true if the task was finished, false if otherwise
-
finishWithError
Description copied from interface:TaskContext
Finishes the task with associatedTaskId
with the providedThrowable
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 interfaceTaskContext
- Parameters:
taskId
- theTaskId
- Returns:
- true if the task was finished, false if otherwise
-
getTaskService
-
setTaskService
-