Hi,<br><br>I'm very new to drools and am trying to understand how "facts" are managed by the knowledge session. I've been experimenting with a simple example using drools 5.3.0. I created a simple Account class that has a single "balance" attribute. My rule tests the balance and prints a message if it is less than 100. I am creating a new instance of Account in my main method and inserting it into a stateful knowledge session. I put this into a loop that runs 3 times and never dispose of the session. Each of my Account instances has a balance less that 100. Here is a portion of the code:<br>
<br> public static final void main(String[] args) throws InterruptedException<br> { <br> KnowledgeBase knowledgeBase = createKnowledgeBase();<br> StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();<br>
<br> for (int i = 0; i < 3; i++)<br> {<br> try<br> {<br> Account account = new Account();<br> switch (i) <br> {<br> case 0: account.setBalance(95);<br>
break;<br> case 1: account.setBalance(85);<br> break;<br> case 2: account.setBalance(80);<br> break;<br> default: account.setBalance(80);<br>
}<br> session.insert(account);<br> session.fireAllRules();<br> }<br> catch (Exception e)<br> {<br> System.out.println("Exception: " + e.toString());<br>
}<br> Thread.sleep(1000);<br> }<br> }<br><br>My rule is:<br>rule "basic rule"<br>when $a : Account (balance < 100) // condition<br>then System.out.println("Account balance " + $a.getBalance() + " is less than 100"); // consequence<br>
end<br><br>What I see is that each time the loop executes only the last instance of Account seems to get triggered. I expected that each time I call "fireAllRules" it would examine all the facts in the session and execute them. So I thought the first time the loop runs I would get 1 activation, the second time the loop runs I get 2 activations, etc.<br>
<br>Are all 3 instances of Account still in the working memory or is the latest instance replacing the existing one? Or, once a fact triggers the rules engine, does it not trigger it again?<br><br>Thanks for any insights,<br>
Anne<br>