cancel
Showing results for 
Search instead for 
Did you mean: 

Behavior about the ExclusiveGatewayActivityBehavior

michaelkira
Champ in-the-making
Champ in-the-making
Hi All

I found very strange behavior when the engine is dealing with the process like the attachment ExclusiveGatewayProcess.png.
[attachment=0]ExclusiveGatewayProcess.png[/attachment]
Which I want to do is that when first execution reach the Exclusive gateway, it trigger the parent execution to went on and destory itself( like the behavior in parallel gateway ), and when the second execution reach the Exclusive gateway, it just destory itself and will not trigger the Exclusive gateway for the second time
And I think this should be the correct way to run such process in the BPMN 2.0 standard.

So I added the following code in ExclusiveGatewayActivityBehavior to meet my requirement
The red one is my code, I want to get some help here is to hear the suggestion from the Activiti Engine Team if my modify is correct or not.
protected void leave(ActivityExecution execution) {
   
    if (log.isLoggable(Level.FINE)) {
      log.fine("Leaving activity '" + execution.getActivity().getId() + "'");
    }
   
    PvmTransition outgoingSeqFlow = null;
    String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
    Iterator<PvmTransition> transitionIterator = execution.getActivity().getOutgoingTransitions().iterator();
   
  if(!execution.isProcessInstance()){
      //the parent execution should be went on instead of the sub process
       ActivityExecution parentExecution = execution.getParent();
      if(parentExecution.isActive()){
         log.info("Parent execution: " + parentExecution.getId() + " is already active, abort the current execution: " + execution.getId() + " is enough");
         execution.end();
         //abort the current execution
         return;
      }
      else{
         log.info("Parent execution: " + parentExecution.getId() + " has been triggered by execution " + execution.getId());
         parentExecution.setActive(true);
         parentExecution.setConcurrent(false);
         execution.end();
         execution = parentExecution;
      }
   }

   
    while (outgoingSeqFlow == null && transitionIterator.hasNext()) {
      PvmTransition seqFlow = transitionIterator.next();
     
      Condition condition = (Condition) seqFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
      if ( (condition == null && (defaultSequenceFlow == null || !defaultSequenceFlow.equals(seqFlow.getId())) )
              || (condition != null && condition.evaluate(execution)) ) {
        if (log.isLoggable(Level.FINE)) {
          log.fine("Sequence flow '" + seqFlow.getId() + " '"
                  + "selected as outgoing sequence flow.");
        }
        outgoingSeqFlow = seqFlow;
      }
    }
   
    if (outgoingSeqFlow != null) {
      execution.take(outgoingSeqFlow);
    } else {
     
      if (defaultSequenceFlow != null) {
        PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
        if (defaultTransition != null) {
          execution.take(defaultTransition);
        } else {
          throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' not found");
        }
      } else {
        //No sequence flow could be found, not even a default one
        throw new ActivitiException("No outgoing sequence flow of the exclusive gateway '"
              + execution.getActivity().getId() + "' could be selected for continuing the process");
      }
    }
  }

Thank you very much for your help.

With Regards
2 REPLIES 2

trademak
Star Contributor
Star Contributor
Hi,

No this is not valid BPMN 2.0 with the description you gave.
When you have a parallel gateway it will produce 2 execution instances.
When each of these execution instances reach the exclusive gateway they will just proceed from there. There is no joining behaviour.
Maybe the inclusive gateway suites your needs?

Best regards,

michaelkira
Champ in-the-making
Champ in-the-making
Hi,

No this is not valid BPMN 2.0 with the description you gave.
When you have a parallel gateway it will produce 2 execution instances.
When each of these execution instances reach the exclusive gateway they will just proceed from there. There is no joining behaviour.
Maybe the inclusive gateway suites your needs?

Best regards,

Thank you very much for your reply.
I think  you are totally right about the behaviour since I've found the following definition from the BPMN 2-0 Specification BMI 09-05-03.pdf

"A converging Exclusive Gateway is used to merge alternative paths. Each incoming control flow token is
routed to the outgoing Sequence Flow without synchronization."

Best Regards