[rules-users] reuse a rule already fired

Edson Tirelli tirelli at post.com
Wed May 9 10:33:22 EDT 2007


   Ck,

    You need to think different when using forward chaining. Your data will
drive the execution, not your "goals".
    So, the state of your facts match rule B twice, it will fire twice.

    "Stupid" example:

rule "1. increment counter"
   salience 10
when
    $c : Counter( value < 2 )
then
    System.out.println( "firing rule 1" );
    $c.setValue( $c.getValue() + 1 );
    modify( $c );
end

rule "2. diplay counter"
when
    Counter( $value : value )
then
    System.out.println("Value = "+$value);
end

   If you do:

wm.assertObject( new Counter( 0 ) );
wm.fireAllRules();

    Rules will fire:

1 -> 1 -> 2

    But that is because your "state" (facts) drive them in that way. Do you
understand that? Try removing salience attribute and check if there is any
difference. Try making rule 2 higher salience than rule 1. Try asserting
different values for the counter, like new Counter( 2 ).

    []s
    Edson


2007/5/9, ch4nd4n <chandan_kumar at msn.com>:
>
>
> Hi,
> is there a possibility to fire a particular rule twice?
>
> For example if I have Rules "A", "B", "C", "D" and I am putting a Person
> Object with few parameters,
>
> Then how can I fire in following order
>
> A -> B -> C -> B -> D
>
> Thanks,
> Ck
> http://www.gfour.net
> --
> View this message in context:
> http://www.nabble.com/reuse-a-rule-already-fired-tf3714857.html#a10391552
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070509/04437348/attachment.html 


More information about the rules-users mailing list