jBPM4.0的用戶指南(五-3)

[size=x-large] 續第5章JPDL
[/size]
[size=medium]5.2.4. concurrency併發
[/size]
使用fork和join活動,可以模擬流向(executions)的匯合。

例子:
流程處理的併發例子

圖 5.6. 流程處理的併發例子

<process name="ConcurrencyGraphBased" xmlns="http://jbpm.org/4/jpdl">
<start>
<transition to="fork" />
</start>

<fork name="fork">
<transition to="send invoice" />
<transition to="load truck" />
<transition to="print shipping documents" />
</fork>

<state name="send invoice">
<transition to="final join" />
</state>

<state name="load truck">
<transition to="shipping join" />
</state>

<state name="print shipping documents">
<transition to="shipping join" />
</state>

<join name="shipping join">
<transition to="drive truck to destiation" />
</join>

<state name="drive truck to destiation">
<transition to="final join" />
</state>

<join name="final join">
<transition to="end" />
</join>

<end name="end" />

</process>


[size=medium]5.2.5. end結束[/size]

結束流向[size=small]
5.2.5.1. end process instance結束流程處理實例[/size]

默認情況下,結束活動會終結已完成流程處理實例。因此在流程處理實例中,仍然在活動的多個併發(concurrent)流向(concurrent)也會結束。
結束活動

圖 5.7. 結束活動

<process name="EndProcessInstance" xmlns="http://jbpm.org/4/jpdl">
<start>
<transition to="end" />
</start>

<end name="end" />

</process>


新的流程處理實例一創建便會直接結束。
[size=small]5.2.5.2. end execution結束流向[/size]

只有流向到達結束(end)活動時會結束流程處理實例,並且其他併發流向會放棄活動。我們可以設置屬性ends="execution"來達到這種狀況。

[size=medium]表 5.8. end execution屬性[/size]
屬性 類型 默認值 是否必須 描述
ends {processinstance|execution} processinstance optional可選 流向路徑到達end活動整個流程處理實例就會結束,

[size=small]5.2.5.3. end multiple多個結束[/size]

一個流程處理可以有多個end events,這樣就很容易顯示出流程處理實例的不同結果。示例:
多個end events

圖 5.8. 多個end events

<prccess name="EndMultiple" xmlns="http://jbpm.org/4/jpdl">
<start>
<transition to="get return code" />
</start>

<state name="get return code">
<transition name="200" to="ok" />
<transition name="400" to="bad request" />
<transition name="500" to="internal server error" />
</state>

<end name="ok" />

<end name="bad request" />

<end name="internal server error" />

</process>


如果你啓動一個流向並使用下面的代碼將它執行到get return code等待狀態,流向便會以bad request的end 活動(event)結束

Execution execution = executionService.startProcessInstanceByKey("EndMultiple");
String executionId = execution.getId();
execution = executionService.signalExecutionById(executionId, "400");


同樣地,使用值爲200或者500就會讓流向(execution)分別以ok或者internal server error的end events結束。[size=small]
5.2.5.4. end State結束狀態[/size]

流向(execution)可以以不同的狀態結束。可以用其他的方式列出流程處理實例的結果。可以用end event的狀態屬性或者end-cancel和end-error表示。
[size=large]
表 5.9. end execution 屬性[/size]
屬性 類型 默認值 是否必須 描述
state String 可選 狀態分配給流向

不同的結束狀態

圖 5.9. 不同的結束狀態

<process name="EndState" xmlns="http://jbpm.org/4/jpdl">
<start>
<transition to="get return code" />
</start>

<state name="get return code">
<transition name="200" to="ok" />
<transition name="400" to="bad request" />
<transition name="500" to="internal server error" />
</state>

<end state="comleted" />
<end-cancel name="bad request" />
<end-error name="internal server error" />

</process>


這時,如果我們啓動一個流向並使用下面的代碼將流向執行到get return code等待狀態,流向會以取消狀態(cancel state)結束。

Execution execution = executionService.startProcessInstanceByKey("EndState");
String executionId = execution.getId();
execution = executionService.signalExecutionById(executionId, "400");


和上面一樣,使用值爲200或500會讓流向分別以comleted或者error states結束。
發佈了1 篇原創文章 · 獲贊 0 · 訪問量 2888
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章