In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you what is the knowledge analysis about Activiti. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1. Query API createXxxQuery
The Xxx in the query interface is the query method for various objects, such as the method defined by createProcessDefinitionQuery for the query process. The final call to the query has the following common methods:
Asc: ascending order, used with list
Desc: in reverse order, used with list
Count: return count
List: returns a list
ListPage: returns the paged list
SingleResult: returns a single object
Different query interfaces need to call different service components, such as repositoryService to provide process definition-related queries; identityService service components to provide users, user group-related queries; runtimeService to provide process instance-related queries.
① regular query: the following query declares a process definition processDefinition to accept the single object returned by the query. The process definition needs to call createProcessDefinition in the repositoryService service component to obtain a single entity defined by the process according to the deployed id.
ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery (). DeploymentId (deployment.getId (). SingleResult ()
② custom sql query: you can use custom sql to query data based on database fields:
List groups=identityService.createNativeGroupQuery (). Sql ("SELECT * FROM ACT_ID_GROUP where NAME=# {name}"). Parameter ("name", "group2"); 2. Process file deployment
Process definition deployment uses the DeploymenBuilder object, which provides the following methods to implement process deployment:
AddClasspathResource
AddInputStream
AddString
AddZipInputStream
AddBpmnModel
AddBytes
Deploy
For example, we normally deploy a process definition defined in a bpmn file using the following code:
DeploymentBuilder builder=repositoryService.createDeployment (); builder.addClasspathResource ("test1.bpmn"); builder.deploy ()
First use the DeploymenBuilder class to live a builder object, and create the deployment through repositoryService, and then deploy the bpmn to the database using the addClasspathResource method of builder. In this process, this method not only stores the contents of the bpmn file into the database, but also generates the corresponding flowchart png file according to bpmn to access the database.
After the process definition deployment is complete, the process definition can also be terminated or activated, and when the process definition is terminated, the process instance of the process definition can no longer be started.
/ / terminate the process definition repositoryService.suspendProcessDefinitionByKey (ProcessDefinitionKey); / / start the process definition repositoryService.activateProcessDefinitionByKey (ProcessDefinitionKey); 3. Task operation
Task candidate (group): indicates that the task can be accomplished by a user group, such as a manager.
Task holder (owner): if it is the responsibility of a person to complete the task, then that person is the holder of the task, and a task can only be owned by one holder.
Task agent (assignee): because I can not handle the task in time, and entrust to others, this person is the task agent, a task can only be one agent.
For the task setting candidate, use addCandidateUser to set the user as the candidate for a person, and record the binding relationship in the ACT_RU_ identifier table, as follows:
String taskId = UUID.randomUUID (). ToString (); / / A task is created directly here because it is only demo. Normally, you should take taskTask task = ts.newTask (taskId); task.setName ("test task"); ts.saveTask (task); / / create user String userId = UUID.randomUUID (). ToString (); User user = is.newUser (userId); user.setFirstName ("angus"); is.saveUser (user) / / candidate user ts.addCandidateUser (taskId, userId) for setting task; / / holding user ts.setOwner (taskId, userId) for setting task; / / proxy for setting task can only be declared once, and ts.claim (taskId, userId) will be declared again; 4. Task parameters and attachments
How to set parameters for a task:
/ / simple task parameters are saved in the ACT_RU_VARIABLE table taskSevice.setVariable (task.id, "var1", "hello"); / / Task parameters can also save an object, but the saved corresponding class must already implement the serialize serializable voice interface / / if the saved object, the data, that is, the sequenced object will be saved to ACT_GE_BYTEARRAYtaskSevice.setVariable (task.id, "person1", p) / / check out the stored object Person p=taskSevice.getVariable (task.id, "person1", Person.class)
Task parameters have different scopes:
Local parameter (setVariableLocal): when the current node is complete, the parameter will be invalidated.
Global parameter (setVariable): always valid.
In addition to using the java code set parameter, you can also save the parameter in the process xml file:
Crazyit
The acquisition method is as follows:
String var = taskService.getVariable (task.getId (), "personName", String.class) 5. Start a process instance
A process ProcessInstance can be understood as an "object" that we create based on a process definition (class).
The execution flow (Execution) is simply understood as the lines in the workflow diagram, and the process instance inherits the execution flow, so it is also called the execution flow.
ProcessInstance can directly use runService's startProcessInstance method to create and build. After successful creation, his data will be saved in the ACT_RU_ implementation table. It should be noted that although there is only one line in the flow chart, there will be two data in the database, one for the main execution stream and one for the sub-execution flow.
No matter what the workflow graph looks like, there must be a main execution flow, and there will be as many sub-execution flows as there are branches.
There are three main types of startProcessInstance to start according to id, key and message messages, the first two are started according to the id and key defined by the process, and the last message is to wait for a message to create a process instance.
6. Operation of process instance
The general process advances using the trigger method, and uses the id of the process to pass parameters.
Execution exe = runService.createExecutionQuery () .processInstanceId (pi.getId ()). OnlyChildExecutions () .singleResult (); System.out.println (pi.getId () + ", current node:" + exe.getActivityId ()); / / Let it go forward runService.trigger (exe.getId ()) Exe = runService.createExecutionQuery () .processInstanceId (pi.getId ()). OnlyChildExecutions () .singleResult (); System.out.println (pi.getId () + ", current node:" + exe.getActivityId ())
Signal event: the form of xml is as follows
......
It needs to wait for the program to signal before it can continue to run, otherwise it will wait in place.
RunService.signalEventReceived ("testSignal")
Message event: in xml, you need to set the message tag first, then create a message event definition in the event thrown in the middle, and execute the message tag using the messageRef attribute.
......
In the corresponding program, you only need to send the corresponding message to move the workflow forward.
RunService.messageEventReceived ("testMsg", exe.getId ())
Difference: from the method parameters of the signal and the message, we can see that the transmission of the signal does not need to define a specific object, but the message needs to establish the process. To put it simply, a signal is like a broadcast, and as long as the person who defines the signal will receive the signal, while the message is like a private message, only the target process that receives the message will continue.
7. The generation and management of work
Work generated by asynchronous tasks: the following applications will use the asynchronous execution of the activiti engine, so you need to configure the following in activiti.cfg.xml to enable asynchronous execution. If this configuration is not enabled, the process will be stuck in ServiceTask and cannot continue to run forward.
Then create a bpmn workflow diagram, open it in xml format, and change its servicetask component properties
Activti:class points to the class he wants to execute (the class needs to implement the JavaDelegate interface and implement the execute method), while the async property turns on asynchronous execution.
Package org.crazyit.act.c10;import org.activiti.engine.delegate.DelegateExecution;import org.activiti.engine.delegate.JavaDelegate;public class MyJavaDelegate implements JavaDelegate {@ Override public void execute (DelegateExecution arg0) {System.out.println ("this is a processing class");}}
Timer task: will wait for the timing to end before continuing execution, as follows:
PT1M
Interrupted tasks: tasks interrupted by suspend will be written to the ACT_RU_ supported table. In the same way that activate reactivates the interrupted tasks, the tasks will be removed from the table and return to normal operation.
Unexecutable tasks: if you join a task and throw an exception three times, it will be added to the ACT_RU_ delete table.
The above is what is the knowledge analysis of Activiti shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.