Skip to content

Commit

Permalink
[JBPM-10187] Handling sessionnotfound in local thread
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Sep 18, 2023
1 parent b8d967b commit 118fc9a
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
package org.jbpm.runtime.manager.impl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;

import org.drools.core.command.SingleSessionCommandService;
import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
Expand Down Expand Up @@ -191,15 +194,33 @@ public void signalEvent(String type, Object event) {

// process currently active runtime engines
Map<Object, RuntimeEngine> currentlyActive = local.get();

if (currentlyActive != null && !currentlyActive.isEmpty()) {
RuntimeEngine[] activeEngines = currentlyActive.values().toArray(new RuntimeEngine[currentlyActive.size()]);
for (RuntimeEngine engine : activeEngines) {
Context<?> context = ((RuntimeEngineImpl) engine).getContext();
@SuppressWarnings("unchecked")
Entry<Object, RuntimeEngine> activeEngines[] = currentlyActive.entrySet()
.toArray(new Entry[currentlyActive.size()]);
Set<Object> enginesToDelete = new HashSet<>();
for (Entry<Object, RuntimeEngine> engine : activeEngines) {
RuntimeEngineImpl engineImpl = (RuntimeEngineImpl) engine.getValue();
if (engineImpl.isDisposed() || engineImpl.isInvalid()) {
enginesToDelete.add(engine.getKey());
continue;
}
Context<?> context = engineImpl.getContext();
if (context != null && context instanceof ProcessInstanceIdContext
&& ((ProcessInstanceIdContext) context).getContextId() != null) {
engine.getKieSession().signalEvent(type, event, ((ProcessInstanceIdContext) context).getContextId());
try {
engineImpl.getKieSession().signalEvent(type, event,
((ProcessInstanceIdContext) context).getContextId());
} catch (SessionNotFoundException ex) {
logger.warn(
"Signal event cannot proceed because of session not found exception {} for engine {}",
ex.getMessage(), engineImpl.getKieSessionId());
enginesToDelete.add(engine.getKey());
}
}
}
enginesToDelete.forEach(currentlyActive::remove);
}
}

Expand Down

0 comments on commit 118fc9a

Please sign in to comment.