Process Tasks-service tasks (Java service Task)

Source: Internet
Author: User
Tags vars

Service tasks are used to request out-of-process tasks or automate tasks, with 3 implementations: Java service Task/web Service/task and Shelltask,

When the process arrives at the task, the corresponding Java class or WebService or shell command is executed.

1.Java Service Task

1.1 Specifies the Java class using Activiti:class, which must be implemented javadelegate,activiti each time a new instance is created.

 Public class Implements javadelegate{    publicvoidthrows  Exception {        System.out.println ( "Implement  javadelegate this  );    }}

Process file Full name limit Delete class

<id= "Servicetask1"  name= "Service Task 1"    <!-- Myjavadelegate must be Javadelegate implementation class-->    activiti:class= " Org.crazyit.activiti.MyJavaDelegate "></servicetask>

1.2 Specifies the Java class using DelegateExpression, which must implement Javadelegate and serializable

A. Creating a Java service task class

 Public class Implements Javadelegate, Serializable {    publicvoidthrows  Exception {        System.out.println ("implement  javadelegate this  );    }}

B. Process file Juel expression

<id= "Servicetask1"  name= "Service Task"    Activiti: DelegateExpression= "${mydelegate}"></servicetask> 

C. The creation of the instance is provided by the provider, and the instance is set to the process parameters:

// Deployment Process Files    
Repositoryservice.createdeployment (). Addclasspathresource ("BPMN/JUELCLASS.BPMN"). deploy (); New Hashmap<string, object>(); Vars.put (new myjavadelegate ()); // START Process ProcessInstance pi = Runtimeservice.startprocessinstancebykey ("Process1", VARs);

1.3 Calling a normal Java bean using activiti:expression

A. Creating a Java bean

 Public class Implements Serializable {        public  String getName () {        return "Bestmyself"    }      Public void print (execution exe) {        System.out.println ("Print method using Java Bean:" + Exe.getid ());}    }

B. Process files combined with Juel call object methods

<ServicetaskID= "Servicetask1"name= "Service Task"<!--Execute the Mybean Print method-->activiti:expression= "${mybean.print (Execution)}" ></Servicetask>    <ServicetaskID= "Servicetask2"name= "Service Task"<!--execution Mybean.getname () method-->activiti:expression= "${execution.setvariable (' MyName ', Mybean.name)}" ></Servicetask>

C. Setting up Java bean instances into the process

  

    New Hashmap<string, object>();    Vars.put (new  Myjavabean ());     // START Process    ProcessInstance pi = Runtimeservice.startprocessinstancebykey ("Process1", VARs);     // Query for Task parameters    System.out.println (  runtimeservice.getvariable (Pi.getid (), "MyName"));

Process Tasks-service tasks (Java service Task)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.