<br> Dirk, <br><br> It is a bug that affects collect and accumulate. Working on that.<br> Firing rules is the default behavior when dynamically adding packages. I think mark created a configuration to change this behavior...
<br><br> []s<br> Edson<br><br><div><span class="gmail_quote">2008/1/9, Dirk Bergstrom <<a href="mailto:dirk@juniper.net">dirk@juniper.net</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have modified my application to allow adding/removing/updating rules during<br>runtime. However, when I add a new rule to the rulebase, I don't get the<br>behavior I expect.<br><br>First, as soon as I call RuleBase.addPackage
(), the new rules fire (the RHS code<br>runs). Shouldn't that happen only when I call fireAllRules()?<br><br>Second, newly added collect() rules don't collect already asserted objects. New<br>non-collect rules can see the objects just fine.
<br><br>Attached is a testcase, and below is the output it produces. Am I doing<br>something wrong, or is this a bug? I'm running Drools 4.0.3 on JDK <a href="http://1.5.0.13">1.5.0.13</a>.<br><br>Start<br>RuleBase created
<br>Adding rules about 'tom':<br>package rules;<br>import java.util.ArrayList;<br>import test.Tester.Record;<br>import test.Tester;<br>rule "Collect tom"<br>when<br> $list : ArrayList(size > 0) from collect( Record(field1 == "tom") )
<br>then<br> Tester.show($list, "Collect tom");<br>end<br><br>rule "Non collect tom"<br>when<br> $rec : Record( field1 == "tom" )<br>then<br> System.out.println("Find 'tom' " + $rec.dump());
<br>end<br><br>inserting record 1:"tom",<br>inserting record 2:"fred",<br>inserting record 3:"harry",<br>inserting record 4:"fred",<br>inserting record 5:"ed",<br>inserting record 6:"tom",
<br>inserting record 7:"sreeni",<br>inserting record 8:"jill",<br>inserting record 9:"ralph",<br>inserting record 10:"tom",<br><br>fireAllRules()<br>Find 'tom' 10:"tom",
<br>'Collect tom' collected 3 records => 1:"tom", 6:"tom", 10:"tom",<br>Find 'tom' 6:"tom",<br>Find 'tom' 1:"tom",<br><br>adding rules about 'fred':
<br>package morerules;<br>import java.util.ArrayList;<br>import test.Tester.Record;<br>import test.Tester;<br>rule "Collect fred"<br>when<br> $list : ArrayList(size > 0) from collect( Record(field1 == "fred") )
<br>then<br> Tester.show($list, "Collect fred");<br>end<br><br>rule "Non collect fred"<br>when<br> $rec : Record( field1 == "fred" )<br>then<br> System.out.println("Find 'fred' " + $rec.dump());
<br>end<br><br> ==> Why do the new rules fire when added?<br>Find 'fred' 4:"fred",<br>Find 'fred' 2:"fred",<br>'Collect fred' collected 0 records =><br> ==> Why doesn't the collect rule collect? The non-collect rule works.
<br>fireAllRules()<br><br>Changing record 3 to 'fred'<br>fireAllRules()<br>Find 'fred' 3:"fred",<br>'Collect fred' collected 1 records => 3:"fred",<br> ==> Why does the collect rule not see the other two 'fred' records?
<br><br>--<br>Dirk Bergstrom <a href="mailto:dirk@juniper.net">dirk@juniper.net</a><br>_____________________________________________<br>Juniper Networks Inc., Computer Geek<br>Tel: 408.745.3182 Fax:
408.745.8905<br><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646
<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>