Drools Fusion: Strange behavior if I cange the filed and use it in the same instant

StackOverflow https://stackoverflow.com/questions/21306464

  •  01-10-2022
  •  | 
  •  

Вопрос

This is my code into an .rdl

rule "Fulfilment 24345"
when

$evPtr: LeftArmStretched($tsmp:time)

    eval((3>$tsmp)==true)
then
System.err.println("$tsmp=      "+$tsmp);

end


rule "set timestamp"

when
   $las:LeftArmStretched();
then
   System.out.println("//change timestamp!!");
   $las.setTime(6);
end

If I run my example, 1st and 2nd rules fire and print:

//change timestamp!!
$tsmp=         6

but if $tsmp=3 the rule1 does not fire!!!! (3>6 false!)

If I manually write eval((3>6)==true) into rule1, the rule1 doesn't correctly fire!

Это было полезно?

Решение

A change to a fact object must be announced to the Rule Engine, i.e., use

modify( $las ){
    setTime( 6 )
}

Also, do not rely on rule "set timestamp" being fired first. Use some additional constraint, or salience.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top