Search in sources :

Example 1 with TreeVisitor

use of org.camunda.bpm.engine.impl.tree.TreeVisitor in project camunda-bpm-platform by camunda.

the class CompensationUtil method collectCompensateEventSubscriptionsForScope.

/**
 * Collect all compensate event subscriptions for scope of given execution.
 */
public static List<EventSubscriptionEntity> collectCompensateEventSubscriptionsForScope(ActivityExecution execution) {
    final Map<ScopeImpl, PvmExecutionImpl> scopeExecutionMapping = execution.createActivityExecutionMapping();
    ScopeImpl activity = (ScopeImpl) execution.getActivity();
    // <LEGACY>: different flow scopes may have the same scope execution =>
    // collect subscriptions in a set
    final Set<EventSubscriptionEntity> subscriptions = new HashSet<EventSubscriptionEntity>();
    TreeVisitor<ScopeImpl> eventSubscriptionCollector = new TreeVisitor<ScopeImpl>() {

        @Override
        public void visit(ScopeImpl obj) {
            PvmExecutionImpl execution = scopeExecutionMapping.get(obj);
            subscriptions.addAll(((ExecutionEntity) execution).getCompensateEventSubscriptions());
        }
    };
    new FlowScopeWalker(activity).addPostVisitor(eventSubscriptionCollector).walkUntil(new ReferenceWalker.WalkCondition<ScopeImpl>() {

        @Override
        public boolean isFulfilled(ScopeImpl element) {
            Boolean consumesCompensationProperty = (Boolean) element.getProperty(BpmnParse.PROPERTYNAME_CONSUMES_COMPENSATION);
            return consumesCompensationProperty == null || consumesCompensationProperty == Boolean.TRUE;
        }
    });
    return new ArrayList<EventSubscriptionEntity>(subscriptions);
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) ArrayList(java.util.ArrayList) TreeVisitor(org.camunda.bpm.engine.impl.tree.TreeVisitor) ReferenceWalker(org.camunda.bpm.engine.impl.tree.ReferenceWalker) FlowScopeWalker(org.camunda.bpm.engine.impl.tree.FlowScopeWalker) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) HashSet(java.util.HashSet)

Example 2 with TreeVisitor

use of org.camunda.bpm.engine.impl.tree.TreeVisitor in project camunda-bpm-platform by camunda.

the class ExecutionEntity method dispatchEvent.

@Override
public void dispatchEvent(VariableEvent variableEvent) {
    final List<ExecutionEntity> execs = new ArrayList<ExecutionEntity>();
    new ExecutionTopDownWalker(this).addPreVisitor(new TreeVisitor<ExecutionEntity>() {

        @Override
        public void visit(ExecutionEntity obj) {
            if (!obj.getEventSubscriptions().isEmpty() && (obj.isInState(ActivityInstanceState.DEFAULT) || (!obj.getActivity().isScope()))) {
                // state is default or tree is compacted
                execs.add(obj);
            }
        }
    }).walkUntil();
    for (ExecutionEntity execution : execs) {
        execution.handleConditionalEventOnVariableChange(variableEvent);
    }
}
Also used : TreeVisitor(org.camunda.bpm.engine.impl.tree.TreeVisitor) CaseExecutionEntity(org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity) ArrayList(java.util.ArrayList) ExecutionTopDownWalker(org.camunda.bpm.engine.impl.tree.ExecutionTopDownWalker)

Aggregations

ArrayList (java.util.ArrayList)2 TreeVisitor (org.camunda.bpm.engine.impl.tree.TreeVisitor)2 HashSet (java.util.HashSet)1 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)1 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)1 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)1 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)1 ExecutionTopDownWalker (org.camunda.bpm.engine.impl.tree.ExecutionTopDownWalker)1 FlowScopeWalker (org.camunda.bpm.engine.impl.tree.FlowScopeWalker)1 ReferenceWalker (org.camunda.bpm.engine.impl.tree.ReferenceWalker)1