Bug 980800 - Event listeners in stateless sessions are only executed at the first execution
Event listeners in stateless sessions are only executed at the first execution
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRM (Guvnor) (Show other bugs)
BRMS 5.3.1
Unspecified Unspecified
medium Severity medium
: GA
: ---
Assigned To: Mario Fusco
Tomas Schlosser
Depends On:
Blocks: 986451
  Show dependency treegraph
Reported: 2013-07-03 05:15 EDT by Martin Weiler
Modified: 2013-09-11 03:15 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 999491 (view as bug list)
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Martin Weiler 2013-07-03 05:15:18 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.

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 03:15:11 EDT
Verified in 5.3.1.BRMS-P04

Note You need to log in before you can comment on or make changes to this bug.