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\" xmlns:omgdc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:omgdi=\"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\" xmlns:omgdc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:omgdi=\"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());
}
}