`
cd826
  • 浏览: 129040 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

jBPM Developers Guide(jBPM开发指南)--Chapter 3. BPMN 2.0(第三部分)

    博客分类:
  • BPMN
阅读更多

3.8.5. Sequence Flow(顺序流)

    A sequence flow is the connection between events, activities and gateways shown as a solid line with an arrow in a BPMN diagram (JPDL equivalent is the transition). Each sequence flow has exactly one source and exactly one target reference, that contains the id of an activity, event or gateway.

 

    BPMN中顺序流显示为为一条带有箭头的实线,用来连接事件、活动和网关(在jPDL中等效的是transition)。每个顺序流都有且仅有一个源头和一个目标活动、事件或网关的引用。

<sequenceFlow id="myFlow" name="My Flow" 
        sourceRef="sourceId" targetRef="targetId" /> 
    An important difference with JPDL is the behaviour of multiple outgoing sequence flows. In JPDL, only one transition is selected as outgoing transition, unless the activity is a fork (or a custom activity with fork behaviour). However, in BPMN, the standard behaviour of multiple outgoing sequence flow is to split the incoming token ('execution' in jBPM terminology) into a collection of tokens, one for each outgoing sequence flow. In the following situation, after completing the first task, there will be three tasks activated instead of one.

 

    与jPDL的一个重要区别是在有多个外出顺序流时。在jPDL中,只有一个转移会成为外向转移,除非活动是fork(或自定义活动拥有fork行为)。然而,在BPMN中,多个外出顺序流的默认行为是将进入的tokenjBPM中术语叫做execution)切分成token集合,每个顺序流一个。在下面示例中,当完成第一个任务后就会激活三个任务。


    To avoid that a certain sequence flow is taken, one has to add a condition to the sequence flow. At runtime, only when the condition evaluates to true, that sequence flow will be taken.

 

    为了避免使用一个顺序流,必须添加condition条件到顺序流中。在运行时,只有当condition条件结果为true,顺序流才会被执行。

 

    To put a condition on a sequence flow, add a conditionExpression element to the sequence flow. Conditions are to be put between ${}.

 

    可以使用conditionExpression元素给顺序流添加condition条件。条件必须放在 ${}中。 

<sequenceFlow id=....>
  <conditionExpression xsi:type="tFormalExpression">${amount >=500}
</conditionExpression>   
</sequenceFlow> 
    Note that is currently is necessary to add the xsi:type="tFormalExpression" to theconditionExpression. This can change in a future release.

 

    注意,当前必须把 xsi:type="tFormalExpression"添加到 conditionExpression中。在未来的版本中可能会修改。

 

    Activities (such as the user task) and gateways (such as the exclusive gateway) can have a default sequence flow. This default sequence flow is taken only when all the other outgoing sequence flow from an activity or gateway have a condition that evaluate to false. A default sequence flow is graphically visualized as a sequence flow with a 'slash marker'.

 

    活动(比如用户任务)和网关(比如唯一网关)可以设置默认顺序流。默认顺序流只会在活动或网关的所有其他外向顺序流的condition条件为false时才会被使用。 默认顺序流图形像是顺序流多了一个斜线标记。


    The default sequence flow is specified by filling in the 'default' attribute of the activity or gateway.

 

    默认顺序流通过活动或网关的 'default' 属性 来指定。

 

    Also note that an expression on a default sequence flow is ignored.

 

    也要注意,默认顺序流上的表达式将会被忽略。

 

3.8.6. Gateways(网关)

    A gateway in BPMN is used to control the flow through the process. More specifically, when a token (the BPMN 2.0 conceptual notion of an execution) arrives in a gateway, it can be merged or split depending on the gateway type.

 

    BPMN中网关是用来控制流程中的流向的。更确切的说,当一个tokenBPMN 2.0execution的概念注解)到达一个网关,它会根据网关的类型进行合并或切分。

 

    Gateways are depicted as a diamond shape, with an icon inside specifying the type (exclusive, inclusive, etc.).

 

    网关使用菱形来表示,内部内部的图标则用来表示网关的类型 (唯一,广泛,其他)。

 

    On every gateway type, the attribute gatewayDirection can be set following values are possible:

 

    作为一个网关,属性gatewayDirection属性可以设置为以下值

  • unspecificed (default): the gateway may have multiple incoming and multiple sequence flow.
  • unspecificed (默认)网关可能拥有多个进入和多个顺序流。
  • mixed: the gateway must have multiple incoming and multiple outgoing sequence flow.
  • mixed网关必须拥有多个进入和外出顺序流。
  • converging: the gateway must have multiple incoming sequence flow, but can have only one outgoing sequence flow.
  • converging网关必须拥有多个进入顺序流, 但是只能有一个外出顺序流。
  • diverging: the gateway must have only one incoming sequence flow and multiple outgoing sequence flow.
  • diverging网关必须拥有一个进入顺序流,和多个外出顺序流。

        Take for example the following example: a parallel gateway that has as gatewayDirection 'converging', will have a join behaviour.

     

        比如下面的例子:当并行网关的gatewayDirection属性设置为'converging' 会拥有流程合并行为。 

    <parallelGateway id="myJoin" name="My synchronizing join" gatewayDirection="converging" /> 

     

        Note: the 'gatewayDirection' attribute is optional according to the specification. This means that we cannot rely on this attribute at runtime to know which type of behaviour a certain gateway has (for example for a parallel gateway if we have joining of forking behaviour). However, the 'gatewayDirection' attribute is used at parsing time as a constraint check for the incoming/outgoing sequence flow. So using this attribute will lower the chance on errors when referencing sequence flow, but is not required.

     

        注意gatewayDirection属性在规范中是可选的。这意味着我们不能通过该属性在运行时知道一个网关的行为(比如,一个用来进行合并切分行为的并行网关)。然而,gatewayDirection属性用在解析进入、外出顺序流的一个约束条件。所以在涉及到顺序流时可以使用该属性减低出错的机会,但不是必须的。


    3.8.7. Gateway: Exclusive Gateway(网关:唯一网关)

     

        An exclusive gateway represents an exclusive decision in the process. Exactly one outgoing sequence flow will be taken, depending on the conditions defined on the sequence flow.

     

        唯一网关表达了流程中的唯一决策。网关会根据定义在顺序流中的条件选择一个外出顺序流。

     

        The corresponding JPDL construct with the same semantics is the decision activity. The full technical name of the exclusive gateway is the 'exclusive data-based gateway', but it is also often called theXOR Gateway. The XOR gateway is depicted as a diamond with a 'X' icon inside. An empty diamond without a gateway also signifies an exclusive gateway.

     

        在jPDL中相应功能的是 decision活动。唯一网关的全称是'基于数据的唯一网关',也经常称之为XOR网关XOR网关被描绘为一个菱形,内部有一个'X'。空的菱形网关也表示唯一网关。

     

        The following diagram shows the usage of an exclusive gateway: depending on the value of the amount variable, one of the three outgoing sequence flow out of the exclusive gateway is chosen.

     

        下面图形显示了唯一网关的用法:根据amount变量的值,会选择三个外出顺序流中的一个。



        The corresponding executable XML of this process looks as follows. Note that the conditions are defined on the sequence flow. The exclusive gateway will select the single sequence flow for which its condition evaluates to true. If multiple conditions evaluate to true, the first one encountered will be taken (a log message will indicate this situation).

     

        这个流程对应的可执行XML如下。注意定义在顺序流中的条件。唯一网关会选择一个条件为真的顺序流。如果多个条件为真,则选择第一个 (日志中则会输出相应的信息)。

    <process id="exclusiveGateway" name="BPMN2 Example exclusive gateway">
    
        <startEvent id="start" />
    
       <sequenceFlow id="flow1" name="fromStartToExclusiveGateway"
          sourceRef="start" targetRef="decideBasedOnAmountGateway" />
          
       <exclusiveGateway id="decideBasedOnAmountGateway" name="decideBasedOnAmount" />
       
       <sequenceFlow id="flow2" name="fromGatewayToEndNotEnough"
          sourceRef="decideBasedOnAmountGateway" targetRef="endNotEnough">
          <conditionExpression xsi:type="tFormalExpression">
            ${amount < 100}
          </conditionExpression>
       </sequenceFlow>
          
       <sequenceFlow id="flow3" name="fromGatewayToEnEnough"
          sourceRef="decideBasedOnAmountGateway" targetRef="endEnough">
          <conditionExpression xsi:type="tFormalExpression">
            ${amount <= 500 && amount >= 100}
            </conditionExpression>
       </sequenceFlow>
          
       <sequenceFlow id="flow4" name="fromGatewayToMoreThanEnough"
          sourceRef="decideBasedOnAmountGateway" targetRef="endMoreThanEnough">
          <conditionExpression xsi:type="tFormalExpression">
            ${amount > 500}
          </conditionExpression>
       </sequenceFlow>   
    
       <endEvent id="endNotEnough" name="not enough" />
       
       <endEvent id="endEnough" name="enough" />
       
       <endEvent id="endMoreThanEnough" name="more than enough" />
    
      </process>      
    
        This process needs a variable such that the expression can be evaluated at runtime. Variables can be provided when starting the process instance (similar to JPDL):

     

        这个流程需要一个变量,这样表达式就可以在运行期间进行求值。变量可以在流程实例启动时提供(类似jPDL)。

     Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("amount", amount);
    ProcessInstance processInstance = executionService.startProcessInstanceByKey("exclusiveGateway", vars); 

        The exclusive gateway requires that all outgoing sequence flow have conditions defined on them. An exception to this rule is the default sequence flow. Use the default attribute to reference an existing id of a sequence flow. This sequence flow will be taken when the conditions on the other outgoing sequence flow all evaluate to false.

     

        唯一网关需要所有外出顺序流上定义条件。对这种规则一种例外是默认顺序流。使用default 属性来引用一个已存在的 顺序流的id。当其他顺序流的条件被评估为false的时候这个顺序流就会被使用。

    <exclusiveGateway id="decision" name="decideBasedOnAmountAndBankType" default="myFlow"/>
       
    <sequenceFlow id="myFlow" name="fromGatewayToStandard"
        sourceRef="decision" targetRef="standard">
    </sequenceFlow> 
     

     

    3.8.8. Gateway: parallel Gateway( 网关:并行网关)

        A parallel gateway is used to split or synchronize the respectively incoming or outgoing sequence flow.

     

        并行网关用来切分或同步相关的进入或外出顺序流。

    • A parallel gateway with one incoming sequence flow and more than one outgoing sequence flow is called a 'parallel split or an 'AND-split'. All outgoing sequence flow are going to be taken in parallel. Note: as defined by the specification, conditions on the outgoing sequence flow are ignored.
    • 并行网关拥有一个进入顺序流和多于一个的外出顺序流叫做'并行切分' 'AND-split'。所有外出顺序流都会被执行。注意:正如规范中所定义的,外出顺序流中的条件都会被忽略。
    • A parallel gateway with multiple incoming sequence flow and one outgoing sequence flow is called a'parallel join' or an AND-join. All incoming sequence flow need to arrive in this parallel joing before the outgoing sequence flow is taken.
    • 并行网关拥有多个进入顺序流和一个外出顺序流的叫做'并行归并''AND-join'。只有当所有进入顺序流的全部到达后,外出顺序流才会被执行。

          A parallel gateway is defined as follows:

       

          并行网关定义如下:

      <parallelGateway id="myParallelGateway" name="My Parallel Gateway" /> 
          Note that the 'gatewayDirection' attribute can be used to catch modeling errors at parsing time (see above).

       

          注意,gatewayDirection属性可以用来在解析阶段获取建模的错误(具体可参考上面)。

       

          The following diagram shows how a parallel gateway can be used. After process start, both the 'prepare shipment' and 'bill customer' user tasks will be active. The parallel gateway is depicted as a diamond shape with a plus icon inside, both for the splitting and joining behaviour.

       

          下面的图形显示了一个并行网关的使用。在流程启动后,'prepare shipment''bill customer'用户任务都会被激活。并行网关被描绘为一个菱形,内部图标是一个十字,对切分和归并行为都是一样。


          The XML counterpart of this diagram looks as follows:

       

          对应的XML如下所示:

      <process id="parallelGateway" name="BPMN2 example parallel gatewar">
        
          <startEvent id="Start" />
      
          <sequenceFlow id="flow1" name="fromStartToSplit"
            sourceRef="Start"
            targetRef="parallelGatewaySplit"  />
      
          <parallelGateway id="parallelGatewaySplit" name="Split" 
            gatewayDirection="diverging"/>
      
          <sequenceFlow id="flow2a" name="Leg 1"
            sourceRef="parallelGatewaySplit"
            targetRef="prepareShipment" />
            
          <userTask id="prepareShipment" name="Prepare shipment" 
            implementation="other" />
          
          <sequenceFlow id="flow2b" name="fromPrepareShipmentToJoin"
            sourceRef="prepareShipment"
            targetRef="parallelGatewayJoin"  />
            
          <sequenceFlow id="flow3a" name="Leg 2" 
            sourceRef="parallelGatewaySplit"
            targetRef="billCustomer" />
            
          <userTask id="billCustomer" name="Bill customer" 
            implementation="other" />
          
          <sequenceFlow id="flow3b" name="fromLeg2ToJoin"
            sourceRef="billCustomer"
            targetRef="parallelGatewayJoin"  />
      
          <parallelGateway id="parallelGatewayJoin" name="Join" 
            gatewayDirection="converging"/>
            
          <sequenceFlow id="flow4" 
            sourceRef="parallelGatewayJoin"
            targetRef="End">
          </sequenceFlow>
      
          <endEvent id="End" name="End" />
          
        </process> 

       

      • 大小: 7.8 KB
      • 大小: 1.2 KB
      • 大小: 12.2 KB
      • 大小: 14.3 KB
      0
      0
      分享到:
      评论

      相关推荐

      Global site tag (gtag.js) - Google Analytics