AnsweredAssumed Answered

Parallel SubProcess and Boundaryevents

Question asked by heri on Aug 6, 2015
Latest reply on Aug 6, 2015 by vasile.dirla
I am new to activiti and trying to create a parallel subprocess with a timeout and an error boundary event. I have three problems which I can't seem to solve on my own:

1. despite setting isSequential="true" in the multiInstanceLoopCharacteristics element, the SubProcesses are executed sequentially.
2. the timeout boundary event is never triggered.
3. despite setting cancelActivity=true" in the boundaryElement element, the subprocess is not cancelled when an errorEvent is thrown. After all subprocesses have finished, I get the following exception:


org.activiti.engine.impl.pvm.PvmException: already taking a transition
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:443)


My script looks as follows (should be importable in a unit-test):


<?xml version="1.0" encoding="UTF-8"?>

<definitions id="definitions"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn"
             targetNamespace="Examples" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="
             http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/2.0/20100501/BPMN20.xsd">


    <process id="testProcess" name="Test process">

        <startEvent id="start"/>
        <sequenceFlow sourceRef="start" targetRef="listTask"/>

        <scriptTask id="listTask" name="Create List" scriptFormat="groovy">
            <script>
                out:println "Task 1: creating list"
                def list = []
                list.add("item1")
                list.add("item2")
                execution.setVariable("list", list)
            </script>
        </scriptTask>


        <sequenceFlow sourceRef="listTask" targetRef="decisionSubprocess"/>

        <subProcess id="decisionSubprocess" name="Subprocess">
            <multiInstanceLoopCharacteristics
                    isSequential="false" activiti:collection="${list}"
                    activiti:elementVariable="item">
            </multiInstanceLoopCharacteristics>

            <startEvent id="decisionStart"/>
            <sequenceFlow sourceRef="decisionStart" targetRef="decisionTask"/>
            <scriptTask id="decisionTask" name="Decide" scriptFormat="groovy">
                <script>
                    sleep(3000)
                    out:println "List " + execution.getVariable("item")
                    execution.setVariable("accepted", 0)
                </script>
            </scriptTask>

            <sequenceFlow sourceRef="decisionTask" targetRef="notificationAccepted" />

            <exclusiveGateway id="notificationAccepted"/>
            <sequenceFlow sourceRef="notificationAccepted" targetRef="changesRejectedEvent">
                <conditionExpression>
                    ${accepted == 0}
                </conditionExpression>
            </sequenceFlow>

            <endEvent id="changesRejectedEvent">
                <errorEventDefinition errorRef="changesRejected"/>
            </endEvent>

            <sequenceFlow sourceRef="notificationAccepted" targetRef="decisionEnd">
                <conditionExpression>
                    ${accepted == 1}
                </conditionExpression>
            </sequenceFlow>

            <endEvent id="decisionEnd"/>
        </subProcess>
        <boundaryEvent id="timeoutEvent" attachedToRef="decisionSubprocess" cancelActivity="true">
            <timerEventDefinition>
                <timeDuration>PT2S</timeDuration>
            </timerEventDefinition>
        </boundaryEvent>

        <boundaryEvent id="errorEvent" attachedToRef="decisionSubprocess" cancelActivity="true">
            <errorEventDefinition errorRef="changesRejected"/>
        </boundaryEvent>

        <sequenceFlow sourceRef="timeoutEvent" targetRef="timeout"/>

        <scriptTask id="timeout" name="Post Timeout" scriptFormat="groovy">
            <script>
                out:println "Timeout occurred."
            </script>
        </scriptTask>

        <sequenceFlow sourceRef="errorEvent" targetRef="error"/>

        <scriptTask id="error" name="Post Decline" scriptFormat="groovy">
            <script>
                out:println "Some declined."
            </script>
        </scriptTask>

        <sequenceFlow sourceRef="error" targetRef="end"/>

        <sequenceFlow sourceRef="timeout" targetRef="end"/>

        <sequenceFlow sourceRef="decisionSubprocess"
                      targetRef="normalEnd"/>

        <scriptTask id="normalEnd" name="Post Accepted" scriptFormat="groovy">
            <script>
                out:println "All accepted."
            </script>
        </scriptTask>

        <sequenceFlow targetRef="end"
                      sourceRef="normalEnd"/>

        <endEvent id="end"/>

    </process>

</definitions>


Would be grateful if someone could point out the errors I made.

Outcomes