在flowable6.3以后的版本中,支持了MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION事件,这个事件顾名思义就是在多实例节点完成的时候,flowable引擎去发布这个完成事件信号。该事件同其他的事件一样,定义在FlowableEngineEventType.java类中。
关于多实例所支持的事件类型如下所示:
MULTI_INSTANCE_ACTIVITY_COMPLETED(多实例完成),
MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION(多实例正常完成),
MULTI_INSTANCE_ACTIVITY_CANCELLED(多实例取消),
不管是什么事件,我们在开发的过程中往往只会关心事件的类型以及事件所产生的数据而已。现在既然我们知道了新增的事件类型是
MULTI_INSTANCE_ACTIVITY_COMPLETED,
MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION,
MULTI_INSTANCE_ACTIVITY_CANCELLED,
三个,那接下来,我们看一下这些事件所对应的事件处理类,具体细节在AbstractFlowableEngineEventListener类中如下所示: case MULTI_INSTANCE_ACTIVITY_COMPLETED:
multiInstanceActivityCompleted((FlowableMultiInstanceActivityCompletedEvent) flowableEngineEvent);
break;
case MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION:
multiInstanceActivityCompletedWithCondition((FlowableMultiInstanceActivityCompletedEvent) flowableEngineEvent);
break;
case MULTI_INSTANCE_ACTIVITY_CANCELLED:
multiInstanceActivityCancelled((FlowableMultiInstanceActivityCancelledEvent) flowableEngineEvent)
protected void multiInstanceActivityCompleted(FlowableMultiInstanceActivityEvent event) {}
protected void multiInstanceActivityCompleted(FlowableMultiInstanceActivityCompletedEvent event) {}
protected void multiInstanceActivityCompletedWithCondition(FlowableMultiInstanceActivityCompletedEvent event) {}
protected void multiInstanceActivityCancelled(FlowableMultiInstanceActivityCancelledEvent event) {}
MULTI_INSTANCE_ACTIVITY_COMPLETED事件对应的事件类为:FlowableMultiInstanceActivityCompletedEvent
MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION事件对应的事件类为:FlowableMultiInstanceActivityCompletedEvent。
MULTI_INSTANCE_ACTIVITY_CANCELLED事件对应的事件类为:FlowableMultiInstanceActivityCancelledEvent。
由上面的源码可以知道 MULTI_INSTANCE_ACTIVITY_COMPLETED与MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION事件对应的事件类是相同的,都是FlowableMultiInstanceActivityCompletedEvent。
MULTI_INSTANCE_ACTIVITY_CANCELLED事件对应的事件类为:FlowableMultiInstanceActivityCancelledEvent。
通过FlowableMultiInstanceActivityCompletedEvent类我们可以获取到的属性信息如下:
numberOfInstances(多实例的个数)
numberOfActiveInstances(多实例活动的个数)
numberOfCompletedInstances(多实例已经完成的活动个数)
关于更多的事件以及事件监听器可以参考Activiti权威指南一书 。