9.2. Task instances|任務(wù)實(shí)例|
A task instance can be assigned to an actorId (java.lang.String).|任務(wù)實(shí)例被分派給一個(gè)行為ID。| All task instances are stored in one table of the database (JBPM_TASKINSTANCE).|所有的實(shí)例都被存儲(chǔ)在數(shù)據(jù)庫的一個(gè)表格里(JBPM_TASKINSTANCE)。| By querying this table for all task instances for a given actorId, you get the task list for that perticular user. |通過查詢這個(gè)行為ID表的所有任務(wù)實(shí)例的表,你得到指定用戶的任務(wù)列表。|
The jBPM task list mechanism can combine jBPM tasks with other tasks, even when those tasks are unrelated to a process execution.|jBPM任務(wù)列表機(jī)制可以與其它任務(wù)結(jié)合jBPM任務(wù),甚至當(dāng)這些任務(wù)與一個(gè)流程執(zhí)行無關(guān)。| That way jBPM developers can easily combine jBPM-process-tasks with tasks of other applications in one centralized task-list-repository.|那種方法jBPM開發(fā)人員可以和容易的使jBPM流程任務(wù)在一個(gè)集中的任務(wù)列表庫與其他程序中的任務(wù)|
9.2.1. Task instance life cycle |任務(wù)實(shí)例生命周期|
The task instance lifecycle is straightforward: After creation, task instances can optionally be started.|任務(wù)生命周期是 簡單的:在創(chuàng)建之后,任務(wù)實(shí)例可以隨意地被開始。| Then, task instances can be ended, which means that the task instance is marked as completed.|接著,任務(wù)實(shí)例可能被結(jié)束,它意味著任務(wù)實(shí)例已經(jīng)被標(biāo)志已完成。|
Note that for flexibility, assignment is not part of the life cycle.|注意適應(yīng)性、委派不是生命周期的一部分。| So task instances can be assigned or not assigned.|所有任務(wù)實(shí)例可能被委派也可能不被委派。| Task instance assignment does not have an influence on the task instance life cycle.|任務(wù)實(shí)例委派不影響任務(wù)實(shí)例的生命周期。|
Task instances are typically created by the process execution entering a task-node (with the method TaskMgmtInstance.createTaskInstance(...)).|任務(wù)實(shí)例被進(jìn)入一個(gè)任務(wù)節(jié)點(diǎn)流程執(zhí)行代典型的創(chuàng)建(使用TaskMgmtInstance.createInstance(...)方法)| Then, a user interface component will query the database for the tasklists using the TaskMgmtSession.findTaskInstancesByActorId(...).|接著一個(gè)用戶接口組件將要為任務(wù)列表查詢數(shù)據(jù)庫使用TaskMgmtSession.findTaskInstancesByActorId(...)| Then, after collecting input from the user, the UI component calls TaskInstance.assign(String), TaskInstance.start() or TaskInstance.end(...).|接著,在收集從用戶收入之后,這個(gè)UI組件調(diào)用TaskIntsance.assign(String),TaskInstance.start() 或者 TaskInstance.end(...)。|
A task instance maintains it's state by means of date-properties : create, start and end.|一個(gè)任務(wù)實(shí)例依靠日期屬性維護(hù)它的狀態(tài):創(chuàng)建、開始、結(jié)束。| Those properties can be accessed by their respective getters on the TaskInstance.|這些屬性可以通過它們的各自在任務(wù)實(shí)例上的的getters被訪問。|
Currently, completed task instances are marked with an end date so that they are not fetched with subsequent queries for tasks lists.|通常地,完成的任務(wù)實(shí)例被標(biāo)志為結(jié)束狀態(tài),所以他們并不通過對(duì)任務(wù)列表的子查詢獲得。| But they remain in the JBPM_TASKINSTANCE table.|但是他們?nèi)匀槐3衷贘BPM_TASKINGSTANCE表中。|
9.2.2. Task instances and graph execution|任務(wù)實(shí)例和圖表執(zhí)行|
Task instances are the items in an actor's tasklist.|任務(wù)實(shí)例是在行動(dòng)者的任務(wù)列表中的項(xiàng)目。| Task instances can be signalling.|任務(wù)實(shí)例可以被發(fā)信號(hào)的| A signalling task instance is a task instance that, when completed, can send a signal to its token to continue the process execution.|一個(gè)發(fā)信號(hào)的任務(wù)實(shí)例是一個(gè)這樣的任務(wù)實(shí)例,當(dāng)被完成時(shí)候,可以發(fā)送一個(gè)信號(hào)給它的令牌以繼續(xù)流程的執(zhí)行。| Task instances can be blocking, meaning that the related token (=path of execution) is not allowed to leave the task-node before the task instance is completed.|任務(wù)實(shí)例可以被模塊化,意味著有關(guān)系的令牌(執(zhí)行路徑)在任務(wù)實(shí)例完成之前允許離開任務(wù)節(jié)點(diǎn)。| By default task instances are signalling and non-blocking. |缺省的任務(wù)實(shí)例是被信號(hào)化且非模塊化的。|
In case more than one task instance are associated with a task-node, the process developer can specify how completion of the task instances affects continuation of the process.|萬一超過一個(gè)的任務(wù)實(shí)例與一個(gè)任務(wù)節(jié)點(diǎn)關(guān)聯(lián),這個(gè)流程開發(fā)者可以定義 任務(wù)實(shí)例的完成如何影響流程的繼續(xù)。| Following is the list of values that can be given to the signal-property of a task-node.|接下來是值的列表可以指定給節(jié)點(diǎn)的信號(hào)屬性。|
last: This is the default.|最后:這是缺省的。| Proceeds execution when the last task instance is completed.|當(dāng)最后流程執(zhí)行完畢,繼續(xù)進(jìn)行執(zhí)行。| When no tasks are created on entrance of this node, execution waits in the task node till tasks are created.|當(dāng)在這個(gè)的節(jié)點(diǎn)的入口沒有任務(wù)被創(chuàng)建,在任務(wù)節(jié)點(diǎn)中執(zhí)行等待直到這些任務(wù)被創(chuàng)建。|
last-wait: Proceeds execution when the last task instance is completed. When no tasks are created on entrance of this node, execution waits in the task node till tasks are created.
first: Proceeds execution when the first task instance is completed. When no tasks are created on entrance of this node, execution is continued.
first-wait: Proceeds execution when the first task instance is completed. When no tasks are created on entrance of this node, execution is continued.
unsynchronized: Execution always continues, regardless wether tasks are created or still unfinished.
never: Execution never continues, regardless wether tasks are created or still unfinished.
Task instance creation might be based upon a runtime calculation. In that case, add an ActionHandler on the node-enter event of the task-node and set the attribute create-tasks="false". Here is an example of such an action handler implementation:
public class CreateTasks implements ActionHandler {
public void execute(ExecutionContext executionContext) throws Exception {
Token token = executionContext.getToken();
TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();
TaskNode taskNode = (TaskNode) executionContext.getNode();
Task changeNappy = taskNode.getTask("change nappy");
// now, 2 task instances are created for the same task.
tmi.createTaskInstance(changeNappy, token);
tmi.createTaskInstance(changeNappy, token);
}
}
As shown in the example the tasks to be created can be specified in the task-node. They could also be specified in the process-definition and fetched from the TaskMgmtDefinition. TaskMgmtDefinition extends the ProcessDefinition with task management information.
The API method for marking task instances as completed is TaskInstance.end(). Optionally, you can specify a transition in the end method. In case the completion of this task instance triggers continuation of the execution, the task-node is left over the specified transition.