Class AbstractTask
java.lang.Object
com.inductiveautomation.ignition.gateway.tasks.AbstractTask
- All Implemented Interfaces:
Task
This abstract implementation of Task handles some of the complexity of dealing with pausing, cancelling, and
resuming. Implementations only have to implement doTaskWork(), though they may also implement the state related
functions to allow for pausing.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.inductiveautomation.ignition.gateway.tasks.Task
Task.TaskStateModel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Can be overridden by sub classes to receive the state model before the task is resumed.void
cancel
(long timeoutMS) When called, the task should stop as quickly as possible.protected abstract void
doTaskWork
(TaskContext context) Should execute the work of the task.protected TaskContext
getId()
protected LoggerEx
protected abstract String
protected Optional<Task.TaskStateModel>
Can be overridded by sub tasks to provide a state model when the task is suspended.protected boolean
void
resume
(Task.TaskStateModel state) final void
run
(TaskContext context) Executes the task.suspend
(long timeoutMS) When called, the task should stop as quickly as possible.
-
Constructor Details
-
AbstractTask
-
-
Method Details
-
getId
-
getLoggerName
-
getLogger
-
getCurrentContext
-
isStopped
protected boolean isStopped() -
run
Description copied from interface:Task
Executes the task. This function should block until completion. If there is a problem executing the task, an exception should be thrown. It is important to note that while this function should block, the task must expect that at some point, suspend or cancel may be called. -
suspend
public Optional<Task.TaskStateModel> suspend(long timeoutMS) throws TimeoutException, InterruptedException Description copied from interface:Task
When called, the task should stop as quickly as possible. If the task is able to resume, it should return a state that will be provided to it when restarted. If this function returns an empty value, it will not be resumed. If appropriate, the call should try to implement the timeout restriction passed in. A timeout of 0 means "no timeout".- Specified by:
suspend
in interfaceTask
- Throws:
TimeoutException
InterruptedException
-
resume
-
cancel
Description copied from interface:Task
When called, the task should stop as quickly as possible. If appropriate, the call should try to implement the timeout restriction passed in. A timeout of 0 means "no timeout".- Specified by:
cancel
in interfaceTask
- Throws:
TimeoutException
InterruptedException
-
getTaskStateModel
Can be overridded by sub tasks to provide a state model when the task is suspended. This will be called after doTaskWork() has exited when the task is "stopped" -
applyTaskStateModel
Can be overridden by sub classes to receive the state model before the task is resumed. At some point soon after this is called, the doTaskWork() function will be called. -
doTaskWork
Should execute the work of the task. It is possible that this function will be called multiple times in the lifecycle of the task. The task may be paused, or the task may choose to yield execution. To yield, it should set its state to "WAITING", and return out of this function. At some point later, it can be resumed by calling resumeTask() on the context, or by the task manager.Inside of this function, the task should periodically check isStopped to see if the task has been paused or canceled.
- Throws:
Exception
-