Red Hat Bugzilla – Bug 980800
Event listeners in stateless sessions are only executed at the first execution
Last modified: 2013-09-11 03:15:11 EDT
Description of problem:
we're using a "Drools Server" like architecture, i.e., a WAR loading a spring context defining a camel context exposing routes to expose rules.
Our functional rules are ordered through a ruleflow (bpmn2 file). All of them are executed inside stateless session.
In the drools configuration, we declare eventlistener in session to monitore the execution.
After the start-up of the server, we call the server for rule execution. the first time, it works well and event listeners log normally.
However, for the following calls, the event listener are no more active.
1. In the Spring integration scenario, the listeners defined in knowledge-services.xml are added to the StatelessKnowledgeSession, by calling ksession.addEventListener(..) in StatelessKnowledgeSessionBeanFactory. This is a result of https://issues.jboss.org/browse/JBRULES-3076
2. This call happens once after initialization, in internalAfterPropertiesSet
3. The fix for DROOLS-141  removes the listeners in the dispose method, and sets the initialized flag to false again
4. This causes the listeners from the working memory to be added again
5. HOWEVER, the listener added to the StatelessKnowledgeSession internal mappedAgendaListeners Map are not getting mapped again. This is why the custom listener is only executed at the first run.
We should take care of not only AgendaEventListener but also WorkingMemoryEventListener and ProcessEventListener.
AgendaEventListener and WorkingMemoryEventListener are happened to be held in mappedAgendaListeners and mappedWorkingMemoryListeners like a cache so we can restore agendaEventSupport/workingMemoryEventSupport from them but ProcessEventListener is not, so we need to add similar one for ProcessEventListener.
KSessionFactoryBean seems to have the same logic as StatelessKnowledgeSessionBeanFactory so the issue seems to still exist in the latest code.
Verified in 5.3.1.BRMS-P04