当前位置:网站首页>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 .
边栏推荐
- 【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN
- [weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100
- Build your own application based on Google's open source tensorflow object detection API video object recognition system (IV)
- Unity load AB package
- B-杰哥的树(状压树形dp)
- Continuous test (CT) practical experience sharing
- Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,
- PowerPivot - DAX (first time)
- Design your security architecture OKR
- Use of OLED screen
猜你喜欢
5. 无线体内纳米网:十大“可行吗?”问题
Web security - payload
【每周一坑】计算100以内质数之和 +【解答】输出三角形
使用.Net驱动Jetson Nano的OLED显示屏
Application layer of tcp/ip protocol cluster
2022 nurse (primary) examination questions and new nurse (primary) examination questions
小孩子学什么编程?
I've seen many tutorials, but I still can't write a program well. How can I break it?
SQL injection 2
BeagleBoneBlack 上手记
随机推荐
Technology sharing | packet capturing analysis TCP protocol
Basic knowledge of lists
8086 instruction code summary (table)
设计你的安全架构OKR
Core principles of video games
Pytest (3) - Test naming rules
Logic is a good thing
[weekly pit] calculate the sum of primes within 100 + [answer] output triangle
【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
逻辑是个好东西
Node. Js: express + MySQL realizes registration, login and identity authentication
Rhcsa Road
2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination
Leetcode question 448 Find all missing numbers in the array
【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN
I've seen many tutorials, but I still can't write a program well. How can I break it?
Catch ball game 1
Anaconda安装后Jupyter launch 没反应&网页打开运行没执行
Tencent cloud database public cloud market ranks top 2!
[weekly pit] output triangle