天天看點

jBPM Developers Guide(jBPM開發指南)--Chapter 3. BPMN 2.0(第五部分)

3.8.12. Task: Script Task(腳本任務)

    A script task is a an automatic activity upon which the process engine will execute a script when the task is reached. The script task is used as follows:

    腳本任務時一個自動活動,當任務到達的時候 流程引擎會執行一個腳本。腳本任務使用方式如下:

<scriptTask id="scriptTask" name="Script Task" scriptLanguage="bsh">
  <script><![CDATA[
    for(int i=0; i < input.length; i++){
      System.out.println(input[i] + " x 2 = " + (input[i]*2));
    }]]>
  </script>
</scriptTask> 
      

    The script task, besides the required id and the optional name, allows for specifying a scriptLanguage and a script. Since we're using JSR-223 ('Scripting for the Java platform'), changing the script language involves

    腳本任務,除了必須的id和可選的 name之外,還允許指定 scriptLanguage和script。因為我們使用了JSR-223(java平台的腳本語言),修改腳本語言就需要:

  • changing the scriptLanguage attribute to the JSR-223 compliant name
  • 把scriptLanguage 屬性修改為JSR-223相容的名稱
  • adding the ScriptEngine implementation of the JSR specification to the classpath
  • 在classpath下添加JSR規範的ScriptEngine實作

    The XML above is visualized as follows (adding a none start and end event).

    上面的XML對應圖形如下所示(添加了空開始和結束事件)。

jBPM Developers Guide(jBPM開發指南)--Chapter 3. BPMN 2.0(第五部分)

    As shown in the example, process variables can be used inside the scripts. We can now start a process instance for this example process, while also supplying some random input variables:

    像上面例子中顯示的那樣,可以在腳本中使用流程變量。我們現在可以啟動一個這個例子的流程,同時提供一些随機生成的輸入變量:

Map<String, Object> variables = new HashMap<String, Object>();
Integer[] values = { 11, 23, 56, 980, 67543, 8762524 };
variables.put("input", values);   
executionService.startProcessInstanceBykey("scriptTaskExample", variables); 
           

     In the output console, we can now see the script being executed:

    在輸出控制台裡,我們現在可以看到腳本的執行:

11 x 2 = 22
23 x 2 = 46
56 x 2 = 112
980 x 2 = 1960
67543 x 2 = 135086
8762524 x 2 = 17525048
           

3.8.13. Task: Manual task(任務:手工任務)

jBPM Developers Guide(jBPM開發指南)--Chapter 3. BPMN 2.0(第五部分)

    A manual task is a task that is performed by an external actor, but without the aid of a BPM system or a service that is invoked. In the real world, examples are plenty: the installation of telephone system, sending of a letter using regular mail, calling a customer by phone, etc.

    手工任務時一個由外部人員執行的任務,但是它的執行沒有BPM系統或服務幫助。在真實世界裡,有很多這樣的例子,如安裝一個電話系統、使用定期郵件發送一封信、用電話聯系客戶,等等。

<manualTask id="myManualTask" name="Call customer" />      

     The purpose of the manual task is more documentation/modeling-wise, as it has no meaning for execution on a process engine. As such, the process engine will simply pass through a manual task when it encounters one.

    手工任務的目的更像是為了文檔或模組化提醒,因為它對流程引擎的運作沒有任何意義。是以,當流程引擎遇到一個手工任務時會簡單略過。

3.8.14. Task: Java Receive task(Java Receive任務)

    A receive task is a task that waits for the arrival of an external message. Besides the obvious use case involving webservices, the specification is liberal in what to do in other environments. The web service use case is not yet implemented, but the receive task can already be used in a Java environment.

    receive task是一個任務會等到外部消息的到來。除了廣泛使用的web service用例,規範在其他環境中的使用也是一樣的。 web service用例還沒有實作, 但是receive task已經可以在java環境中使用了。

    The receive task is depicted as a rounded rectangle (= task shape) with a little enveloppe in the left top corner.

    receive task顯示為一個圓角矩形(和task圖形一樣) 在左上角有一個小信封的圖示。

jBPM Developers Guide(jBPM開發指南)--Chapter 3. BPMN 2.0(第五部分)

    In a Java environment, the receive task without any other attribute filled in besides an id and (optionally) a name, behaves as a wait state. To introduce a wait state in your business process, just add the following line:

    在java環境中,receive task除了id和name(可選)屬性外,沒有其他屬性,其行為就像是一個等待狀态。為了在你的業務流程中使用等待狀态,隻需要加入如下幾行:

<receiveTask id="receiveTask" name="wait" />      

    Process execution will wait in such a receive task. The process can then be continued using the familiar jBPM signal methods. Note that this will probably change in the future, since a 'signal' has a completely different meaning in BPMN 2.0.

    流程執行當遇到一個receive task是将會進入等待狀态。流程可以使用我們熟悉的jBPM signal 方法來繼續執行。注意,這些可能在未來改變,因為'signal'在BPMN 2.0中擁有完全不同的含義。

Execution execution = processInstance.findActiveExecutionIn("receiveTask");
executionService.signalExecutionById(execution.getId());