当前位置:网站首页>Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
2022-07-06 20:32:00 【Programmer Shi Lei】
If we want to configure monitoring for tasks , As a rule, it's like this
Configure one by one , More trouble .
Now use ActivitiEventListener, Monitor global events , And we can judge different event types , And then perform different business logic .
1. Define event handling handler Interface
Using interfaces to define uniform conventions
public interface EventHandler {
void handle(ActivitiEvent event);
}
- 1.
- 2.
- 3.
2. Implement different events
End of mission Events
*/
public class TaskCompleteListener implements EventHandler {
protected Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void handle(ActivitiEvent event) {
ActivitiEntityEventImpl eventImpl = (ActivitiEntityEventImpl) event;
TaskEntity taskEntity = (TaskEntity) eventImpl.getEntity();
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
Task creation Events
public class TaskCreateListener implements EventHandler {
protected Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void handle(ActivitiEvent event) {
ActivitiEntityEventImpl eventImpl = (ActivitiEntityEventImpl) event;
TaskEntity taskEntity = (TaskEntity) eventImpl.getEntity();
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
There are many more events , such as TASK_ASSIGNED,PROCESS_STARTED,PROCESS_COMPLETED
3. Realization ActivitiEventListener
public class GlobalEventListener implements ActivitiEventListener {
protected Logger logger = LoggerFactory.getLogger(getClass());
/**
* Various types Event The processor of
*/
private Map<ActivitiEventType, EventHandler> handlers = new HashMap<ActivitiEventType, EventHandler>();
@Override
public void onEvent(ActivitiEvent event) {
EventHandler eventHandler = handlers.get(event.getType());
if(eventHandler!=null){
eventHandler.handle(event);
}
}
@Override
public boolean isFailOnException() {
return false;
}
public Map<ActivitiEventType, EventHandler> getHandlers() {
return handlers;
}
public void setHandlers(Map<ActivitiEventType, EventHandler> handlers) {
this.handlers = handlers;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
4. Register event monitoring
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="jobExecutorActivate" value="false"/>
<property name="history" value="full"/>
<property name="processDefinitionCacheLimit" value="10"/>
<!-- Generate font for flowchart -->
<property name="activityFontName" value=" Song style "/>
<property name="labelFontName" value=" Song style "/>
<property name="annotationFontName" value=" Song style "/>
<!-- Automatic deployment -->
<property name="deploymentResources">
<list>
<value>classpath*:*</value>
</list>
</property>
<!-- <property name="idGenerator" ref="idGenerator"/>-->
<property name="eventListeners">
<list>
<ref bean="globalEventListener"/>
</list>
</property>
<property name="customFormTypes">
<bean class="org.activiti.engine.impl.form.DateFormType">
<constructor-arg value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"/>
</bean>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
<bean id="formService" factory-bean="processEngine" factory-method="getFormService"/>
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>
<!-- Process global event handler -->
<bean id="globalEventListener" class="GlobalEventListener">
<property name="handlers">
<map>
<entry key="TASK_CREATED">
<bean class="TaskCreateListener"/>
</entry>
<entry key="TASK_COMPLETED">
<bean class="TaskCompleteListener"/>
</entry>
</map>
</property>
</bean>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
advantage
- So the code is clear , Business logic decoupling , Single responsibility
- Omit the bpmn.xml Middle configuration , convenient .
边栏推荐
- 2022 refrigeration and air conditioning equipment installation and repair examination contents and new version of refrigeration and air conditioning equipment installation and repair examination quest
- Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
- (work record) March 11, 2020 to March 15, 2021
- 5. 無線體內納米網:十大“可行嗎?”問題
- 02 基础入门-数据包拓展
- BUUCTF---Reverse---easyre
- “罚点球”小游戏
- Qinglong panel white screen one key repair
- Special topic of rotor position estimation of permanent magnet synchronous motor -- fundamental wave model and rotor position angle
- SSO single sign on
猜你喜欢
Oceanbase Community Edition OBD mode deployment mode stand-alone installation
Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
[network planning] Chapter 3 data link layer (3) channel division medium access control
SQL injection 2
“罚点球”小游戏
5. Wireless in vivo nano network: top ten "feasible?" problem
棋盘左上角到右下角方案数(2)
报错分析~csdn反弹shell报错
Tencent T4 architect, Android interview Foundation
【每周一坑】输出三角形
随机推荐
[DIY]自己设计微软MakeCode街机,官方开源软硬件
5. Wireless in vivo nano network: top ten "feasible?" problem
Function optimization and arrow function of ES6
Discussion on beegfs high availability mode
Introduction of Xia Zhigang
Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model
使用.Net驱动Jetson Nano的OLED显示屏
APS taps home appliance industry into new growth points
【计网】第三章 数据链路层(3)信道划分介质访问控制
[DSP] [Part 1] start DSP learning
为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?
【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
Deep learning classification network -- zfnet
In line elements are transformed into block level elements, and display transformation and implicit transformation
8086指令码汇总表(表格)
使用ssh连接被拒
BUUCTF---Reverse---easyre
[DIY]如何制作一款個性的收音機
Unity load AB package
[weekly pit] calculate the sum of primes within 100 + [answer] output triangle