Bug 980800

Summary: Event listeners in stateless sessions are only executed at the first execution
Product: [JBoss] JBoss Enterprise BRMS Platform 5 Reporter: Martin Weiler <mweiler>
Component: BRM (Guvnor)Assignee: Mario Fusco <mfusco>
Status: VERIFIED --- QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: BRMS 5.3.1CC: alazarot, nwallace
Target Milestone: GA   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 999491 (view as bug list) Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 986451    

Description Martin Weiler 2013-07-03 09:15:18 UTC
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

Comment 1 Tomas Schlosser 2013-09-11 07:15:11 UTC
Verified in 5.3.1.BRMS-P04