当前位置:网站首页>flowable 全局监听 监听流程的启动和流程的结束
flowable 全局监听 监听流程的启动和流程的结束
2022-06-22 21:43:00 【gblfy】
1. Flowable全局监听配置
package com.gblfy.flowable.config;
import com.gblfy.flowable.listener.global.GlobalProcistEndListener;
import com.gblfy.flowable.listener.global.GlobalProcessStartedListener;
import com.gblfy.flowable.listener.global.GlobalTaskCompletedListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
/** * Flowable全局监听配置 * 用途:在任务特殊节点或者流程的特殊节点做一些自定义操作 * * @author gblfy * @Date 2022-06-21 **/
@Configuration
public class FlowableGlobListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
private SpringProcessEngineConfiguration configuration;
@Autowired
private GlobalTaskCompletedListener globalTaskCompletedListener;
@Autowired
private GlobalProcessStartedListener globalProcessStartedListener;
@Autowired
private GlobalProcistEndListener globalProcistEndListener;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
//任务创建全局监听
dispatcher.addEventListener(globalTaskCompletedListener, FlowableEngineEventType.TASK_COMPLETED);
//流程开始全局监听
dispatcher.addEventListener(globalProcessStartedListener, FlowableEngineEventType.PROCESS_STARTED);
//流程结束全局监听
dispatcher.addEventListener(globalProcistEndListener, FlowableEngineEventType.PROCESS_COMPLETED);
}
}
2. 流程启动的监听器
package com.gblfy.flowable.listener.global;
import org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 全局的流程启动的监听器
*
* @author: gblfy
* @date 2022-06-21
*/
@Component
public class GlobalProcessStartedListener extends AbstractFlowableEngineEventListener {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
protected void processStarted(FlowableProcessStartedEvent event) {
logger.info("进入流程开始监听器------------------------Start---------------------->");
String eventName = event.getType().name();
FlowableEntityEventImpl flowableEntityEvent = (FlowableEntityEventImpl) event;
ExecutionEntityImpl processInstance = (ExecutionEntityImpl) flowableEntityEvent.getEntity();
Date startTime = processInstance.getStartTime();
String processDefinitionKey = processInstance.getProcessDefinitionKey();
String processInstanceId = processInstance.getProcessInstanceId();
String processInstanceBusinessKey = processInstance.getProcessInstanceBusinessKey();
int suspensionState = processInstance.getSuspensionState();
logger.info("流程事件类型->{}", eventName);
logger.info("流程开始时间->{}", startTime);
logger.info("流程定义Key->{}", processDefinitionKey);
logger.info("流程实例ID->{}", processInstanceId);
logger.info("流程业务key->{}", processInstanceBusinessKey);
logger.info("流程是否挂起标志->{}", suspensionState);
logger.info("流程开始监听器------------------------End---------------------->");
}
}
3. 流程结束的监听器
package com.gblfy.flowable.listener.global;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 流程结束全局监听器
*
* @author: gblfy
* @date 2022-06-21
*/
@Component
public class GlobalProcistEndListener extends AbstractFlowableEngineEventListener {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
protected void processCompleted(FlowableEngineEntityEvent event) {
logger.info("进入流程完成监听器------------------------Start---------------------->");
String eventName = event.getType().name();
FlowableEntityEventImpl flowableEntityEvent = (FlowableEntityEventImpl) event;
ExecutionEntityImpl processInstance = (ExecutionEntityImpl) flowableEntityEvent.getEntity();
Date startTime = processInstance.getStartTime();
String processDefinitionKey = processInstance.getProcessDefinitionKey();
String processInstanceId = processInstance.getProcessInstanceId();
String processInstanceBusinessKey = processInstance.getProcessInstanceBusinessKey();
int suspensionState = processInstance.getSuspensionState();
logger.info("流程事件类型->{}", eventName);
logger.info("流程开始时间->{}", startTime);
logger.info("流程定义Key->{}", processDefinitionKey);
logger.info("流程实例ID->{}", processInstanceId);
logger.info("流程业务key->{}", processInstanceBusinessKey);
logger.info("流程是否挂起标志->{}", suspensionState);
logger.info("流程完成监听器------------------------End---------------------->");
}
}
注意:FlowableEntityEventImpl类的包路径
import org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl;
边栏推荐
- Webrtc series - 4connection sorting of network transmission
- Optimization - linear programming
- JSBridge
- Anti shake & throttling enhanced version
- Smart data won two annual awards at the second isig China Industrial Intelligence Conference
- OJ daily practice - find the first character that only appears once
- OJ每日一练——病毒的增生
- [go] go polymorphism
- OJ daily exercise - virus proliferation
- OJ daily practice - class dining
猜你喜欢

Future alternatives to IPv4! Read the advantages, features and address types of IPv6

SAP MM ME27 创建公司内STO单
因为我说:volatile 是轻量级的 synchronized,面试官让我回去等通知!

Kunlun distributed database sequence function and its implementation mechanism

Introduction to the unique variable reading and writing function of Kunlun distributed database
![[STM32 skill] use the hardware I2C of STM32 Hal library to drive rx8025t real-time clock chip](/img/32/88321db57afb50ccc096d687ff9c41.png)
[STM32 skill] use the hardware I2C of STM32 Hal library to drive rx8025t real-time clock chip

KunlunDB查询优化(二)Project和Filter下推
![[go] go mod mode, package 12import/add is not in goroot](/img/b5/4cf5d3f04d0e5cc6f5a957959022ec.png)
[go] go mod mode, package 12import/add is not in goroot

How to use swagger2

SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库试读版
随机推荐
Anti shake & throttling enhanced version
华为云招募工业智能领域合作伙伴,强力扶持+商业变现
2022天梯赛-全国总决赛复盘赛
为什么大家很少使用外键了?
事务系统的隔离级别
OJ每日一练——找第一个只出现一次的字符
DML:Data Manipulation Language 数据操纵语言
Future alternatives to IPv4! Read the advantages, features and address types of IPv6
Package management tools --npm, -cnpm, -yan, -cyarn
SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库试读版
Customize multi-level list styles in word
Redis cache
OJ daily practice - word length
事物系统的几种异常场景
Unity: use ray to detect objects
【GO】Go Modules入門
Php7.3 error undefined function simplexml_ load_ string()
Tp5.1 upload excel file and read its contents
Isolation level of transaction system
KunlunDB备份和恢复