| Package | com.developmentarc.framework.controllers |
| Class | public class TaskController |
| Inheritance | TaskController flash.events.EventDispatcher |
The TaskController, by default, is not a singleton and the goal of the framework is to allow multiple Task systems to be running in any given application. For example, one task system can be created to manage server requests while another can be used to control internal business operations. To create multiple systems, simply create multiple instances of the TaskController.
To use the TaskController as a singleton, utilize the SingletonFactory utility class within the DevelopmentArc Core library.
The controller starts a set of tasks based on the active task limit set on the controller. By default 2 tasks can be concurrently active within the controller, however this is configurable in the task controller instance. When a task is complete the controller will remove the task from the active list and start the next one in the queue, if any.
The TaskController is also responsible for managing overrides. When a task is added to the controller, the tasks overrides are applied removing any existing tasks from the queue that matches an override. Overrides do pertain to tasks that are currently active, those will be canceled and removed from the queue. Next the task is added to the internal priority queue in the proper order.| Property | Defined by | ||
|---|---|---|---|
| activeTaskLimit : uint
Contains the number of tasks that can be run at the same time.
| TaskController | ||
| Property | Defined by | ||
|---|---|---|---|
| activeTasks : HashTable
Stores the active Tasks and TaskGroups that are have been started by the controller.
| TaskController | ||
| notReadyQueue : HashTable
Stores ITasks that returned false for the ready value when attempted to be started by the controller.
| TaskController | ||
| taskQueue : PriorityQueue
Stores the current Tasks and TaskGroups within the TaskController.
| TaskController | ||
| Method | Defined by | ||
|---|---|---|---|
|
Constructor.
| TaskController | ||
|
When an ITask (task, task group, etc.) is ready to be added to the controller this
method is called.
| TaskController | ||
| Method | Defined by | ||
|---|---|---|---|
|
applyOverrides(newTask:ITask):Boolean
Used to find and remove any tasks in the current queue that are overriden by a new task that has been added to the controller. | TaskController | ||
|
handleTaskEvent(event:TaskEvent):void
Called when a task changes state, such as complete or error.
| TaskController | ||
|
next():void
Checks to see if any task slots are available, if so then the next
task in the queue is added.
| TaskController | ||
| activeTaskLimit | property |
activeTaskLimit:uint [read-write]Contains the number of tasks that can be run at the same time. The defaulf value is 2 tasks.
Implementation public function get activeTaskLimit():uint
public function set activeTaskLimit(value:uint):void
| activeTasks | property |
protected var activeTasks:HashTableStores the active Tasks and TaskGroups that are have been started by the controller.
| notReadyQueue | property |
protected var notReadyQueue:HashTableStores ITasks that returned false for the ready value when attempted to be started by the controller.
| taskQueue | property |
protected var taskQueue:PriorityQueueStores the current Tasks and TaskGroups within the TaskController.
| TaskController | () | constructor |
public function TaskController()Constructor.
| addTask | () | method |
public function addTask(task:ITask):voidWhen an ITask (task, task group, etc.) is ready to be added to the controller this method is called. addTask() puts the item at the end of the queue and then applies any overrides assigned by the ITask. If the current queue contains overrides then the override conflict logic is applied to determine if the added item is kept and the existing conflicting task is removed or if the existing task is kept and the new one is discarded.
Parameterstask:ITask — The ITask to add to the controller.
|
| applyOverrides | () | method |
protected function applyOverrides(newTask:ITask):Boolean
Used to find and remove any tasks in the current queue that are overriden by a new task that has been added to the controller. This includes those tasks that are active.
If the new task is selfOverriding two scenarios will play out.
newTask:ITask — New Task to be added to queue
|
Boolean — Boolean True if newTasks overrides were processed,otherwise false
|
| handleTaskEvent | () | method |
protected function handleTaskEvent(event:TaskEvent):voidCalled when a task changes state, such as complete or error. Handles unregistering event listening, checks to see if the queue was blocked and then calls next() to continue the process.
Parametersevent:TaskEvent — The TaskEvent dispatched from the watched ITask instance.
|
| next | () | method |
protected function next():voidChecks to see if any task slots are available, if so then the next task in the queue is added. This method is called when tasks are added or change state. This method is protected to prevent developers from directly calling next() and instead letting the controller process the queue based on the defined logic.