Bug 999491 - Event listeners in stateless sessions are only executed at the first execution
Summary: Event listeners in stateless sessions are only executed at the first execution
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss BRMS Platform 6
Classification: Retired
Component: Business Central
Version: 6.0.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ER3
: 6.0.0
Assignee: Mario Fusco
QA Contact: Marek Winkler
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-08-21 12:08 UTC by Martin Weiler
Modified: 2018-12-03 19:42 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of: 980800
Environment:
Last Closed: 2014-08-06 20:15:49 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Martin Weiler 2013-08-21 12:08:24 UTC
+++ 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

Comment 2 Mario Fusco 2013-08-22 11:17:11 UTC
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?

Comment 3 Martin Weiler 2013-08-22 13:30:23 UTC
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.

Comment 4 Mario Fusco 2013-08-23 16:30:34 UTC
Fixed by https://github.com/droolsjbpm/drools/commit/770d13033

Comment 5 Edson Tirelli 2013-08-26 14:46:57 UTC
As requested, backported to 5.3.x as well:

https://github.com/droolsjbpm/drools/commit/96d311297

Comment 9 Marek Winkler 2014-01-14 17:09:33 UTC
Verified on BRMS 6.0.0 ER7.


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