Flowable源码地址:https://github.com/flowable/flowable-engine
Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated
包路径:org.flowable.engine.delegate
ExecutionListener 执行监听器接口类
/**
* 回调接口,用于通知执行事件,如启动流程实例、结束活动实例或进行转换。
*
* @author Tom Baeyens
* @author Joram Barrez
* @author Yvo Swillens
*/
public interface ExecutionListener extends BaseExecutionListener {
void notify(DelegateExecution execution);
}
ProcessInstanceEndHandler 流程实例结束处理类
package org.activiti.engine.impl.history.handler;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
/**
* 负责更新ACT_HI_PROCINST表中的数据
*
* @author Tom Baeyens
*/
public class ProcessInstanceEndHandler implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
Context.getCommandContext().getHistoryManager().recordProcessInstanceEnd(
execution.getProcessInstanceId(), ((ExecutionEntity) execution).getDeleteReason(), ((ExecutionEntity) execution).getActivityId());
}
}
StartEventEndHandler 开始事件结束处理类
package org.activiti.engine.impl.history.handler;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
/**
* 负责将开始节点的信息插入到ACT_HI_ACTINST表中
*
* @author Tom Baeyens
*/
public class StartEventEndHandler implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
String activityId = ((ExecutionEntity) execution).getActivityId();
Context.getCommandContext().getHistoryManager()
.recordStartEventEnded((ExecutionEntity) execution, activityId);
}
}
CallActivityStartHandler 调用活动开始处理类
package org.activiti.engine.impl.history.handler;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
/**
* 流程引擎暂时没有对其进行实现
*/
public class CallActivityStartHandler implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
}
}
ActivityInstanceStartHandler 活动实例开始处理类
package org.activiti.engine.impl.history.handler;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
/**
* 负责将历史数据插入到ACT_HI_ACTINST表中
*
* @author Tom Baeyens
*
* 请注意:对于开始事件,这是在ProcessDefinitionEntity中完成的!
*/
public class ActivityInstanceStartHandler implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
Context.getCommandContext().getHistoryManager()
.recordActivityStart((ExecutionEntity) execution);
}
}
ActivityInstanceEndHandler 活动实例结束处理类
package org.activiti.engine.impl.history.handler;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
/**
* 负责更新ACT_HI_ACTINST表中的删除原因(非必须)、结束时间、节点持续时间
*
* @author Tom Baeyens
*/
public class ActivityInstanceEndHandler implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
Context.getCommandContext().getHistoryManager()
.recordActivityEnd((ExecutionEntity) execution);
}
}
ExpressionExecutionListener Expression执行监听器
package org.flowable.engine.impl.bpmn.listener;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
/**
* 一个执行监听器{@link ExecutionListener},在收到通知时对表达式{@link Expression}求值。
* 负责调度执行expression方式创建的执行监听器
*
* @author Frederik Heremans
*/
public class ExpressionExecutionListener implements ExecutionListener {
protected Expression expression;
public ExpressionExecutionListener(Expression expression) {
this.expression = expression;
}
@Override
public void notify(DelegateExecution execution) {
// Return value of expression is ignored
expression.getValue(execution);
}
/**
* 返回此执行监听器的表达式文本。如果你想检查你已经有了哪些监听器,这很有用。
*/
public String getExpressionText() {
return expression.getExpressionText();
}
}
DelegateExpressionExecutionListener DelegateExpression执行监听器
/**
* 负责调度执行DelegateExpression方式创建的执行监听器
*
* @author Joram Barrez
*/
public class DelegateExpressionExecutionListener implements ExecutionListener {
protected Expression expression;
private final List<FieldDeclaration> fieldDeclarations;
public DelegateExpressionExecutionListener(Expression expression, List<FieldDeclaration> fieldDeclarations) {
this.expression = expression;
this.fieldDeclarations = fieldDeclarations;
}
@Override
public void notify(DelegateExecution execution) {
Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, execution, fieldDeclarations);
if (delegate instanceof ExecutionListener) {
CommandContextUtil.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution));
} else if (delegate instanceof JavaDelegate) {
CommandContextUtil.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
} else {
throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ExecutionListener.class + " nor " + JavaDelegate.class);
}
}
/**
* 返回此执行监听器的表达式文本。如果你想检查你已经有了哪些监听器,这很有用。
*/
public String getExpressionText() {
return expression.getExpressionText();
}
}