目录
类型
执行监听器
用途
配置
自定义实现
任务监听器
配置
自定义实现
事件监听器(全局监听器)
用途
配置
自定义实现
运行总结
流程图
运行日志
分析结果
执行监听器则监听流程的所有节点和连线。主要有start、end、take事件。其中节点有start、end两种事件,而连线则有take事件
自定义执行监听器需要实现ExecutionListener接口,并且实现notify方法。
@Slf4j
public class MyExecutionListener implements ExecutionListener{
@Override
public void notify(DelegateExecution delegateExecution) throws Exception {
log.info("============executionListener start============");
String eventName = delegateExecution.getEventName();
String currentActivitiId = delegateExecution.getCurrentActivityId();
log.info("事件名称:{}", eventName);
log.info("ActivitiId:{}", currentActivitiId);
log.info("============executionListener end============");
}
}
用于监听任务,任务监听器生命周期对应四个事件,分别是assignment、create、complete、delete。
当流程引擎触发这四种事件类型时,对应的任务监听器会捕获其事件类型,再按照监听器的处理逻辑进行处理。
自定义任务监听器需要实现TaskListener接口,并且实现notify方法。
@Slf4j
public class MyTaskListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
log.info("============TaskListener start============");
String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
String eventName = delegateTask.getEventName();
log.info("事件名称:{}", eventName);
log.info("taskDefinitionKey:{}", taskDefinitionKey);
log.info("============TaskListener end============");
}
}
监控该流程的启动和结束。
可配置各类事件
@Override
public final void onEvent(ActivitiEvent event) {
if (isValidEvent(event)) {
// Check if this event
if (event.getType() == ActivitiEventType.ENTITY_CREATED) {
onCreate(event);
} else if (event.getType() == ActivitiEventType.ENTITY_INITIALIZED) {
onInitialized(event);
} else if (event.getType() == ActivitiEventType.ENTITY_DELETED) {
onDelete(event);
} else if (event.getType() == ActivitiEventType.ENTITY_UPDATED) {
onUpdate(event);
} else {
// Entity-specific event
onEntityEvent(event);
}
}
}
@Slf4j
public class MyActivitiEventListener implements ActivitiEventListener {
//当时间被执行时调用该方法
@Override
public void onEvent(ActivitiEvent activitiEvent) {
log.info("============ActivitiEventListener start============");
log.info("事件类型:{}", activitiEvent.getType());
log.info("ExecutionId:{}", activitiEvent.getExecutionId());
log.info("ProcessInstanceId:{}", activitiEvent.getProcessInstanceId());
log.info("============ActivitiEventListener end============");
}
//这个是onEvent执行失败之后进行的处理
// 如果是true则返回onEvent执行失败的异常
// 如果是false则忽略这个异常
@Override
public boolean isFailOnException() {
return false;
}
}
其中1配置了全局事件监听器,如上图
2配置执行监听器,事件为take
3配置执行监听器,事件为start、end
3配置任务监听器,事件为assignment、create、complete、delete
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.391:[ INFO] [214320] [] [XNIO-2 task-2:2431126] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:19] ============ActivitiEventListener start============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.481:[ INFO] [214320] [] [XNIO-2 task-2:2431216] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:20] 事件类型:ACTIVITY_STARTED
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.481:[ INFO] [214320] [] [XNIO-2 task-2:2431216] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:21] ExecutionId:10021
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.481:[ INFO] [214320] [] [XNIO-2 task-2:2431216] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:22] ProcessInstanceId:10021
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.482:[ INFO] [214320] [] [XNIO-2 task-2:2431217] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:23] ============ActivitiEventListener end============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.486:[ INFO] [214320] [] [XNIO-2 task-2:2431221] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:18] ============executionListener start============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.486:[ INFO] [214320] [] [XNIO-2 task-2:2431221] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:21] 事件名称:take
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.487:[ INFO] [214320] [] [XNIO-2 task-2:2431222] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:22] ActivitiId:sid-397FFB45-7110-4874-9E72-F4EBA8F284C8
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.487:[ INFO] [214320] [] [XNIO-2 task-2:2431222] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:23] ============executionListener end============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.489:[ INFO] [214320] [] [XNIO-2 task-2:2431224] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:18] ============executionListener start============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.490:[ INFO] [214320] [] [XNIO-2 task-2:2431225] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:21] 事件名称:start
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.490:[ INFO] [214320] [] [XNIO-2 task-2:2431225] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:22] ActivitiId:task_1
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.491:[ INFO] [214320] [] [XNIO-2 task-2:2431226] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:23] ============executionListener end============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.491:[ INFO] [214320] [] [XNIO-2 task-2:2431226] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:19] ============ActivitiEventListener start============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.491:[ INFO] [214320] [] [XNIO-2 task-2:2431226] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:20] 事件类型:ACTIVITY_STARTED
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.492:[ INFO] [214320] [] [XNIO-2 task-2:2431227] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:21] ExecutionId:10021
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.492:[ INFO] [214320] [] [XNIO-2 task-2:2431227] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:22] ProcessInstanceId:10021
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.492:[ INFO] [214320] [] [XNIO-2 task-2:2431227] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:23] ============ActivitiEventListener end============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.525:[ INFO] [214320] [] [XNIO-2 task-2:2431260] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:16] ============TaskListener start============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.526:[ INFO] [214320] [] [XNIO-2 task-2:2431261] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:19] 事件名称:assignment
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.526:[ INFO] [214320] [] [XNIO-2 task-2:2431261] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:20] taskDefinitionKey:task_1
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.526:[ INFO] [214320] [] [XNIO-2 task-2:2431261] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:21] ============TaskListener end============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.527:[ INFO] [214320] [] [XNIO-2 task-2:2431262] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:16] ============TaskListener start============
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.527:[ INFO] [214320] [] [XNIO-2 task-2:2431262] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:19] 事件名称:create
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.527:[ INFO] [214320] [] [XNIO-2 task-2:2431262] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:20] taskDefinitionKey:task_1
[cp3-activiti-server:8780:0000:] 2021-01-21 15:32:17.528:[ INFO] [214320] [] [XNIO-2 task-2:2431263] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:21] ============TaskListener end============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.897:[ INFO] [214320] [] [XNIO-2 task-2:2797632] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:16] ============TaskListener start============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.898:[ INFO] [214320] [] [XNIO-2 task-2:2797633] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:19] 事件名称:complete
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.898:[ INFO] [214320] [] [XNIO-2 task-2:2797633] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:20] taskDefinitionKey:task_1
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.898:[ INFO] [214320] [] [XNIO-2 task-2:2797633] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:21] ============TaskListener end============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.898:[ INFO] [214320] [] [XNIO-2 task-2:2797633] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:16] ============TaskListener start============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.899:[ INFO] [214320] [] [XNIO-2 task-2:2797634] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:19] 事件名称:delete
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.899:[ INFO] [214320] [] [XNIO-2 task-2:2797634] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:20] taskDefinitionKey:task_1
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.899:[ INFO] [214320] [] [XNIO-2 task-2:2797634] [c.c.c.a.controller.flow.listener.MyTaskListener.notify:21] ============TaskListener end============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.914:[ INFO] [214320] [] [XNIO-2 task-2:2797649] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:18] ============executionListener start============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.915:[ INFO] [214320] [] [XNIO-2 task-2:2797650] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:21] 事件名称:end
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.915:[ INFO] [214320] [] [XNIO-2 task-2:2797650] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:22] ActivitiId:task_1
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.915:[ INFO] [214320] [] [XNIO-2 task-2:2797650] [c.c.c.a.c.flow.listener.MyExecutionListener.notify:23] ============executionListener end============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.919:[ INFO] [214320] [] [XNIO-2 task-2:2797654] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:19] ============ActivitiEventListener start============
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.919:[ INFO] [214320] [] [XNIO-2 task-2:2797654] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:20] 事件类型:ACTIVITY_STARTED
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.920:[ INFO] [214320] [] [XNIO-2 task-2:2797655] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:21] ExecutionId:10021
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.920:[ INFO] [214320] [] [XNIO-2 task-2:2797655] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:22] ProcessInstanceId:10021
[cp3-activiti-server:8780:MDAwMA==:] 2021-01-21 15:38:23.921:[ INFO] [214320] [] [XNIO-2 task-2:2797656] [c.c.c.a.c.flow.listener.MyActivitiEventListener.onEvent:23] ============ActivitiEventListener end============