Hemi JavaScript Framework
Hemi.task
Description
The Task Service coordinates various actions and handlers and dependencies. Tasks are excellent bootstraps for multiple asynchronous operations.
Class Index
static Hemi.task.service
version 3.1.0
Static instance of serviceImpl.
Hemi.task.TaskServiceImpl
version 3.1.0
A service for managing asynchronous and dependency-driven actions.
Index
Object Index
Method Index
- public addTask: Adds a new task.
- public addTaskDependency: Adds a dependency to a Task object.
- public addTaskLoader: Convenience method for adding a task that overrides the default task loader name.
- public clearAllTasks: Clears all tasks. Any task that is still in operation will be unceremoniously removed from operation, as opposed to clearTask which allows the task to continue current operation until it's finished.
- public clearDependency: Removes the specified dependency, regardless of whether it was resolved or completed.
- public clearTask: Clears the specified task and removes the TaskObject. If the task is still in operation, auto destroy is enabled and the task will continue to function.
- public destroy: Prepares this object for destruction. All tasks will be cleared.
- public doTransaction (internal): Invoked by TransactionService as a TransactionParticipant.
- public endTask: End task returns all named dependencies for the task, and then invokes clearTask.
- public endTransaction (internal): Invoked by TransactionService as a TransactionParticipant.
- public executeTask: Forces the task action to be executed.
- public executeTaskByName: Forces the task action to be executed.
- public executeTaskHandler: Forces the task handler to be executed, and positioning the task to be in a completed state.
- public executeTaskHandlerByName: Forces the task handler to be executed, and positioning the task to be in a completed state.
- public executeTaskLoader: Convenience method for adding and immediately executing a task. Used as a driver to launch other task lists by the Space service. Invokes addTaskLoader.
- public getTask: Returns the specified Task object.
- public getTaskByName: Returns the specified Task object.
- public getTaskDepends: Returns a copy of the dependency names for this task.
- public getTasks: Returns an array of Task objects.
- public importTaskFromXML: Creates a TaskObject from the specified XML Node.
- public isExternalLoaded: Returns true if any external task list has been loaded, false otherwise.
- public isTask: Returns true if the specified name exists.
- public isTaskComplete: Returns whether or not the task was completed.
- public newTaskObject (internal): Creates a new task object.
- public returnDependency: Returns the specified depency name or dependent task name, causing all tasks identifying this dependency to be updated. If the returned dependency is a task, the task is forced closed regardless of whether its action or handler were executed.
- public serveTaskTransaction: Forces the transaction that drives the Task object to serve the corresponding TransactionPacket. This is used when a Task object is thought to be stuck due to some uncaught exception in its action, handler, or dependencies.
- public sigterm: Sends a termination signal to this object.
- public startTransaction (internal): Invoked by TransactionService as a TransactionParticipant.
Objects
Task
Properties
- task_state as int: Current state of the task. State ranges from 0 to 5.
- handled as boolean: Bit indicating the task has been handled.
- task_id as String: The unique task identifier.
- transaction_id as String: The transaction identifier for this task.
- index as int: The index of this task in the TaskService tasks array.
- task_name as String: The name of the task.
- action_type as String: The type of action this task performs. Supported types are: xml, task, import-task, event, script, and function.
- action as String: The action this task performs, based on the
- handler_type as String: The type of handler this task performs. Supported types are: xml, task, import-task, event, script, and function.
- handler as String: The handler this task performs, based on the
- data as variant: The data associated with the task.
- depends as array: Array of identifiers representing dependencies that must be completed before the task can be handled.
- executed as boolean: Bit indicating the task has been executed.
- processor as function: Task pre-processor for manipulating XML data prior to the task being evaluated.
- busy as boolean: Bit indicating the task is busy working on its action or handler.
- parent_id as String: The identifier of the parent task, which depends on this task to complete.
Methods
Methods
addTask
Adds a new task.
Syntax
o = addTask(
n, at, a, ht, h, f
)
Parameters
- n as String : Task name.
- at as String : Action type. Supported types are: xml, task, import-task, event, script, and function.
- a as variant : Task action, based on specified action type.
- ht as String : Handler type. Supported types are: xml, task, import-task, event, script, and function.
- h as variant : Task handler, based on specified action type.
- f as function (optional): Dependency pre-processor used to resolve tokenized values for xml import tasks.
Returns
o as TaskObject: New Task object.
addTaskDependency
Adds a dependency to a Task object.
Syntax
a = addTaskDependency(
t, d
)
Parameters
- t as TaskObject : A Task object.
- d as String : Name of the dependency.
Returns
a as boolean: Bit indicating whether the dependency was added.
addTaskLoader
Convenience method for adding a task that overrides the default task loader name.
Syntax
o = addTaskLoader(
n, at, a, ht, h, f
)
Parameters
- n as String : Task name.
- at as String : Action type. Supported types are: xml, task, import-task, event, script, and function.
- a as variant : Task action, based on specified action type.
- ht as String : Handler type. Supported types are: xml, task, import-task, event, script, and function.
- h as variant : Task handler, based on specified action type.
- f as function (optional): Dependency pre-processor used to resolve tokenized values for xml import tasks.
Returns
o as TaskObject: New Task object.
clearAllTasks
Clears all tasks. Any task that is still in operation will be unceremoniously removed from operation, as opposed to clearTask which allows the task to continue current operation until it's finished.
Syntax
void clearAllTasks(
)
clearDependency
Removes the specified dependency, regardless of whether it was resolved or completed.
Syntax
void clearDependency(
v
)
Parameters
- v as variant : A Task object, task name, or dependency name.
clearTask
Clears the specified task and removes the TaskObject. If the task is still in operation, auto destroy is enabled and the task will continue to function.
Syntax
t = clearTask(
v
)
Parameters
- v as Variant : TaskObject or task identifier.
Returns
t as boolean: Returns true if the task was cleared or slated to be cleared, or otherwise false.
destroy
Prepares this object for destruction. All tasks will be cleared.
Syntax
void destroy(
)
doTransaction
Invoked by TransactionService as a TransactionParticipant.
Syntax
void doTransaction(
s, p
)
Parameters
- s as TransactionService : TransactionService managing this transaction.
- p as TransactionPacket : TransactionPacket used to monitor the task state.
endTask
End task returns all named dependencies for the task, and then invokes clearTask.
Syntax
t = endTask(
v, b
)
Parameters
- v as Variant : TaskObject or task identifier.
- b as Boolean : Bit indicating that all task dependencies should be removed from the cleared dependencies list.
Returns
t as boolean: Returns true if the task was ended.
endTransaction
Invoked by TransactionService as a TransactionParticipant.
Syntax
void endTransaction(
s, p
)
Parameters
- s as TransactionService : TransactionService managing this transaction.
- p as TransactionPacket : TransactionPacket used to monitor the task state.
executeTask
Forces the task action to be executed.
Syntax
b = executeTask(
o
)
Parameters
- o as Task : A Task object.
Returns
b as boolean: Bit indicating whether the task action was executed.
executeTaskByName
Forces the task action to be executed.
Syntax
b = executeTaskByName(
n
)
Parameters
- n as String : The name of a task object.
Returns
b as boolean: Bit indicating whether the task action was executed.
executeTaskHandler
Forces the task handler to be executed, and positioning the task to be in a completed state.
Syntax
b = executeTaskHandler(
o
)
Parameters
- o as Task : A Task object.
Returns
b as boolean: Bit indicating whether the handler was executed.
executeTaskHandlerByName
Forces the task handler to be executed, and positioning the task to be in a completed state.
Syntax
b = executeTaskHandlerByName(
n
)
Parameters
- n as String : The name of a task object.
Returns
b as boolean: Bit indicating whether the handler was executed.
executeTaskLoader
Convenience method for adding and immediately executing a task. Used as a driver to launch other task lists by the Space service. Invokes addTaskLoader.
Syntax
o = executeTaskLoader(
n, at, a, ht, h, f
)
Parameters
- n as String : Task name.
- at as String : Action type. Supported types are: xml, task, import-task, event, script, and function.
- a as variant : Task action, based on specified action type.
- ht as String : Handler type. Supported types are: xml, task, import-task, event, script, and function.
- h as variant : Task handler, based on specified action type.
- f as function (optional): Dependency pre-processor used to resolve tokenized values for xml import tasks.
Returns
o as TaskObject: New Task object.
getTask
Returns the specified Task object.
Syntax
e = getTask(
i
)
Parameters
- i as int : Index of the Task object..
Returns
e as Task: XHTMLForm object.
getTaskByName
Returns the specified Task object.
Syntax
e = getTaskByName(
n
)
Parameters
- n as String : Name of the element.
Returns
e as Task: Task object.
getTaskDepends
Returns a copy of the dependency names for this task.
Syntax
a = getTaskDepends(
t
)
Parameters
- t as TaskObject : A Task object.
Returns
a as array: Array of task dependency names.
getTasks
Returns an array of Task objects.
Syntax
a = getTasks(
)
Returns
a as array: Array of Task objects.
importTaskFromXML
Creates a TaskObject from the specified XML Node.
Syntax
void importTaskFromXML(
n, o, d, b
)
Parameters
- n as variant : XML Node representing a task, or a String naming a task.
- o as TaskObject (optional): Parent task, which would be made dependent on this task.
- d as DOMDocument : The XML Document from which the XML Node originated.
- b as boolean : Bit indicating the task should be executed immediately.
isExternalLoaded
Returns true if any external task list has been loaded, false otherwise.
Syntax
b = isExternalLoaded(
)
Returns
b as boolean: Bit indicating whether an external task list has been loaded.
isTask
Returns true if the specified name exists.
Syntax
b = isTask(
i
)
Parameters
- i as variant : Name or index of the Task object..
Returns
b as boolean: Bit indicating whether the specified object name exists.
isTaskComplete
Returns whether or not the task was completed.
Syntax
c = isTaskComplete(
o
)
Parameters
- o as Task : A Task object.
Returns
c as boolean: Bit indicating whether the task was completed.
newTaskObject
Creates a new task object.
Syntax
t = newTaskObject(
n, at, a, ht, h, k, i, r, p
)
Parameters
- n as String : Unique task name.
- at as String : Action type.
- a as String : Action, based on type. Example: Action type of function would be a function name (not evaluatable)
- ht as String : Handler type.
- h as String : Handler, based on type.
- k as String : Task id.
- i as int : Task index.
- r as String : Transaction id.
- p as function : Task pre-prococessor.
Returns
t as TaskObject: Returns a new TaskObject.
returnDependency
Returns the specified depency name or dependent task name, causing all tasks identifying this dependency to be updated. If the returned dependency is a task, the task is forced closed regardless of whether its action or handler were executed.
Syntax
void returnDependency(
v
)
Parameters
- v as variant : A Task object, task name, or dependency name.
serveTaskTransaction
Forces the transaction that drives the Task object to serve the corresponding TransactionPacket. This is used when a Task object is thought to be stuck due to some uncaught exception in its action, handler, or dependencies.
Syntax
void serveTaskTransaction(
o
)
Parameters
- o as Task : A Task object.
sigterm
Sends a termination signal to this object.
Syntax
void sigterm(
)
startTransaction
Invoked by TransactionService as a TransactionParticipant.
Syntax
void startTransaction(
s, p
)
Parameters
- s as TransactionService : TransactionService managing this transaction.
- p as TransactionPacket : TransactionPacket used to monitor the task state.
[ Hemi JavaScript Framework - Stephen W. Cote, 2002 - 2009. ]