<br>&nbsp;&nbsp;&nbsp; It depends on what addResult() does and if you need the actual values of A() and B(). Forward chaining engines are &quot;data driven&quot; and as so, changes to your data (facts) are what cause the engine to cancel activations.<br>
&nbsp;&nbsp;&nbsp; So, if you don&#39;t need the actual values of A and B, use &quot;exists&quot;:<br><br>exists( A( $c : code) and B(parentCode == $c) )<br><br>&nbsp;&nbsp;&nbsp;&nbsp; Although, since addResult() uses them as parameters, I guess it is not the case. So, does addResult() changes your facts in any way? Lets say addResult() creates a Association fact between A and B, you could write:<br>
<br>when<br>&nbsp;&nbsp;&nbsp; $a : A( $c : code )<br>&nbsp;&nbsp;&nbsp; $b : B( parentCode == $c )<br>&nbsp;&nbsp;&nbsp; not( Association( &lt;you can constraint something here if you want&gt; ) )<br>then<br><br>&nbsp;&nbsp;&nbsp; Or if A and B have an attribute that is set by addResult()<br>
<br>when<br>
&nbsp;&nbsp;&nbsp; $a : A( $c : code )<br>
&nbsp;&nbsp;&nbsp; $b : B( parentCode == $c )<br>
&nbsp;&nbsp;&nbsp; not( A( resultAdded == true ) and B( resultAdded == true ) )<br>
then<br>
<br>&nbsp;&nbsp;&nbsp; So, in the end, rules in forward chaining are about taking actions triggered by a given data state. Write rules that react to the expected state and change the state accordingly.<br><br>&nbsp;&nbsp;&nbsp; Oh, obviously you can always use fire limit or halt to &quot;pause&quot; the execution if that is what you want too. <br>
<br>session.fireAllRules( 1 ); // fires only one rule and returns control to the application<br><br>&nbsp;&nbsp;&nbsp; Or:<br><br>when<br>

&nbsp;&nbsp;&nbsp; $a : A( $c : code )<br>

&nbsp;&nbsp;&nbsp; $b : B( parentCode == $c )<br>

then<br>&nbsp;&nbsp;&nbsp; addResult( $a, $b );<br>&nbsp;&nbsp;&nbsp; drools.halt();<br>end<br><br>&nbsp;&nbsp;&nbsp; After firing the above rule, stop firing rules and return the control to the application. Above situations will only pause the engine. All activations that were not fired will remain in the agenda waiting for the next call to fireAllRules() to be fired.<br>
<br>&nbsp;&nbsp;&nbsp; []s<br>&nbsp;&nbsp;&nbsp; Edson<br><br><br><div class="gmail_quote">2009/1/26 Maxim Veksler <span dir="ltr">&lt;<a href="mailto:maxim.veksler@gmail.com">maxim.veksler@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">Hello group,<br><br>Assuming I have the rule: <br><br>rule &quot;try not to loop&quot;<br>&nbsp;&nbsp; &nbsp;when<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; $a : A($code : code)<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; $b : B(parentCode == $code)<br>&nbsp;&nbsp; &nbsp;then<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; addResult($a, $b);<br>

end<br><br><br>and the classes:<br><br>public class A {<br>int code;<br>}<br><br>public class B {<br>int parentCode;<br>}<br><br><br><br>I insert into the WM 4 objects :<br>A(code = 1), A(code = 2);<br>B(parentCode=1), B(parentCode = 2);<br>

<br>I would like that after calling fireAllRules() only 1 match will be returned. I have no preference regarding which one, in the current situation 2 matches are returned. <br><br>Anyone could suggest a method to enforce this ?<br>

<br><br>Thank you,<br>Maxim.<br></div>
<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br> &nbsp;Edson Tirelli<br> &nbsp;JBoss Drools Core Development<br> &nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>