AnsweredAssumed Answered

Behavior about the ExclusiveGatewayActivityBehavior

Question asked by michaelkira on Jan 6, 2012
Latest reply on Jan 11, 2012 by michaelkira
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

Attachments

Outcomes