<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:'times new roman', 'new york', times, serif;font-size:12pt"><div>thanks , Both are possible ways for the issue though they are a little complicated.</div><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><br><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">发件人:</span></b> Michael Anstis <michael.anstis@gmail.com><br><b><span style="font-weight: bold;">收件人:</span></b> Rules Users List <rules-users@lists.jboss.org><br><b><span style="font-weight: bold;">发送日期:</span></b> 2011/3/19 (周六) 12:25:48 上午<br><b><span style="font-weight: bold;">主 题:</span></b> Re: [rules-users] how to ensure that one rule only is executed once?<br></font><br>You'd need to make sure
you inform the engine that Order's price has changed:-<br><br>when<br> ...<br>then<br> modify( $o ) {<br> setPrice( $o.getPrice() - 20);<br> }<br><br>You could also consider using agenda-groups or lock-on-active to provide your behaviour.<br>
<br><b>agenda-groups<br></b><br> rule "rule 1"<br>//implied default agenda-group of MAIN<br>when<br> $o : Order (amount>100 && <200);<br>then<br> modify( $o ) {<br> setPrice( $o.getPrice() - 10);<br>
}<br> drools.setFocus("next step in calculation");<br>end<br><br>rule "rule 2"<br>//implied default agenda-group of MAIN<br>
when<br> $o:Order (amount>200);<br>
then<br> modify( $o ) {<br> setPrice($o.getPrice() - 20);<br> }<br> drools.setFocus("next step in calculation");<br>
end<br><br>rule "rule 3"<br>agenda-group "next step in calculation"<br>when<br> $o : Order(....)<br>then<br> ....<br>end<br><br><b>lock-on-active</b><br><br> rule "rule 1"<br>
//implied default agenda-group of MAIN<br>lock-on-active true<br>
when<br>
$o : Order (amount>100 && <200);<br>
then<br>
modify( $o ) {<br>
setPrice( $o.getPrice() - 10);<br>
}<br>
end<br>
<br>
rule "rule 2"<br>
//implied default agenda-group of MAIN<br>
lock-on-active true<br>
when<br>
$o:Order (amount>200);<br>
then<br>
modify( $o ) {<br>
setPrice($o.getPrice() - 20);<br>
}<br>
end<br>
<br>
rule "rule 3"<br>
agenda-group "next step in calculation"<br>
when<br>
$o : Order(....)<br>
then<br>
....<br>
end<br>
<br><div class="gmail_quote">On 18 March 2011 16:08, Gabor Szokoli <span dir="ltr"><<a rel="nofollow" ymailto="mailto:szocske@gmail.com" target="_blank" href="mailto:szocske@gmail.com">szocske@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex;">
Hi,<br>
<br>
>From what I know, it's generally better to make the rules idempotent:<br>
In your case introduce a discountedPrice field, leaving the original<br>
price alone.<br>
<br>
If you insist on making it run only once instead, you can introduce a<br>
field or fact class to mark an order "discounted", then all<br>
discounting rules know to ignore it. (This gets really complicated if<br>
the order amount ever changes and you do need to run the discounting<br>
rules again.)<br>
<br>
<br>
Gabor<br>
<br>
2011/3/18 yong zhao <<a rel="nofollow" ymailto="mailto:cluncao@yahoo.com.cn" target="_blank" href="mailto:cluncao@yahoo.com.cn">cluncao@yahoo.com.cn</a>>:<br>
<div><div></div><div class="h5">> Hi<br>
> I just try to uses jboss rules in our projects. I met a question. for<br>
> example<br>
> package sample<br>
> rule "rule 1"<br>
> when<br>
> $o:Order (amount>100 and amount<200);<br>
> then<br>
> $o.setPrice($o.getPrice()-10);<br>
> end<br>
> rule "rule 2"<br>
> when<br>
> $o:Order (amount>200);<br>
> then<br>
> $o.setPrice($o.getPrice()-20);<br>
> end<br>
> if the fact , order's amount is 210. then the rule2 will be executed, then<br>
> the rule1 will be fired . I want to stop the session once some rule is<br>
> executed or how to control the rule flow.<br>
> thanks in advance<br>
> -Yong<br>
><br>
><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> rules-users mailing list<br>
> <a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> <a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
><br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>
</div></div><div style="position:fixed"></div>
</div><br>
</body></html>