Skip to content

Commit

Permalink
[JBPM-10208] Avoid signalling the same engine more than once
Browse files Browse the repository at this point in the history
In the same signalEvent call
  • Loading branch information
fjtirado committed Nov 7, 2023
1 parent 5a9f791 commit bc17dcb
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ public RuntimeEngine getRuntimeEngine(Context<?> context) {
public void signalEvent(String type, Object event) {

// first signal with new context in case there are start event with signal
Set<RuntimeEngine> signalledEngines = new HashSet<>();
KieSession signalSession = null;
RuntimeEngine runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
try {
// signal execution can rise errors
signalSession = runtimeEngine.getKieSession();
signalSession.signalEvent(type, event);
signalledEngines.add(runtimeEngine);
} finally {
// ensure we clean up
if(signalSession!=null) {
Expand All @@ -179,13 +181,17 @@ public void signalEvent(String type, Object event) {
disposeRuntimeEngine(runtimeEngine);
}


// next find out all instances waiting for given event type
List<String> processInstances = ((InternalMapper) mapper).findContextIdForEvent(type, getIdentifier());
for (String piId : processInstances) {
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(Long.parseLong(piId)));
try {
// signal execution can rise errors
runtimeEngine.getKieSession().signalEvent(type, event);
if (!signalledEngines.contains(runtimeEngine)) {
runtimeEngine.getKieSession().signalEvent(type, event);
signalledEngines.add(runtimeEngine);
}
} finally {
// ensure we clean up
disposeRuntimeEngine(runtimeEngine);
Expand Down Expand Up @@ -215,8 +221,11 @@ public void signalEvent(String type, Object event) {
if (context != null && context instanceof ProcessInstanceIdContext
&& ((ProcessInstanceIdContext) context).getContextId() != null) {
try {
engineImpl.getKieSession().signalEvent(type, event,
if (!signalledEngines.contains(engineImpl)) {
engineImpl.getKieSession().signalEvent(type, event,
((ProcessInstanceIdContext) context).getContextId());
signalledEngines.add(engineImpl);
}
} catch (org.drools.persistence.api.SessionNotFoundException ex) {
logger.warn(
"Signal event cannot proceed because of session not found exception {} for engine {}",
Expand Down

0 comments on commit bc17dcb

Please sign in to comment.