+++ This bug was initially created as a clone of Bug #980800 +++ 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. Additional info: 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 [1] 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. [1] https://github.com/sotty/drools/blob/3aa311905a1cf6b06e777294ecd327f9a3bb797a/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java
There is something I am not understanding here: the fix for DROOLS-141 at point 3. has NOT been forward ported to the master/6.0.x branches but only applied to the 5.6.x branch, so I don't see how this issue could affect BRMS 6 as reported in this ticket. Could you please clarify which version of Drools suffers of this problem?
The fixes for DROOLS-141 need to be applied to the 6.0.x branch as well, otherwise the issue reported in DROOLS-141 still exists in that version. Once they are applied, and all rules are executed on subsequent calls to execute() on the same StatelessKnowledgeSession instance, it should be ensured that all listeners get executed as well.
Fixed by https://github.com/droolsjbpm/drools/commit/770d13033
As requested, backported to 5.3.x as well: https://github.com/droolsjbpm/drools/commit/96d311297
Verified on BRMS 6.0.0 ER7.