cancel
Showing results for 
Search instead for 
Did you mean: 

Loop issue

jpgouin
Champ on-the-rise
Champ on-the-rise
Hi ,
I'm trying to make a while loop on a workflow using TimerCatchEvent. (see attached bpmn)
The workflow only work once and does not restart the FTP or the  MessageQ Script task.
However it also do not go into the last Script task just before the end.

Maybe I misconfigured the TimerCatchingEvent …

Thanks !
1 ACCEPTED ANSWER

jpgouin
Champ on-the-rise
Champ on-the-rise
I don't think so, can you tell me what I have to add in the config file ?

Edit : it's ok I found it in the user doc . I will try with this . Thanks !

Edit2 : It worked thanks !

I have another question, on the script task FTP, I've attached a listener which start another process that I have deploy in the repositoryService.
How can I avoid the listener to block the execution of the script task FTP (because of <code> runtimeService.startProcessInstanceByKey </code> ?

View answer in original post

14 REPLIES 14

anilmann
Confirmed Champ
Confirmed Champ
I think you need to add default flow on both exclusive gateways.
This should resolve your problem.

For your reference, your BPMN file should have this line.
<code>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="flow9"></exclusiveGateway>
<exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway" default="flow15"></exclusiveGateway>
</code>
Watch for default attribute.

jpgouin
Champ on-the-rise
Champ on-the-rise
Thanks for the reply !

I just tried and it didn't work.

Edit: here is the updated bpmn

One more point. Since flow9 is now default transition, you need to remove the condition on "flow9" sequence.
It should work after that.

anilmann
Confirmed Champ
Confirmed Champ
Please use below bpmn. It worked for me.
<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/test">
  <process id="Process_message_pooling" name="Process_message_pooling" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <scriptTask id="config" name="Configuration" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>System.out.println("System Started and configrured !!")
execution.setVariable("workflow_stop",false)
</script>
    </scriptTask>
    <scriptTask id="ftp" name="FTP" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>System.out.println("FTP activated"+workflow_stop)
file = "ERROR on 192.168.10.21 Test! "
if(!file.isEmpty())
{
execution.setVariable("input_file",file);
}
</script>
    </scriptTask>
    <scriptTask id="messageQ" name="MessageQ" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>System.out.println("MessageQ activated")
/*
MessageQClient client = MessageQClient.getInstance("localhost","sendMessageQ",new WorkflowListener() {
   
    @Override
    public Serializable fireEvent(Serializable object) {
     // TODO Auto-generated method stub
   
    }
   });
*/</script>
    </scriptTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="config"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="messageQ" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="ftp" targetRef="exclusivegateway2"></sequenceFlow>
    <intermediateCatchEvent id="timerintermediatecatchevent1" name="TimerCatchEvent">
      <timerEventDefinition>
        <timeDuration>PT5S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <intermediateCatchEvent id="timerintermediatecatchevent2" name="TimerCatchEvent">
      <timerEventDefinition>
        <timeDuration>PT5S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="flow9" sourceRef="exclusivegateway1" targetRef="timerintermediatecatchevent1"></sequenceFlow>
    <sequenceFlow id="flow10" sourceRef="timerintermediatecatchevent1" targetRef="messageQ"></sequenceFlow>
    <sequenceFlow id="flow11" sourceRef="exclusivegateway2" targetRef="parallelgateway2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${workflow_stop == true}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow12" sourceRef="exclusivegateway1" targetRef="parallelgateway2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${workflow_stop == true}]]></conditionExpression>
    </sequenceFlow>
    <scriptTask id="scripttask1" name="Script Task" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>System.out.println("Stopping System");</script>
    </scriptTask>
    <sequenceFlow id="flow13" sourceRef="parallelgateway2" targetRef="scripttask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow14" sourceRef="scripttask1" targetRef="endevent1"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="flow9"></exclusiveGateway>
    <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway" default="flow15"></exclusiveGateway>
    <sequenceFlow id="flow15" sourceRef="exclusivegateway2" targetRef="timerintermediatecatchevent2"></sequenceFlow>
    <sequenceFlow id="flow16" sourceRef="timerintermediatecatchevent2" targetRef="ftp"></sequenceFlow>
    <sequenceFlow id="flow17" sourceRef="config" targetRef="parallelgateway1"></sequenceFlow>
    <sequenceFlow id="flow18" sourceRef="parallelgateway1" targetRef="ftp"></sequenceFlow>
    <sequenceFlow id="flow19" sourceRef="parallelgateway1" targetRef="messageQ"></sequenceFlow>
    <parallelGateway id="parallelgateway1" name="Exclusive Gateway"></parallelGateway>
    <parallelGateway id="parallelgateway2" name="Exclusive Gateway"></parallelGateway>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_Process_message_pooling">
    <bpmndi:BPMNPlane bpmnElement="Process_message_pooling" id="BPMNPlane_Process_message_pooling">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="60.0" y="270.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="config" id="BPMNShape_config">
        <omgdc:Bounds height="55.0" width="105.0" x="210.0" y="260.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="ftp" id="BPMNShape_ftp">
        <omgdc:Bounds height="55.0" width="105.0" x="530.0" y="110.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="messageQ" id="BPMNShape_messageQ">
        <omgdc:Bounds height="55.0" width="105.0" x="530.0" y="380.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="timerintermediatecatchevent1" id="BPMNShape_timerintermediatecatchevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="660.0" y="480.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="timerintermediatecatchevent2" id="BPMNShape_timerintermediatecatchevent2">
        <omgdc:Bounds height="35.0" width="35.0" x="670.0" y="30.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1">
        <omgdc:Bounds height="55.0" width="105.0" x="860.0" y="260.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="1010.0" y="270.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="720.0" y="387.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="720.0" y="117.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="370.0" y="267.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="800.0" y="267.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="95.0" y="287.0"></omgdi:waypoint>
        <omgdi:waypoint x="210.0" y="287.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="635.0" y="407.0"></omgdi:waypoint>
        <omgdi:waypoint x="720.0" y="407.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="635.0" y="137.0"></omgdi:waypoint>
        <omgdi:waypoint x="720.0" y="137.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
        <omgdi:waypoint x="740.0" y="427.0"></omgdi:waypoint>
        <omgdi:waypoint x="739.0" y="497.0"></omgdi:waypoint>
        <omgdi:waypoint x="695.0" y="497.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
        <omgdi:waypoint x="660.0" y="497.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="497.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="435.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
        <omgdi:waypoint x="760.0" y="137.0"></omgdi:waypoint>
        <omgdi:waypoint x="820.0" y="137.0"></omgdi:waypoint>
        <omgdi:waypoint x="820.0" y="267.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
        <omgdi:waypoint x="760.0" y="407.0"></omgdi:waypoint>
        <omgdi:waypoint x="820.0" y="407.0"></omgdi:waypoint>
        <omgdi:waypoint x="820.0" y="307.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
        <omgdi:waypoint x="840.0" y="287.0"></omgdi:waypoint>
        <omgdi:waypoint x="860.0" y="287.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
        <omgdi:waypoint x="965.0" y="287.0"></omgdi:waypoint>
        <omgdi:waypoint x="1010.0" y="287.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
        <omgdi:waypoint x="740.0" y="117.0"></omgdi:waypoint>
        <omgdi:waypoint x="740.0" y="47.0"></omgdi:waypoint>
        <omgdi:waypoint x="705.0" y="47.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16">
        <omgdi:waypoint x="670.0" y="47.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="47.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="110.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow17" id="BPMNEdge_flow17">
        <omgdi:waypoint x="315.0" y="287.0"></omgdi:waypoint>
        <omgdi:waypoint x="370.0" y="287.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow18" id="BPMNEdge_flow18">
        <omgdi:waypoint x="390.0" y="267.0"></omgdi:waypoint>
        <omgdi:waypoint x="390.0" y="137.0"></omgdi:waypoint>
        <omgdi:waypoint x="530.0" y="137.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow19" id="BPMNEdge_flow19">
        <omgdi:waypoint x="390.0" y="307.0"></omgdi:waypoint>
        <omgdi:waypoint x="390.0" y="407.0"></omgdi:waypoint>
        <omgdi:waypoint x="530.0" y="407.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
</code?

jpgouin
Champ on-the-rise
Champ on-the-rise
I used your model and it didn't work for me either.

So maybe it's in the execution of the model.
I've generated a unit test (with Eclipse) for the model and  this is the output :

<code>
nov. 23, 2016 5:47:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFOS: Loading XML bean definitions from class path resource [activiti.cfg.xml]
nov. 23, 2016 5:47:09 PM org.activiti.engine.impl.db.DbSqlSession executeSchemaResource
INFOS: performing create on engine with resource org/activiti/db/create/activiti.h2.create.engine.sql
nov. 23, 2016 5:47:09 PM org.activiti.engine.impl.db.DbSqlSession executeSchemaResource
INFOS: performing create on history with resource org/activiti/db/create/activiti.h2.create.history.sql
nov. 23, 2016 5:47:09 PM org.activiti.engine.impl.db.DbSqlSession executeSchemaResource
INFOS: performing create on identity with resource org/activiti/db/create/activiti.h2.create.identity.sql
nov. 23, 2016 5:47:09 PM org.activiti.engine.impl.ProcessEngineImpl <init>
INFOS: ProcessEngine default created
nov. 23, 2016 5:47:09 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFOS: Processing resource Process_message_pooling.bpmn20.xml
System Started and configrured !!
FTP activatedfalse
MessageQ activated
id 5 Process_message_pooling:1:4
</code>

and this is the generated unit test :

<java>
package org.activiti.designer.test;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;
import java.io.FileInputStream;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.ActivitiRule;
import org.junit.Rule;
import org.junit.Test;

public class ProcessTestProcessmessagepooling {

private String filename = "C:\\Users\\gouin\\Desktop\\LOGGUI\\Work\\Workspace\\PachaWebGui\\testAcr\\src\\main\\resources\\diagrams\\SendPooling2.bpmn";

@Rule
public ActivitiRule activitiRule = new ActivitiRule();

@Test
public void startProcess() throws Exception {
  RepositoryService repositoryService = activitiRule.getRepositoryService();
  repositoryService.createDeployment().addInputStream("Process_message_pooling.bpmn20.xml",
    new FileInputStream(filename)).deploy();
  RuntimeService runtimeService = activitiRule.getRuntimeService();
  Map<String, Object> variableMap = new HashMap<String, Object>();
  variableMap.put("name", "Activiti");
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_message_pooling", variableMap);
  assertNotNull(processInstance.getId());
  System.out.println("id " + processInstance.getId() + " "
    + processInstance.getProcessDefinitionId());
}
}
</java>

anilmann
Confirmed Champ
Confirmed Champ
Actually its problem with your unit test class. It triggers the run but as soon as it return back from workfow (and it will due to intermediate timer catching event), it terminates the JVM.

Please add below code to wait till the process actually complete.

<java>
while (true) {
   Thread.sleep(5000);
   System.out.println(activitiRule.getManagementService().createJobQuery().list());
   if (activitiRule.getManagementService().createJobQuery().list().isEmpty())
    break;
  }
</java>

jpgouin
Champ on-the-rise
Champ on-the-rise
Ok thanks i will try tomorrow.

Edit :
I tried your solution and come to this problem.
The test is not terminated as expected however this is the output :
<code>
System Started and configrured !!
FTP activatedfalse
MessageQ activated
[JobEntity [id=22], JobEntity [id=27]]
[JobEntity [id=22], JobEntity [id=27]]
[JobEntity [id=22], JobEntity [id=27]]
</code>

The FTP and the MessageQ are not re-executed…

According to me your test will never complete because your process never completes. You have to complete your process. I see its infinite loop in your process.

The while loop that I provided will stay your test alive till process gets completed.

warper
Star Contributor
Star Contributor
Do you have JobExecutor enabled or AsyncJobExecutor enables/activated in activiti config?