Activiti Combat Notes
A, an overview of
Chart 1.1
1.2 the Service
RepositoryService | Management Process Definition |
---|---|
RuntimeService | Perform management, including starting, advancing, and deleting process instances |
TaskService | Task management |
HistoryService | History management (management of finished data) |
IdentityService | Organization management |
FormService | An optional service, task form management |
ManagerService |
1.3 Database Tables
The table prefix | type | meaning |
---|---|---|
ACT_RE_* | repository | Contains process definitions and process static resources (images, rules, and so on) |
ACT_RU_* | runtime | Run-time tables, which contain running data such as process instances, tasks, variables, and asynchronous tasks, save data only during the execution of the process instance and delete records at the end of the process so that the run-time table can remain small and fast. |
ACT_ID_* | identity | Contains identity information, such as users, groups, and so on |
ACT_HI_* | history | Contains historical data, such as historical process instances, variables, tasks, and so on |
ACT_GE_* | general | Used in different scenarios, such as storing resource files |
1.4 Activiti data table list
Classification table | The name of the table | explain |
---|---|---|
General data | ACT_GE_BYTEARRAY | Common process definitions and process resources |
General data | ACT_GE_PROPERTY | System related Attributes |
Process history | ACT_HI_ACTINST | Historical process instances |
Process history | ACT_HI_ATTACHMENT | Historical process attachments |
Process history | ACT_HI_COMMENT | Historical illustrative information |
Process history | ACT_HI_DETAIL | Details of the process execution in history |
Process history | ACT_HI_IDENTITYLINK | History of user relationships during process runs |
Process history | ACT_HI_PROCINST | Historical process instances |
Process history | ACT_HI_TASKINST | Historical task instances |
Process history | ACT_HI_VARINST | Historical information about variables in a process run |
User Indicates the user group table | ACT_ID_GROUP | Identity information – Group information |
User Indicates the user group table | ACT_ID_INFO | Identity information – Group information |
User Indicates the user group table | ACT_ID_MEMBERSHIP | Identity information – An intermediate table of user and group relationships |
User Indicates the user group table | ACT_ID_USER | Identity information – User information |
Process definition table | ACT_RE_DEPLOYMENT | Deployment Unit Information |
Process definition table | ACT_RE_MODEL | Model information |
Process definition table | ACT_RE_PROCDEF | Deployed process definitions |
Run instance table | ACT_RU_EVENT_SUBSCR | Run time event |
Run instance table | ACT_RU_EXECUTION | Runtime process execution instance |
Run instance table | ACT_RU_IDENTITYLINK | Runtime user relationship information |
Run instance table | ACT_RU_JOB | Run time job |
Run instance table | ACT_RU_TASK | Runtime task |
Run instance table | ACT_RU_VARIABLE | Run time varying meter |
1.5 core API
1.5.1 ProcessInstance
Represents an execution instance of a process definition. A process instance represents the largest process branch from start to finish of a process, i.e. there is only one process instance in a process.
1.5.2 Execution
The Execution of a process once according to the rules defined by the process;
- A process executed concurrently, with the total line representing ProcessInstance and each activity in the sub-line representing Execution
- A process in which Execution objects execute concurrently, with the total line representing ProcessInstance and each activity in the sub-line representing Execution
- There can be more than one, but ProcessInstance can only have one
2. Method & table
2.1 DeploymentBuilder. Deploy ()
Deployment deployment = processEngine.getRepositoryService()//
.createDeployment()
.addClasspathResource("diagrams/LeaveBill.bpmn")
.addClasspathResource("diagrams/LeaveBill.png")
.deploy();
Copy the code
This step will operate on three tables in the database:
- Act_re_deployment (deployment object table) holds the display name and deployment time defined by the process, adding one record for each deployment
- Act_re_procdef (Process definition table)
Holds property information for process definitions, and each new process definition is deployed to add a record to this table.
Note: Version upgrades are used when the process defines the same key
- Act_ge_bytearray (Resource file table) stores deployment information related to the process definition. That is, where the process definition document is stored. Each deployment adds two records, one for the BPMN rule file and one for the image. (If only one BPMN file is specified at deployment time, Activiti will parse the BPMN file content to automatically generate a flow chart at deployment time.) Both files are not very large and are stored in the database in binary form.
-
The ACT_RE_PROCDEF process parses the table, parses successfully, and saves a record in the table. Business process definition data table ACT_RE_PROCDEF(ACT_RE_PROCDEF)
NAME The field name The field ID_ Process ID {processDefinitionKey}:{processDefinitionVersion}:{generated-id} REV_ The version number CATEGORY_ Process namespace The Namespace defined by the process is the category NAME_ The name of the process This number is the value of the name attribute of the process element in the process file KEY_ Process definition ID This number is the id attribute value of the process element in the process file VERSION_ Process version number Controlled by the program, the new is 1, after modification, add 1 to complete DEPLOYMENT_ID_ Deployment number Deployment table ID RESOURCE_NAME_ Process BPMN file name DGRM_RESOURCE_NAME_ PNG Process image name DESCRIPTION_ Description information describe HAS_START_FORM_KEY_ Start Specifies whether formKey exists on the node 0 no 1 is SUSPENSION_STATE_ Whether a hang 1 Activate 2 Suspend This table has a many-to-one relationship with ACT_RE_DEPLOYMENT, that is, a deployed BAR package may contain multiple process definition files, and each process definition file will have one record in the ACT_RE_PROCDEF table. The data defined by each process, Both a resource file and a PNG image file in the ACT_GE_BYTEARRAY table. The association with ACT_GE_BYTEARRAY is done programmatically with act_ge_bytearray. NAME and act_re_procdef.name_, and is not reflected in the database table structure
-
ACT_RE_DEPLOYMENT is used to store information that needs to be persisted at deployment time
Whether the primary key The field name The field ID_ The deployment number is self-increasing NAME_ The name of the deployment package CATEGORY_ type VARCHAR(255) DEPLOY_TIME_ The deployment of time TIMESTAMP -
BPMN and leavebill. PNG are resourceEntities that are added to the table. ACT_GE_BYTEARRAY(ACT_GE_BYTEARRAY)
Name The field name The field ID_ ID_ Primary key ID, resource file number, self-growing REV_ The version number INT(11) NAME_ The name of the deployed file, DEPLOYMENT_ID_ Primary key from parent table ACT_RE_DEPLOYMENT BYTES_ Large text type that stores a stream of text bytes LONGBLOB GENERATED_ Engine generated or not 0 is generated by the user and 1 is generated by Activiti
2.2 RuntimeService().startProcessInstanceByKey()
When the process reaches a node, one entry is produced in the ACT_RU_EXECUTION table, which adds a record to the ACT_RU_TASK table if the current node is a user task node
-
ACT_RU_TASK(ACT_RU_TASK) (ACT_RU_TASK)
Whether the primary key The field name The field ID_ REV_ The version number INT(11) EXECUTION_ID_ Instance ID (foreign key EXECUTION_ID_) Execution Instance ID ** PROC_INST_ID_** Process instance ID (foreign key PROC_INST_ID_) VARCHAR(64) PROC_DEF_ID_ Process definition ID VARCHAR(64) NAME_ The name of the task Node definition name PARENT_TASK_ID_ Parent task ID ID of the parent node instance DESCRIPTION_ Task description Description of node Definition TASK_DEF_KEY_ Task Definition Key ID of the task definition OWNER_ Owner (old version) Owner (generally empty and has a value only when delegating) ASSIGNEE_ Agent (assignee) Consignee or trustee DELEGATION_ Agent group DelegationState is classified into two types: PENDING and RESOLVED. Null if no delegate VARCHAR(64) PRIORITY_ priority INT(11) CREATE_TIME_ Creation time TIMESTAMP DUE_DATE_ The execution time Time consuming SUSPENSION_STATE_ hold 1 indicates activation. 2 indicates suspension -
ACT_RU_EXECUTION core, my to-do list ACT_RU_EXECUTION(ACT_RU_EXECUTION)
Whether the primary key The field name The field ID_ ID_ REV_ The version number INT(11) PROC_INST_ID_ Process Instance Number VARCHAR(64) BUSINESS_KEY_ ID of the service primary key VARCHAR(255) PARENT_ID_ Parent execution process ID of the parent node instance PROC_DEF_ID_ Process definition Id VARCHAR(64) SUPER_EXEC_ VARCHAR(64) 64 ACT_ID_ Instance id The node instance ID is the ID of ACT_HI_ACTINST IS_ACTIVE_ active Whether to live IS_CONCURRENT_ The concurrent state Parallel or not (true/false) IS_SCOPE_ TINYINT(4) IS_EVENT_SCOPE_ TINYINT(4) SUSPENSION_STATE_ Suspended state _ Suspended state 1 Active 2 Suspended CACHED_ENT_STATE_ Cache end status _ INT(11) -
ACT_RU_IDENTITYLINK stores information about the current node participant, a task participant data table. ACT_RU_IDENTITYLINK(act_ru_identitylink)
Whether the primary key The field name The field ID_ ID_ REV_ The version number INT(11) GROUP_ID_ The user group ID VARCHAR(255) TYPE_ User Group Type It is mainly divided into the following categories: Assignee, candidate, owner, starter, and Participant. Namely: transferee, candidate, owner, starter, participant USER_ID_ The user ID VARCHAR(255) TASK_ID_ Task Id VARCHAR(64) PROC_INST_ID_ Process instance ID VARCHAR(64) PROC_DEF_ID_ Process definition Id VARCHAR(64) -
ACT_HI_ACTINST (History node table) Historical activity information. Unlike HI_TASKINST, which only records the userTask content, this records all nodes through which the process flows
ACT_HI_ACTINST(act_hi_actinst)
Whether the primary key The field name The field ID_ ID_ PROC_DEF_ID_ Process definition ID VARCHAR(64) PROC_INST_ID_ Process instance ID VARCHAR(64) EXECUTION_ID_ Process execution ID VARCHAR(64) ACT_ID_ Activity ID Node Definition ID TASK_ID_ Task ID Task Instance ID The instance IDS of other node types are empty here CALL_PROC_INST_ID_ Request process instance ID Process instance ID’ to invoke the external process ACT_NAME_ The name of the event Node definition name ACT_TYPE_ The activity type Such as startEvent, userTask ASSIGNEE_ The agent Node signatory START_TIME_ The start time DATETIME END_TIME_ The end of time DATETIME DURATION_ Length of time Millisecond value
Third, the tutorial
3.1 Differences between setVariable and setVariableLocal
- SetVariable When setting a process variable, if the process variable name is the same, the previous value is replaced by the previous value, and the TASK_ID field does not store the task ID value
- SetVariableLocal sets the process variable for the current active node. If there are two active nodes (branches) in a process, set the process variable for each active node. Even if the name of the process variable is the same, the value of the later version will not replace the value of the previous version. It stores the two process variable values using different task ids as identifiers, and you can see that the TASK_ID field holds the value of the task ID
3.2 Exclusive Gateway
Only one result will be returned. When the process is executed to the exclusive gateway, the process engine automatically retrieves the gateway exit from top to bottom. If the result of the first decision is found to be true or no condition is set (the default is true), the process engine will flow out. Using the process variable, set the criteria for the wire, and execute the workflow according to the criteria for the wire, leaving with the default wire if no criteria are met. You need to set flow variables. If you do not set flow variables, exceptions will be thrown and the system will not go to the default gateway
3.3 Parallel Gateway
If the same parallel gateway has multiple incoming and multiple outgoing sequential flows, it has both branching and converging capabilities. In this case, the gateway will converge all incoming sequential streams before splitting them into parallel branches. Parallel gateways do not parse conditions, and even if they are defined in sequential flows, they are ignored
3.4 Receiving Activities receiveTask
After the task is created, it means that the process goes into a wait state until the engine receives a specific message, which triggers the process to continue through the receive task. The ReceiceTask task, which is performed automatically by the machine, produces only one piece of data in the ACT_RU_execution table
3.5 Personal Tasks
Set the task manager
3.5.1 Using process variables
3.5.2 using class
processEngine.getTaskService().setAssignee(taskId, userId);
3.6 set of tasks
- Direct appointment of transactor
Example Query the task member list of a group
List<IdentityLink> list = processEngine.getTaskService().getIdentityLinksForTask(taskId)
Copy the code
Act_ru_identitylink: owner of a storage task, including an individual task and a group task, indicating ongoing tasks act_hi_identitylink: owner of a storage task, including an individual task and a group task, indicating historical tasks If it’s an individual task TYPE it’s a Participant and if it’s a group task TYPE it’s a candidate and participant
-
Using process variables
-
class
through
processEngine.getTaskService().claim (taskId, userId);
To assign a group task to an individual task, also known as a claim task, is to assign someone to handle the task. If the userId is not in the candidate, the userId is added to the candidate list, corresponding to the IdentityLink table
When taking a task, the participant can be either a task member or a non-task member. In this case, the Type of Type is set to Participant to specify the task handler
3.7 character set
Act_id_group: role group table ACT_ID_user: user table ACT_ID_membership: user role table Sets the manager of group tasks and stores group and user information to the Activiti table between the deployment process definition and the startup process instance
Activiti combat
4.1 the task
4.1.1 User Tasks
Task to monitor the Create Create a task, the assignment tasks, complete the task complete Expression, delegateExpression, Alfresco script Activity: initiator = “XXX”, can put the people in starting the operation of the process instance variable name “XXX” saved to the database, need to cooperate identityService setAuthenticatedUserId (authenticatedUserId) with
4.1.2 Script Tasks
Scripting languages can be runCopy the code
4.1.3 Service task
4.1.4 Business Rule Tasks
You can integrate with Drools
4.1.5 Email Task
An extension of Activiti based on serviceTask for emailing
4.1.6 Camel
Extending from Activiti, serviceTask is a framework for addressing message routing
4.1.7 Manual task
Without doing anything, the process engine doesn’t have to figure out how to handle it. Activiti treats a manual task as an empty task that the engine automatically completes when it reaches and moves on to the next task
4.1.8 Receive task
After a task is created, it waits for a message to arrive and does not complete the task until it is triggered. You can send a signal through the Signal () method of the RuntimeService interface to trigger the receiving task
4.1.9 multi-instance
Allow a task or even a sub-process to be repeated multiple times such as an application approved by more than one person, sequential execution and parallel execution can be selected, repeated execution and completion conditions can be set
4.2 the gateway gateway
4.2.1 Exclusive Gateway
If more than one line evaluates to true, the gateway with the first value true is executed. If none of the lines evaluates to true, an exception is thrown
4.2.2 Parallel Gateway
At the parallel gateway convergence, only when all incoming processes have entered can a process move down
4.2.3 Inclusion Gateway InclusiveGateway
It combines the characteristics of the exclusive gateway and the parallel gateway, which can execute multiple lines simultaneously and allow conditions to be set on the gateway
4.2.4 Event Gateway
The event gateway is specifically set up for intermediate capture events, allowing multiple output streams to be set up to point to multiple different intermediate capture events (at least two). After the process executes to the event gateway, the process is in the “wait” state, and the intermediate capture event needs to be triggered by the intermediate throw event to change the wait state to the active state
4.3 Subprocesses and invoke activities
4.3.1 subprocesses
Subprocesses can contain most of the models of process specifications. The most common one is to separate the most common processes into subprocesses and embed them in each process
- The constraint
- Only one and only one null start event can be contained
- There must be at least one closing event
- A sequential flow in a subprocess cannot directly set an output stream to an activity outside the subprocess; it can be set through boundary events instead
4.3.2 Calling an Activity Call Activiti
In place of an activity embedded in a subprocess, you can use an invocation activity to act as a subactivity of the main process by creating an invocation activity model and specifying the id of the external process
4.3.3 Event subprocess
Similar to a subprocess, except that an event subprocess cannot be started directly, but is passively triggered by other events that can be triggered by exception events, signal events, message events, timer events, compensation events, etc
4.3.4 Transaction subprocess
This subprocess has transactional,ACID, rollback
4.4 Boundary and intermediate events
A boundary event is a “catch” event that is bound to an activity. Once a boundary event is triggered, the current activity is interrupted and then executed in the output stream following the boundary event. Only one boundary event can be bound
4.4.1 Timer boundary Events
Timer start event: used to start a new process timer boundary event at a specified time: attached to a non-automatic task, invoke activity, subprocess, and start countdown to trigger event after completion of upstream task execution
4.4.2 Abnormal boundary events
Used to catch an exception thrown by an embedded subprocess or invoke activity that is then caught by the main process’s exception boundary event, while the activity in the embedded subprocess or invoke activity is also interrupted
<sequenceFlow id="flow-treasurerAudit" name="Financial disapproval" sourceRef="exclusivegateway-treasurerAudit" targetRef="errorendevent2">
Copy the code
You can also throw an exception directly
4.4.3 Signal boundary events
Signal boundary event can capture process execution of signals, can be attached on the various activities and subprocesses signal throw events is global: signals boundary events not only can capture this process, also can capture signals to other process events, if defines multiple signals boundary events and listen to the same, will trigger multiple boundary events at the same time
4.4.4 Cancel the boundary event
Designed specifically for the transaction subprocess to capture cancellation events thrown in the subprocess and cannot be attached to other activities
- A transaction main process allows only one cancellation event to be attached
- If a subprocess is nested within a transaction subprocess, only the subprocess compensation event that has already been completed is fired?
- For a multi-instance transaction subprocess, if one instance triggers a cancellation event, all instances will trigger a cancellation boundary event
4.4.5 Compensating for boundary events
It is used to compensate the business logic after the transaction failure in the transaction subprocess. If the compensation boundary event is attached to the activity room multi-instance, when the compensation event is thrown, each instance will trigger the compensation boundary event
4.4.6 Intermediate Capture events
An intermediate capture event must be connected to an input stream and an output stream, depending on the type of event that needs to be used in different ways to continue the activity of subsequent output streams
- Events are captured in the middle of timers
- The intermediate capture event is used to capture the signal event thrown, and the broadcast propagation can be captured if the signal ID is consistent
- In-message capture events are propagated one-to-one, and only one message can be sent to one specified process instance at a time
4.4.7 Intermediate Event Thrown
Intermediate throw events are meaningful only if they are received by corresponding capture events. Intermediate throw events are generally used in scenarios where notifications or other system tasks need to be executed after the completion of a task, and the workflow engine will propagate the event
- Throwing events in the air does not perform flow functions, but can be made more meaningful by the extended capabilities added to Activiti for most activities/events, acting as intermediate state/result handlers
- The event thrown in the middle of the signal can be synchronized or asynchronous. When the signal is synchronized, the process can be continued until the signal is captured and processed. If an error occurs in the middle, the next process will be executed immediately after the signal is sent in the asynchronous process without rollback
4.5 the listener
4.5.1 Execution listener
Allows Java code to be executed in the execution flow listening for types :start,end,take
- The process instance starts and ends
- Output stream capture
- The activity starts and ends
- The route starts and ends
- Intermediate events begin and end
- Trigger start event, trigger end event
Three listener execution types
- Class: Implements the interface
- Expression: Expression, similar to EL
- DelegateExpression: Interface class that can be implemented as parameters
4.5.2 Task Listener
Applies only to user task listening types
- Assignment: Triggered after a task has been assigned to a handler, before create
- Create: Agent, candidate, and candidate group attributes that need to be processed one by one
- Assignment -> create->complete
4.6 Task List
The form properties
Five, timed operation
After the engine deploys the process, the engine does some initialization of the deployed process definition, including registration of scheduled jobs and registration of message events with the main field descriptions of the ACT_RU_JOB table
6. Message start event
After the process is deployed, the engine processes message events in initialization, registers the message type in the data act_ru_EVENT_subSCr. Message type events encountered during process execution or triggered by API trigger the table to read data, and invoke the message handler based on the message properties
ProcessInstance = runtimeService. StartProcessInstanceByMessage (" start XXX process ");
End the event
Terminating event: Terminates the entire process. Null terminating event: terminates the execution of only one output stream HistoricActivityInstance in historical task instance, a HistoricActivityInstance. GetDeleteReason (), the corresponding act_hi_taskinst table DELETE_REASON_ fields If a task completed normally (using the complete method), the DELETE_REASON_ value is completed, and if the task was deleted, the reason is deleted For example, if the null-end event did not complete but the main process completed, the records for the subprocess are deleted
Message boundary events
For message boundary events, signal boundary events, and exception boundary events, a cancelActivity attribute is added. The value can be: True: cancelActivity is cancelled after the boundary event is triggered. False: The registered event is retained after the boundary event is triggered and can be triggered again
runtimeService.messageEventReceived(messageName, executionId); // Trigger a message boundary event
Copy the code
By the same token, the trigger signal runtimeService. SignalEventReceived (signalName executionId); If a task has additional message boundary events, the registered events will be removed when the task completes and the boundary events are not triggered
Nine, task,
9.1 Task client and Task manager
Client: Owner_ Handler: Assignee_
// Participant:
taskService.addUserIdentityLink(taskId, userId, identityLinkType);
taskService.getIdentityLinksForTask(taskId);
/ / sign for it
processEngine.getTaskService().claim(task.getId(), " user "); // The database field owner_ is user
/ / delegation
processEngine.getTaskService().delegateTask(task.getId(), "henryyan"); The // // database field assignee _ is Henryyan
// The delegate completes the task
taskService.resolveTask(task.getId());
Copy the code
Final Assignee: user1, Owen: user1 owner is the task owner is only one, Assignee’s task to determine the receiver, also is only one, the candidate is the person who can get the task, then there will be a lot of, So the candidate on identitylink associated task in the table, and the first two is directly in the task can be indicated in the table When the taskService. GetIdentityLinksForTask (” task102 “); , the three cases (two tables) should be taken into account.
9.2 Acceptance and counter acceptance
Claim (taskId, userId); Claim (taskId, null); // Empty the signed task handler
9.3 Candidates and candidate Groups
TaskService. AddUserIdentityLink (taskId, userId, identityLinkType) identityLinkType into several classes of people
What is the use of setting an authenticated user?
9.4 the subtasks
A task can be split into multiple tasks and assigned to different people. When the main task is complete, the sub-tasks are also completed by default, and deleted from the RU table into the HI table
Task task2 = taskService.newTask();
task2.setParentTaskId(task.getId());
task2.setAssignee("sub task");
taskService.saveTask(task2); // Record to the database
Copy the code
stories
- View child processes through parent processes
List<Execution> processInstances = processEngine.getRuntimeService().createExecutionQuery().processInstanceId("13201").list();
Copy the code