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

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

    博客分类:
  • BPMN
阅读更多

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之外,还允许指定 scriptLanguagescript。因为我们使用了JSR-223java平台的脚本语言),修改脚本语言就需要:

  • 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对应图形如下所示(添加了空开始和结束事件)。


        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(任务:手工任务)

     

        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图形一样) 在左上角有一个小信封的图标。


        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除了idname(可选)属性外,没有其他属性,其行为就像是一个等待状态。为了在你的业务流程中使用等待状态,只需要加入如下几行:

    <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()); 
    
    • 大小: 6.1 KB
    • 大小: 3.4 KB
    • 大小: 5.4 KB
    0
    0
    分享到:
    评论

    相关推荐

    Global site tag (gtag.js) - Google Analytics