Hi, I’m trying to migrate from Flowable to Camunda and one specific issue is blocking my progress for now. I have the following code:
private final Map<String, List<SomeClass>> processListeners = new HashMap<>();
// in the constructor:
CamundaReactor.eventBus().register((ExecutionListener) execution -> {
triggerEvent(execution);
});
private void triggerEvent(DelegateExecution execution) {
List<SomeClass> listeners;
synchronized (processListeners) {
listeners = processListeners.get(execution.getProcessInstanceId());
}
if (listeners != null) {
// this never happens
}
}
public ProcessInstance startProcess(String processDefinitionKey, Subject subject,
SomeClass... listeners) {
synchronized (processListeners) {
ProcessInstance processInstance =
processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey);
if (listeners.length > 0) {
processListeners.put(processInstance.getProcessInstanceId(), Arrays.asList(listeners));
}
return processInstance;
}
}
The problem is that when I call “startProcess” and pass some listeners, they are not called because “startProcessInstanceByKey” is synchronous and the “triggerEvent” method is called BEFORE “startProcessInstanceByKey” finishes (and hence the listeners are added in “processListeners”). Then, in “triggerEvent” I read an empty “processListeners”.
I’m actually not sure how do I fix that at all. Marking the start event of the process async does not work for me as these could be user-generated definitions and I cannot expect users to always mark them as async.
Any ideas would be appreciated! Thanks!