Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated
BoundaryCancelEventActivityBehavior 边界取消事件活动行为类
/**
* 边界取消事件活动行为类
*
* 取消边界事件(cancel boundary event),在事务取消时触发。当取消边界事件触发时,首先会中断当前范围的所有活动执行。
* 接下来,启动事务范围内所有有效的的补偿边界事件(compensation boundary event)。
* 补偿会同步执行,也就是说在离开事务前,边界事件会等待补偿完成。当补偿完成时,沿取消边界事件的任何出口顺序流离开事务子流程。
*
* 请注意:一个事务子流程只允许使用一个取消边界事件。
*
* 请注意:如果事务子流程中有嵌套的子流程,只会对成功完成的子流程触发补偿。
*
* 请注意:如果取消边界事件放置在具有多实例特性的事务子流程上,如果一个实例触发了取消,则边界事件将取消所有实例。
*
* @author Tijs Rademakers
*/
public class BoundaryCancelEventActivityBehavior extends BoundaryEventActivityBehavior {
private static final long serialVersionUID = 1L;
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();
CommandContext commandContext = Context.getCommandContext();
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
ExecutionEntityManager executionEntityManager = processEngineConfiguration.getExecutionEntityManager();
ExecutionEntity subProcessExecution = null;
// TODO:这是可以优化的。不需要对所有执行情况进行全面搜索
List<ExecutionEntity> processInstanceExecutions = executionEntityManager.findChildExecutionsByProcessInstanceId(execution.getProcessInstanceId());
for (ExecutionEntity childExecution : processInstanceExecutions) {
if (childExecution.getCurrentFlowElement() != null
&& childExecution.getCurrentFlowElement().getId().equals(boundaryEvent.getAttachedToRefId())) {
subProcessExecution = childExecution;
break;
}
}
if (subProcessExecution == null) {
throw new FlowableException("No execution found for sub process of boundary cancel event " + boundaryEvent.getId());
}
EventSubscriptionService eventSubscriptionService = processEngineConfiguration.getEventSubscriptionServiceConfiguration().getEventSubscriptionService