Packagecom.developmentarc.framework.controllers
Classpublic class TaskController
InheritanceTaskController Inheritance flash.events.EventDispatcher

The TaskController class is the main manager of the task system framework. This class is responsible for managing current and new tasks in a task system. The class is used as an instance to allow for multiple task to run in the same application.

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.



Public Properties
 PropertyDefined by
  activeTaskLimit : uint
Contains the number of tasks that can be run at the same time.
TaskController
Protected Properties
 PropertyDefined 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
Public Methods
 MethodDefined by
  
Constructor.
TaskController
  
addTask(task:ITask):void
When an ITask (task, task group, etc.) is ready to be added to the controller this method is called.
TaskController
Protected Methods
 MethodDefined 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
  
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
Property detail
activeTaskLimitproperty
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
activeTasksproperty 
protected var activeTasks:HashTable

Stores the active Tasks and TaskGroups that are have been started by the controller.

notReadyQueueproperty 
protected var notReadyQueue:HashTable

Stores ITasks that returned false for the ready value when attempted to be started by the controller.

taskQueueproperty 
protected var taskQueue:PriorityQueue

Stores the current Tasks and TaskGroups within the TaskController.

Constructor detail
TaskController()constructor
public function TaskController()

Constructor.

Method detail
addTask()method
public function addTask(task:ITask):void

When 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.

Parameters
task: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.

Parameters
newTask:ITask — New Task to be added to queue

Returns
Boolean — Boolean True if newTasks overrides were processed,otherwise false
handleTaskEvent()method 
protected function handleTaskEvent(event:TaskEvent):void

Called 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.

Parameters
event:TaskEvent — The TaskEvent dispatched from the watched ITask instance.
next()method 
protected function next():void

Checks 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.