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.TaskTask.TaskStateModel
 
- 
 - 
Constructor SummaryConstructors Constructor Description AbstractTask(java.util.UUID id)
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidapplyTaskStateModel(Task.TaskStateModel model)Can be overridden by sub classes to receive the state model before the task is resumed.voidcancel(long timeoutMS)When called, the task should stop as quickly as possible.protected abstract voiddoTaskWork(TaskContext context)Should execute the work of the task.protected TaskContextgetCurrentContext()java.util.UUIDgetId()protected LoggerExgetLogger()protected abstract java.lang.StringgetLoggerName()protected java.util.Optional<Task.TaskStateModel>getTaskStateModel()Can be overridded by sub tasks to provide a state model when the task is suspended.protected booleanisStopped()voidresume(Task.TaskStateModel state)voidrun(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- 
getLoggerNameprotected abstract java.lang.String getLoggerName() 
 - 
getLoggerprotected LoggerEx getLogger() 
 - 
getCurrentContextprotected TaskContext getCurrentContext() 
 - 
isStoppedprotected boolean isStopped() 
 - 
runpublic final void run(TaskContext context) throws java.lang.Exception Description copied from interface:TaskExecutes 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.
 - 
suspendpublic java.util.Optional<Task.TaskStateModel> suspend(long timeoutMS) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException Description copied from interface:TaskWhen 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".
 - 
resumepublic void resume(Task.TaskStateModel state) 
 - 
cancelpublic void cancel(long timeoutMS) throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionDescription copied from interface:TaskWhen 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".
 - 
getTaskStateModelprotected 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"
 - 
applyTaskStateModelprotected 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.
 - 
doTaskWorkprotected 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
 
 
- 
 
-