Problems with understanding signals

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
strauss
Member II

Problems with understanding signals

Hi everyone!

I have a problem with signals in activiti. Please help me.

My case: i have two simple processes (p1 and p2)

p1: start -> catchSignal -> end

p2: start -> throwSignal (async) -> end

First, i start process p1. Second, i start process p2. They launched in separates java threads.

This is how it works in my case (based on RuntimeService events):

>>> [start_p1][ACTIVITY_STARTED]
>>> [start_p1][ACTIVITY_COMPLETED]
>>> [signal_catch_p1][ACTIVITY_STARTED]
>>> [start_p2][ACTIVITY_STARTED]
>>> [start_p2][ACTIVITY_COMPLETED]
>>> [signal_throw_p2][ACTIVITY_STARTED]
>>> [signal_catch_p1][ACTIVITY_SIGNALED]
>>> [signal_throw_p2][ACTIVITY_COMPLETED]
>>> [end_p2][ACTIVITY_STARTED]
>>> [end_p2][ACTIVITY_COMPLETED]

I can't understand, why process p1 not ended? Signal_catch_p1 was signaled... and nothing more. I expected signal_catch_p1 to be completed and process go to end.

Java code:

public void test() {
          String bpmnDbPath = "E:\\activiti-db;DB_CLOSE_DELAY=1000";

          ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
          cfg = cfg.setJdbcDriver("org.h2.Driver").setJdbcUrl("jdbc:h2:" + bpmnDbPath).setJdbcUsername("sa")
                     .setJdbcPassword("").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
          ManagedAsyncJobExecutor jobExecutor = new ManagedAsyncJobExecutor();
          jobExecutor.setAutoActivate(true);
          jobExecutor.setCorePoolSize(3);
          jobExecutor.setMaxPoolSize(20);
          cfg.setAsyncExecutor(jobExecutor);
          cfg.setAsyncExecutorActivate(true);

          ProcessEngine processEngine = cfg.buildProcessEngine();
          processEngine.getRuntimeService().addEventListener(new ActivitiEventListener() {
               @Override
               public void onEvent(ActivitiEvent activitiEvent) {
                    if (activitiEvent instanceof ActivitiActivityEventImpl) {
                         ActivitiActivityEventImpl aaeImpl = (ActivitiActivityEventImpl) activitiEvent;
                         String activitiId = aaeImpl.getActivityId();
                         String type = activitiEvent.getType().toString();
                         System.out.println(String.format(">>> [%s][%s]", activitiId, type));
                    }
               }

               @Override
               public boolean isFailOnException() {
                    return true;
               }
          });

          String p1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                         "<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\">\n" +
                         "  <signal id=\"UnknownSignal\" name=\"UnknownSignal\"></signal>\n" +
                         "  <process id=\"p1\" isExecutable=\"true\">\n" +
                         "    <endEvent id=\"end_p1\"></endEvent>\n" +
                         "    <startEvent id=\"start_p1\"></startEvent>\n" +
                         "    <intermediateCatchEvent id=\"signal_catch_p1\">\n" +
                         "      <signalEventDefinition signalRef=\"UnknownSignal\"></signalEventDefinition>\n" +
                         "    </intermediateCatchEvent>\n" +
                         "    <sequenceFlow sourceRef=\"start_p1\" targetRef=\"signal_catch_p1\"></sequenceFlow>\n" +
                         "    <sequenceFlow sourceRef=\"signal_catch_p1\" targetRef=\"end_p1\"></sequenceFlow>\n" +
                         "  </process>\n" +
                         "</definitions>";

          String p2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                         "<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\">\n" +
                         "  <signal id=\"UnknownSignal\" name=\"UnknownSignal\"></signal>\n" +
                         "  <process id=\"p2\" isExecutable=\"true\">\n" +
                         "    <endEvent id=\"end_p2\"></endEvent>\n" +
                         "    <startEvent id=\"start_p2\"></startEvent>\n" +
                         "    <intermediateThrowEvent id=\"signal_throw_p2\">\n" +
                         "      <signalEventDefinition signalRef=\"UnknownSignal\" activiti:async=\"true\"></signalEventDefinition>\n" +
                         "    </intermediateThrowEvent>\n" +
                         "    <sequenceFlow sourceRef=\"start_p2\" targetRef=\"signal_throw_p2\"></sequenceFlow>\n" +
                         "    <sequenceFlow sourceRef=\"signal_throw_p2\" targetRef=\"end_p2\"></sequenceFlow>\n" +
                         "  </process>\n" +
                         "</definitions>";

          deployAndStartProcess(processEngine, p1, "p1");
          deployAndStartProcess(processEngine, p2, "p2");
     }

     private void deployAndStartProcess(ProcessEngine processEngine, String bpmnProcess, String processId) {
          try {
               RuntimeService runtimeService = processEngine.getRuntimeService();
               RepositoryService repositoryService = processEngine.getRepositoryService();
               DeploymentBuilder db = repositoryService.createDeployment();

               String deploymentId = processId + ".bpmn20.xml";

               db.addString(deploymentId, bpmnProcess).deploy();

               Runnable r = () -> runtimeService.startProcessInstanceByKey(processId);
               (new Thread(r)).start();
          } catch (Exception e) {
               System.out.println(e.getMessage());
          }
     }
4 Replies
mdtabrezmca
Established Member II

Re: Problems with understanding signals

Did you checked the event logs at this table in activiti act_evt_log.Because when i see the similar application running using activiti app(not from the java code) it is able to end the process p1 in my case.below is the event logs from my activiti databse. also please find the attachment of my APP.

 25VARIABLE_CREATEDsignal_catch_process:1:2500725022250222018-07-31 12:16:05.0951...1
 26HISTORIC_PROCESS_INSTANCE_CREATEDsignal_catch_process:1:25007250222018-07-31 12:16:05.0971...1
 27HISTORIC_ACTIVITY_INSTANCE_CREATEDsignal_catch_process:1:2500725022250222018-07-31 12:16:05.1041...1
 28HISTORIC_ACTIVITY_INSTANCE_ENDEDsignal_catch_process:1:2500725022250222018-07-31 12:16:05.1091...1
 29SEQUENCEFLOW_TAKENsignal_catch_process:1:2500725022250222018-07-31 12:16:05.1011...1
 30HISTORIC_ACTIVITY_INSTANCE_CREATEDsignal_catch_process:1:2500725022250262018-07-31 12:16:05.1101...1
 31VARIABLE_CREATEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1211...1
 32HISTORIC_PROCESS_INSTANCE_CREATEDsignal_throwing_process:1:25006250292018-07-31 12:16:45.1211...1
 33HISTORIC_ACTIVITY_INSTANCE_CREATEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1211...1
 34HISTORIC_ACTIVITY_INSTANCE_ENDEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1361...1
 35SEQUENCEFLOW_TAKENsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1211...1
 36HISTORIC_ACTIVITY_INSTANCE_CREATEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1361...1
 37HISTORIC_ACTIVITY_INSTANCE_ENDEDsignal_catch_process:1:2500725022250262018-07-31 12:16:45.1551...1
 38SEQUENCEFLOW_TAKENsignal_catch_process:1:2500725022250222018-07-31 12:16:45.1361...1
 39HISTORIC_ACTIVITY_INSTANCE_CREATEDsignal_catch_process:1:2500725022250222018-07-31 12:16:45.1571...1
 40HISTORIC_ACTIVITY_INSTANCE_ENDEDsignal_catch_process:1:2500725022250222018-07-31 12:16:45.1651...1
 41HISTORIC_PROCESS_INSTANCE_ENDEDsignal_catch_process:1:25007250222018-07-31 12:16:45.1591...1
 42VARIABLE_DELETEDsignal_catch_process:1:2500725022250222018-07-31 12:16:45.1621...1
 43HISTORIC_ACTIVITY_INSTANCE_ENDEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1671...1
 44SEQUENCEFLOW_TAKENsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1591...1
 45HISTORIC_ACTIVITY_INSTANCE_CREATEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1751...1
 46HISTORIC_ACTIVITY_INSTANCE_ENDEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1741...1
 47HISTORIC_PROCESS_INSTANCE_ENDEDsignal_throwing_process:1:25006250292018-07-31 12:16:45.1761...1
 48VARIABLE_DELETEDsignal_throwing_process:1:2500625029250292018-07-31 12:16:45.1791...1
mdtabrezmca
Established Member II

Re: Problems with understanding signals

Forgot to attach the app......

strauss
Member II

Re: Problems with understanding signals

tabrez khan

Thank you for answer.

I looked at your app. But it contains one important difference from my case: you use IntermediateThrowSignal in sync mode. I want use this in async mode.

mdtabrezmca
Established Member II

Re: Problems with understanding signals

I see you are using Async Intermediate throwing event. I guess you can see some of the test cases written in activiti-engine which you can find helpful......

Activiti/modules/activiti-engine/src/test/resources/org/activiti/engine/test/bpmn/event/signal at 6....