Class AbstractTask
- java.lang.Object
-
- com.inductiveautomation.ignition.gateway.tasks.AbstractTask
-
- All Implemented Interfaces:
Task
public abstract class AbstractTask extends java.lang.Object implements 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 Constructor Description AbstractTask(java.util.UUID id)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
applyTaskStateModel(Task.TaskStateModel model)
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
getCurrentContext()
java.util.UUID
getId()
protected LoggerEx
getLogger()
protected abstract java.lang.String
getLoggerName()
protected java.util.Optional<Task.TaskStateModel>
getTaskStateModel()
Can be overridded by sub tasks to provide a state model when the task is suspended.protected boolean
isStopped()
void
resume(Task.TaskStateModel state)
void
run(TaskContext context)
Executes the task.java.util.Optional<Task.TaskStateModel>
suspend(long timeoutMS)
When called, the task should stop as quickly as possible.
-
-
-
Method Detail
-
getLoggerName
protected abstract java.lang.String getLoggerName()
-
getLogger
protected LoggerEx getLogger()
-
getCurrentContext
protected TaskContext getCurrentContext()
-
isStopped
protected boolean isStopped()
-
run
public final void run(TaskContext context) throws java.lang.Exception
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 java.util.Optional<Task.TaskStateModel> suspend(long timeoutMS) throws java.util.concurrent.TimeoutException, java.lang.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".
-
resume
public void resume(Task.TaskStateModel state)
-
cancel
public void cancel(long timeoutMS) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException
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".
-
getTaskStateModel
protected java.util.Optional<Task.TaskStateModel> 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
protected void applyTaskStateModel(Task.TaskStateModel model)
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
protected abstract void doTaskWork(TaskContext context) throws java.lang.Exception
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:
java.lang.Exception
-
-