cancel
Showing results for 
Search instead for 
Did you mean: 

Execution Query

kayj
Champ in-the-making
Champ in-the-making
Hi,

I've got a quite simple example:


ProcessEngine processEngine = ProcessEngineConfiguration
        .createStandaloneInMemProcessEngineConfiguration()
        .buildProcessEngine();

RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();

repositoryService.createDeployment().addClasspathResource( "diagrams/automationProcess.bpmn20.xml").deploy();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey( "automationProcessId");
      
List<Execution> executions = runtimeService.createExecutionQuery().list();


The process instance gets started correctly, 2 tasks are executed until a boundary event is reached which is waiting for a signal. The documentation says that:
"An Execution represents a 'path of execution' in a process instance. Note that a ProcessInstance also is an execution." (http://activiti.org/javadocs/org/activiti/engine/runtime/Execution.html)

Therefore I would assume that the length of the executions list must be 1 (due to the processInstance that was started). But it is empty. Even though the process is waiting for a signal, the execution should be still available or am I wrong?

If I query the historic instances instead the list returns 1.
Furthermore I figured out that the length of the execution list is 1 if the boundary event is removed.

Could someone try to explain this behaviour?

4 REPLIES 4

smirzai
Champ on-the-rise
Champ on-the-rise
It seems that the process is finished and not waiting. can you send the process ?

kayj
Champ in-the-making
Champ in-the-making
This is the complete xml of the process

<code>
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <signal id="continueSignal" name="continueSignal"></signal>
  <process id="automationProcessId" isExecutable="true">
    <extensionElements>
      <activiti:executionListener event="start" class="org.cybercon.automation.listeners.DebugListener"></activiti:executionListener>
      <activiti:executionListener event="end" class="org.cybercon.automation.listeners.DebugListener"></activiti:executionListener>
    </extensionElements>
    <startEvent id="StartId"></startEvent>
    <scriptTask id="initialize" name="Initialize" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <documentation>* Check if data is consistent
    * write script names to VAR map (concatenated list) scriptNamesList</documentation>
      <extensionElements>
        <activiti:executionListener event="end" class="org.cybercon.automation.listeners.InitializationListener"></activiti:executionListener>
      </extensionElements>
      <script>out.println "Initialize";
String[] scriptNamesList = ["script1", "script2", "script3"];
execution.setVariable( "scriptNamesListTest", scriptNamesList);
execution.setVariable( "currentScriptNameIndex", -1);</script>
    </scriptTask>
    <sequenceFlow id="flow1" sourceRef="StartId" targetRef="initialize"></sequenceFlow>
    <scriptTask id="automateSubtaskX" name="Automate Subtask X" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <documentation>read next script name from VAR map scriptNamesList
    according to currentSubtaskIndex (or use push/pop stack)</documentation>
      <extensionElements>
        <activiti:executionListener event="start" class="org.cybercon.automation.listeners.AutomateSubtaskListener"></activiti:executionListener>
        <activiti:executionListener event="end" class="org.cybercon.automation.listeners.AutomateSubtaskListener"></activiti:executionListener>
      </extensionElements>
      <script>out.println "Automate Subtask";
out.println scriptNamesList.size();</script>
    </scriptTask>
    <sequenceFlow id="flow2" sourceRef="initialize" targetRef="automateSubtaskX"></sequenceFlow>
    <exclusiveGateway id="automaticExecutionGateway" name="Success Gateway">
      <documentation>success: if no error occured during execution
    failure: if the subtask has not been executed without failures</documentation>
    </exclusiveGateway>
    <exclusiveGateway id="finishGateway" name="Exclusive Gateway">
      <documentation>Finished: if sript list in VAR map subtaskList is
    empty
    Not finished: if the scriptNamesList in the VAR map is not empty</documentation>
    </exclusiveGateway>
    <sequenceFlow id="successAutomatic" name="Success" sourceRef="automaticExecutionGateway" targetRef="finishGateway">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[automationResult == 0]]></conditionExpression>
    </sequenceFlow>
    <userTask id="ManualExecution" name="Manual Execution">
      <documentation>Employee needs to execute the failed subtask manually</documentation>
    </userTask>
    <sequenceFlow id="failureAutomatic" name="Failure" sourceRef="automaticExecutionGateway" targetRef="ManualExecution">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[automationResult > 0]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="manualExecutionGateway" name="Exclusive Gateway">
      <documentation>success: if the manual execution succeeds
    failure: if manual execution fails, the process can't be automated.
    Escalation.</documentation>
    </exclusiveGateway>
    <endEvent id="endevent1" name="End"></endEvent>
    <endEvent id="errorendevent1" name="ErrorEnd">
      <errorEventDefinition errorRef="myErrorEndEvent"></errorEventDefinition>
    </endEvent>
    <sequenceFlow id="failureManual" name="Failure" sourceRef="manualExecutionGateway" targetRef="errorendevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[automationResult > 0]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="finishedProcess" name="Finished" sourceRef="finishGateway" targetRef="endevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[subtaskArray.size() == 0]]></conditionExpression>
    </sequenceFlow>
    <scriptTask id="incrementTaskId" name="Increment Task ID" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <documentation>increment currentSubtaskId int the VAR map</documentation>
      <script>out.println "Increment Task ID";</script>
    </scriptTask>
    <sequenceFlow id="notFinishedProcess" name="Not Finished" sourceRef="finishGateway" targetRef="incrementTaskId">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[scriptNamesList.size() > 0]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="incrementTaskId" targetRef="automateSubtaskX"></sequenceFlow>
    <sequenceFlow id="successManual" name="Success" sourceRef="manualExecutionGateway" targetRef="finishGateway">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[automationResult == 0]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="ManualExecution" targetRef="manualExecutionGateway"></sequenceFlow>
    <boundaryEvent id="boundarysignal1" name="Message" attachedToRef="automateSubtaskX" cancelActivity="true">
      <signalEventDefinition signalRef="continueSignal"></signalEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="flow3" sourceRef="boundarysignal1" targetRef="automaticExecutionGateway">
      <extensionElements>
        <activiti:executionListener event="take" class="org.cybercon.automation.listeners.DebugListener"></activiti:executionListener>
      </extensionElements>
    </sequenceFlow>
    <textAnnotation id="textannotation1">
      <text>Write script names of subtasks to VAR map.</text>
    </textAnnotation>
    <association id="association1" sourceRef="textannotation1" targetRef="initialize"></association>
    <textAnnotation id="textannotation2">
      <text>* Read script name from VAR map (next to be executed).
* trigger Tplan execution on client
* wait for result before proceeding</text>
    </textAnnotation>
    <association id="association2" sourceRef="textannotation2" targetRef="automateSubtaskX"></association>
    <textAnnotation id="textannotation3">
      <text>Manual execution of subtask if automation failed.</text>
    </textAnnotation>
    <association id="association3" sourceRef="textannotation3" targetRef="ManualExecution"></association>
    <textAnnotation id="textannotation4">
      <text>If execution of the whole process isn't finished, the next subtask is executed. Pop executed script name from list or increment index.</text>
    </textAnnotation>
    <association id="association4" sourceRef="textannotation4" targetRef="incrementTaskId"></association>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_automationProcessId">
    <bpmndi:BPMNPlane bpmnElement="automationProcessId" id="BPMNPlane_automationProcessId">
      <bpmndi:BPMNShape bpmnElement="StartId" id="BPMNShape_StartId">
        <omgdc:Bounds height="35.0" width="35.0" x="45.0" y="235.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="initialize" id="BPMNShape_initialize">
        <omgdc:Bounds height="55.0" width="105.0" x="170.0" y="225.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="automateSubtaskX" id="BPMNShape_automateSubtaskX">
        <omgdc:Bounds height="55.0" width="145.0" x="350.0" y="225.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="automaticExecutionGateway" id="BPMNShape_automaticExecutionGateway">
        <omgdc:Bounds height="40.0" width="40.0" x="640.0" y="232.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="finishGateway" id="BPMNShape_finishGateway">
        <omgdc:Bounds height="40.0" width="40.0" x="810.0" y="232.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="ManualExecution" id="BPMNShape_ManualExecution">
        <omgdc:Bounds height="55.0" width="105.0" x="608.0" y="360.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="manualExecutionGateway" id="BPMNShape_manualExecutionGateway">
        <omgdc:Bounds height="40.0" width="40.0" x="810.0" y="368.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="926.0" y="235.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="errorendevent1" id="BPMNShape_errorendevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="930.0" y="370.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="incrementTaskId" id="BPMNShape_incrementTaskId">
        <omgdc:Bounds height="55.0" width="105.0" x="608.0" y="60.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="boundarysignal1" id="BPMNShape_boundarysignal1">
        <omgdc:Bounds height="30.0" width="30.0" x="480.0" y="238.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="textannotation1" id="BPMNShape_textannotation1">
        <omgdc:Bounds height="50.0" width="100.0" x="71.0" y="368.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="textannotation2" id="BPMNShape_textannotation2">
        <omgdc:Bounds height="71.0" width="220.0" x="290.0" y="380.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="textannotation3" id="BPMNShape_textannotation3">
        <omgdc:Bounds height="50.0" width="100.0" x="550.0" y="480.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="textannotation4" id="BPMNShape_textannotation4">
        <omgdc:Bounds height="60.0" width="247.0" x="794.0" y="11.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="80.0" y="252.0"></omgdi:waypoint>
        <omgdi:waypoint x="170.0" y="252.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="275.0" y="252.0"></omgdi:waypoint>
        <omgdi:waypoint x="350.0" y="252.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="successAutomatic" id="BPMNEdge_successAutomatic">
        <omgdi:waypoint x="680.0" y="252.0"></omgdi:waypoint>
        <omgdi:waypoint x="810.0" y="252.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="12.0" width="100.0" x="690.0" y="252.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="failureAutomatic" id="BPMNEdge_failureAutomatic">
        <omgdi:waypoint x="660.0" y="272.0"></omgdi:waypoint>
        <omgdi:waypoint x="660.0" y="360.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="12.0" width="33.0" x="670.0" y="319.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="failureManual" id="BPMNEdge_failureManual">
        <omgdi:waypoint x="850.0" y="388.0"></omgdi:waypoint>
        <omgdi:waypoint x="930.0" y="387.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="12.0" width="33.0" x="860.0" y="388.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="finishedProcess" id="BPMNEdge_finishedProcess">
        <omgdi:waypoint x="850.0" y="252.0"></omgdi:waypoint>
        <omgdi:waypoint x="926.0" y="252.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="12.0" width="41.0" x="860.0" y="252.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="notFinishedProcess" id="BPMNEdge_notFinishedProcess">
        <omgdi:waypoint x="830.0" y="232.0"></omgdi:waypoint>
        <omgdi:waypoint x="829.0" y="87.0"></omgdi:waypoint>
        <omgdi:waypoint x="713.0" y="87.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="12.0" width="61.0" x="840.0" y="171.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="608.0" y="87.0"></omgdi:waypoint>
        <omgdi:waypoint x="422.0" y="87.0"></omgdi:waypoint>
        <omgdi:waypoint x="422.0" y="225.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="successManual" id="BPMNEdge_successManual">
        <omgdi:waypoint x="830.0" y="368.0"></omgdi:waypoint>
        <omgdi:waypoint x="830.0" y="272.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="12.0" width="43.0" x="831.0" y="309.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="713.0" y="387.0"></omgdi:waypoint>
        <omgdi:waypoint x="810.0" y="388.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="510.0" y="253.0"></omgdi:waypoint>
        <omgdi:waypoint x="640.0" y="252.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="association1" id="BPMNEdge_association1">
        <omgdi:waypoint x="121.0" y="368.0"></omgdi:waypoint>
        <omgdi:waypoint x="222.0" y="280.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="association2" id="BPMNEdge_association2">
        <omgdi:waypoint x="400.0" y="380.0"></omgdi:waypoint>
        <omgdi:waypoint x="422.0" y="280.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="association3" id="BPMNEdge_association3">
        <omgdi:waypoint x="600.0" y="480.0"></omgdi:waypoint>
        <omgdi:waypoint x="660.0" y="415.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="association4" id="BPMNEdge_association4">
        <omgdi:waypoint x="794.0" y="41.0"></omgdi:waypoint>
        <omgdi:waypoint x="660.0" y="60.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
</code>

jbarrez
Star Contributor
Star Contributor
There is a whole lot optimization going on to get the amount of executions as small as possible. So don't try to logically see how many you expect, the engine does optimize and recycle quite a few of them.

kayj
Champ in-the-making
Champ in-the-making
Could you explain how to send a signal to a specific execution (e.g.   <code>mProcessEngine.getRuntimeService().signalEventReceived("continueSignal", executionId);</code>) if the execution is no more available (as mentioned before)? I did not find a solution to this problem yet.