2
votes

(I am a bit new to working with Drools, so please excuse if this is a simple question).

I would like to use Drools for reactive execution of rules, this means we could consider the “facts” being inserted to be “event” instances. However, I want this to execute in a way that rules can be fired as soon as events are received. But, in the case that a rule may depend on several events, how can I configure the Working Memory, to remember previous events. Consider a very simple example:

Say I have the following rules:

 - when (E1) do A1
 - when (E2) do A2
 - when (E1,E2) do A3

Then, if time progresses as follows, I want to following rules to be fired, example:

 - t=1 , E1 happens => A1 fired
 - t=2 , E2 happens => A2 fired + A3 fired

The problem I have is if I call ksession.fireAllRules() after every insertion, the working memory will forget all previous events. What is the best way to achieve what I want?

1

1 Answers

0
votes

as long as you use a Stateful Knowledge Session, what you are probably doing because the stateless one has no fireAllRules() method, the WM will not forget all the inserted facts.

What you express as "E1 happens" should be ksession.insert(E1);

You may play with the example given in the documentation (link above)...