Oracle神谕

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  219 随笔 :: 7 文章 :: 94 评论 :: 0 Trackbacks

2005年6月15日 #

9.4. Swimlanes(咏道)
A swimlane is a process role(角色). It is a mechanism to specify that multiple tasks in the process should be done by the same actor.(多个任务被同一个用户执行) So after the first task instance is created for a given swimlane, the actor should be remembered in the process for all subsequent(后来的) tasks that are in the same swimlane. A swimlane therefore has one assignment and all tasks that reference a swimlane should not specify an assignment.

When the first task in a given swimlane is created, the AssignmentHandler of the swimlane is called. The Assignable that is passed to the AssignmentHandler will be the SwimlaneInstance. Important to know is that all assignments that are done on the task instances in a given swimlane will propagate to the swimlane instance. This behaviour is implemented as the default because the person that takes a task to fulfilling(实行) a certain process role will have the knowledge of that perticular process. So all subsequent(并发的) assignements of task instances to that swimlane are done automatically to that user.

Swimlane is a terminology(术语) borrowed from UML activity(活动) diagrams.

------------------------------------------------------------
9.5. Task events (任务事件)
Tasks can have actions associated with them. There are 4 standard event types defined for tasks: task-create, task-assign, task-start and task-end.

(1)task-create
 is fired when a task instance is created.

(2)task-assign
is fired when a task instance is being assigned. Note that in actions that are executed on this event, you can access the previous actor with executionContext.getTaskInstance().getPreviousActorId();
executionContext.getTaskInstance().getPreviousActorId();

(3)task-start
is fired when TaskInstance.start() is called. This can be used to indicate(指示) that the user is actually starting to work on this task instance. Starting a task is optional.

(4)task-end
 is fired when TaskInstance.end(...) is called. This marks the completion of the task. If the task is related to a process execution, this call might trigger the resuming(恢复) of the process execution.

Since tasks can have events and actions associated with them, also exception handlers can be specified on a task. For more information about exception handling, see Section 7.5, “Exception handling”.

---------------------------------------------------------------
9.6. Task timers(任务定时器)
As on nodes, timers can be specified(指定) on tasks. See Section 10.1, “Timers”.

The special(特别的) thing about timers for tasks is that the cancel-event for task timers can be customized(取消事件可以被定制). By default, a timer on a task will be cancelled when the task is ended (=completed). But with the cancel-event attribute on the timer, process developers can customize that to e.g. task-assign or task-start. The cancel-event supports multiple events.|取消事件支持多种事件| The cancel-event types can be combined by specifying them in a comma(逗号) separated list in the attribute.

9.7. Customizing task instances(定制任务实例)
Task instances can be customized. The easiest way to do this is to create a subclass of TaskInstance.|创建一个任务实例的子类| Then update the property jbpm.task.instance.class and specify the class name of your custom class that inherits from TaskInstance. Also create a hibernate mapping file for the subclass (using the hibernate extends="org.jbpm.taskmgmt.exe.TaskInstance"). Then add that mapping file to the list of mapping files in the hibernate.cfg.xml
(1)更新jbpm.task.instance.class 的属性
(2)指定继承TaskInstance的定制类
(3)创建一个子类的影射文件(使用 extends="org.jbpm.taskmgmt.exe.TaskInstance")
(4)将这个影射文件加到 hibernate.cfg.xml

9.8. The identity component(身份组件)
Management of users, groups and permissions is commonly known as identity management. jBPM includes an optional identity component that can be easily replaced by a company's own identity data store.

The jBPM identity management component includes knowledge of the organisational model. Task assignment is typically done with organisational knowledge. So this implies knowledge of an organisational model, describing the users, groups, systems and the relations between them. Optionally, permissions and roles can be included too in an organisational model. Various academic(理论的) research attempts failed, proving that no generic organisational model can be created that fits every organisation.

The way jBPM handles this is by defining an actor as an actual participant(参与者) in a process. An actor is identified by its ID called an actorId. jBPM has only knowledge(知道) about actorId's and they are represented as java.lang.Strings for maximum flexibility. So any knowledge about the organisational model and the structure of that data is outside the scope of the jBPM core engine.

As an extension to jBPM we will provide (in the future) a component to manage that simple user-roles model. This many to many relation between users and roles is the same model as is defined in the J2EE and the servlet specs and it could serve as a starting point in new developments. People interested in contributing should check the jboss jbpm jira issue tracker for more details. 用户和角色 (user-roles 模型)


Note that the user-roles model as it is used in the servlet, ejb and portlet specifications, is not sufficiently powerful for handling task assignments. That model is a many-to-many relation between users and roles. This doesn't include information about the teams and the organisational structure of users involved in a process.


The classes in yellow are the relevant(相关的) classes for the expression assignment handler that is discussed next.

A User represents a user or a service.|一个用户表现为一个用户或一个服务。| A Group is any kind of group of users.|一个组是任何种类用户组。| Groups can be nested to model the relation between a team, a business unit and the whole company.|组可以被内嵌到在团队、商业单元和整个公司的关系模型。 | Groups have a type to differentiate between the hierarchical groups and e.g. haircolor groups.|组可以有一个种类来区分分等级的组和haircolor组。| Memberships represent the many-to-many relation between users and groups. A membership can be used to represent a position in a company.|一个membership可以被用来表现在公司中的位置。| The name of the membership can be used to indicate(指出) the role that the user fullfills in the group.

9.8.2. Assignment expressions (分派表达式)
The identity component comes with one implementation that evaluates an expression for the calculation of actors during assignment of tasks. Here's an example of using the assignment expression in a process definition:

<process-definition>
  ...
  <task-node name='a'>
    <task name='laundry'>
      <assignment expression='previous --> group(hierarchy) --> member(boss)' />
    </task>
    <transition to='b' />
  </task-node>
  ...
Syntax of the assignment expression is like this:

first-term --> next-term --> next-term --> ... --> next-term

where

first-term ::= previous |
               swimlane(swimlane-name) |
               variable(variable-name) |
               user(user-name) |
               group(group-name)

and

next-term ::= group(group-type) |
              member(role-name)

9.8.2.1. First terms
An expression is resolved(分解) from left to right.|一个表达式被从左到右进行分解| The first-term specifies a User or Group in the identity model.|第一个项目是在身份模型中指定了一个用户或组| Subsequent terms calculate the next term from the intermediate(中间的) user or group.

previous means the task is assigned to the current authenticated actor. This means the actor that performed the previous step in the process.

swimlane(swimlane-name) means the user or group is taken from the specified swimlane instance.

variable(variable-name) means the user or group is taken from the specified variable instance. The variable instance can contain a java.lang.String, in which case that user or group is fetched from the identity component. Or the variable instance contains a User or Group object.

user(user-name) means the given user is taken from the identity component.

group(group-name) means the given group is taken from the identity component.

9.8.2.2. Next terms
group(group-type) gets the group for a user. Meaning that previous terms must have resulted in a User. It searches for the the group with the given group-type in all the memberships for the user.

member(role-name) gets the user that performs a given role for a group. The previous terms must have resulted in a Group. This term searches for the user with a membership to the group for which the name of the membership matches the given role-name.

9.8.3. Removing the identity component
When you want to use your own datasource for organisational information such as your company's user database or ldap system, you can just rip out the jBPM identity component. The only thing you need to do is make sure that you delete the line ...

<mapping resource="org/jbpm/identity/hibernate/identitymappings.hbm.xml"/>
from the hibernate.cfg.xml

The ExpressionAssignmentHandler is dependent on the identity component so you will not be able to use it as is. In case you want to reuse the ExpressionAssignmentHandler and bind it to your user data store, you can extend from the ExpressionAssignmentHandler and override the method getExpressionSession.

protected ExpressionSession getExpressionSession(AssignmentContext assignmentContext);

posted @ 2005-06-15 13:42 java世界畅谈 阅读(520) | 评论 (0)编辑 收藏

Assignment(分派)
A process definition contains can have task nodes. A task-node contains zero or more tasks. Tasks are a static description as part of the process definition. At runtime, tasks result(起源于) in the creation of task instances. A task instance corresponds to(相应) one entry in a person's task list.
tasknodes-->>task-node--->>tasks 

With jBPM, push and pull model (see below) of task assignment can be applied in combination. The process can calculate(考虑) the responsible for a task and push it in his/her tasklist. Or alternatively(作为选择), a task can be assigned to a pool of actors, in which case each of the actors in the pool can pull the task and put it in the actor's personal tasklist.  {这里提到了一个行为池的概念 pool of actors}

9.3.1. Assignment interfaces
Assigning task instances is done via the interface AssignmentHandler: {任务实例分派是依靠AssignmentHandler来实现的}

public interface AssignmentHandler extends Serializable {
  void assign( Assignable assignable, ExecutionContext executionContext );
}
An assignment handler implementation is called when a task instance is created. At that time, the task instance can be assigned to one or more actors. The AssignmentHandler implementation should call the Assignable methods (setActorId or setPooledActors) to assign a task. The Assignable is either a TaskInstance or a SwimlaneInstance (=process role).

Assignable 流程角色:TaskInstance  SwimlaneInstance

public interface Assignable {
  public void setActorId(String actorId);
  public void setPooledActors(String[] pooledActors);
}

Both TaskInstances and SwimlaneInstances can be assigned to a specific user or to a pool of actors. To assign a TaskInstance to a user, call Assignable.setActorId(String actorId). To assign a TaskInstance to a pool of candidate(侯选) actors, call Assignable.setPooledActors(String[] actorIds).

分配对象:
分配给一个用户       Assignable.setActorId(String actorId);
分配给一个侯选用户池 Assignable.setPooledActors(String[] actorIds);

Each task in the process definition can be associated with an assignment handler implementation to perform the assignment at runtime.


When more then one task in a process should be assigned to the same person or group of actors, consider the usage of a swimlane

在一个流程当多于一个任务时应当被分派给一个用户或多用户的组,考虑使用泳道。

To allow for the creation of reusable AssignmentHandlers, each usage of an AssignmentHandler can be configured in the processdefinition.xml. See Section 13.2, “Delegation(委托)” for more information on how to add configuration to assignment handlers.

9.3.2. The assignment data model
The datamodel for managing assignments of task instances and swimlane instances to actors is the following. Each TaskInstance has an actorId and a set of pooled actors.

The actorId is the responsible for the task, while the set of pooled actors represents a collection of candidates that can become responsible if they would take the task. Both actorId and pooledActors are optional and can also be combined.


Pull model(拉模式)
On the other hand, the tasks of pooled tasks for a given user are the tasks for which the given user is referenced in the pooled actors.
Fetching the list of pooled tasks is typically a two step operation :
1) get all the groups for the given user from the identity component. and
2) get the list of all pooled tasks for the combined set of the user's actorId and the actorId's that reference the users' groups.
 Getting the list of pooled tasks that are offered to a given user can be done with the methods TaskMgmtSession.findPooledTaskInstances(String actorId) or TaskMgmtSession.findPooledTaskInstances(List actorIds). These methods will only return task instances for which the actorId is null and one of the given actorIds matches one of the pooled actors.

TaskMgmtSession.findPooledTaskInstance(String actorId)
TaskMgmtSession.findPooledTaskInstance(List actorIds)

To prevent multiple users working on the same pooled task, it is sufficient to update the actorId of the TaskInstance with the user's actorId. After that, the task instance will not appear in the list of pooled tasks, but only in the user's personal task list. Setting the actorId of a taskInstance to null will put the task instance back in the pooled tasks.

posted @ 2005-06-15 11:18 java世界畅谈 阅读(679) | 评论 (0)编辑 收藏

9.2. Task instances|任务实例|
A task instance can be assigned to an actorId (java.lang.String).|任务实例被分派给一个行为ID。| All task instances are stored in one table of the database (JBPM_TASKINSTANCE).|所有的实例都被存储在数据库的一个表格里(JBPM_TASKINSTANCE)。| By querying this table for all task instances for a given actorId, you get the task list for that perticular user. |通过查询这个行为ID表的所有任务实例的表,你得到指定用户的任务列表。|

The jBPM task list mechanism can combine jBPM tasks with other tasks, even when those tasks are unrelated to a process execution.|jBPM任务列表机制可以与其它任务结合jBPM任务,甚至当这些任务与一个流程执行无关。| That way jBPM developers can easily combine jBPM-process-tasks with tasks of other applications in one centralized task-list-repository.|那种方法jBPM开发人员可以和容易的使jBPM流程任务在一个集中的任务列表库与其他程序中的任务|

9.2.1. Task instance life cycle |任务实例生命周期|
The task instance lifecycle is straightforward: After creation, task instances can optionally be started.|任务生命周期是 简单的:在创建之后,任务实例可以随意地被开始。| Then, task instances can be ended, which means that the task instance is marked as completed.|接着,任务实例可能被结束,它意味着任务实例已经被标志已完成。|

Note that for flexibility, assignment is not part of the life cycle.|注意适应性、委派不是生命周期的一部分。| So task instances can be assigned or not assigned.|所有任务实例可能被委派也可能不被委派。| Task instance assignment does not have an influence on the task instance life cycle.|任务实例委派不影响任务实例的生命周期。|

Task instances are typically created by the process execution entering a task-node (with the method TaskMgmtInstance.createTaskInstance(...)).|任务实例被进入一个任务节点流程执行代典型的创建(使用TaskMgmtInstance.createInstance(...)方法)| Then, a user interface component will query the database for the tasklists using the TaskMgmtSession.findTaskInstancesByActorId(...).|接着一个用户接口组件将要为任务列表查询数据库使用TaskMgmtSession.findTaskInstancesByActorId(...)| Then, after collecting input from the user, the UI component calls TaskInstance.assign(String), TaskInstance.start() or TaskInstance.end(...).|接着,在收集从用户收入之后,这个UI组件调用TaskIntsance.assign(String),TaskInstance.start() 或者 TaskInstance.end(...)。|

A task instance maintains it's state by means of date-properties : create, start and end.|一个任务实例依靠日期属性维护它的状态:创建、开始、结束。| Those properties can be accessed by their respective getters on the TaskInstance.|这些属性可以通过它们的各自在任务实例上的的getters被访问。|

Currently, completed task instances are marked with an end date so that they are not fetched with subsequent queries for tasks lists.|通常地,完成的任务实例被标志为结束状态,所以他们并不通过对任务列表的子查询获得。| But they remain in the JBPM_TASKINSTANCE table.|但是他们仍然保持在JBPM_TASKINGSTANCE表中。|

9.2.2. Task instances and graph execution|任务实例和图表执行|
Task instances are the items in an actor's tasklist.|任务实例是在行动者的任务列表中的项目。| Task instances can be signalling.|任务实例可以被发信号的| A signalling task instance is a task instance that, when completed, can send a signal to its token to continue the process execution.|一个发信号的任务实例是一个这样的任务实例,当被完成时候,可以发送一个信号给它的令牌以继续流程的执行。| 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.|任务实例可以被模块化,意味着有关系的令牌(执行路径)在任务实例完成之前允许离开任务节点。| By default task instances are signalling and non-blocking. |缺省的任务实例是被信号化且非模块化的。|

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.|万一超过一个的任务实例与一个任务节点关联,这个流程开发者可以定义 任务实例的完成如何影响流程的继续。| Following is the list of values that can be given to the signal-property of a task-node.|接下来是值的列表可以指定给节点的信号属性。|

last: This is the default.|最后:这是缺省的。| 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.|当在这个的节点的入口没有任务被创建,在任务节点中执行等待直到这些任务被创建。|
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.

posted @ 2005-06-15 10:33 java世界畅谈 阅读(448) | 评论 (0)编辑 收藏