How does the update feature work in drools?

How does the update function in drools work? Does this mean that the same rules are automatically triggered automatically?

+3


source to share


1 answer


I think you need to read the manual: http://docs.jboss.org/drools/release/5.4.0.Final/drools-expert-docs/html_single/

Usage update

makes the engine rules know that the fact has changed. Therefore, the rules that depend on this fact must be re-evaluated. This causes the rule to be triggered in an infinite loop. For example, given the following DRL, you will see that the Infinite Loop rule will run continuously:

declare AreWeThereYet
    answer : boolean
end

rule "Are we there yet?"
when
    not AreWeThereYet()
then
    insert(new AreWeThereYet());
end

rule "Infinite loop"
    no-loop
when
    $question: AreWeThereYet()
then
    $question.setAnswer(false);
    update($question);
end

      



This is because the rule engine has been instructed update($question)

that it $question

has changed and that it needs to re-evaluate it.

There are ways to prevent this. Just place no-loop

on the line between the rule name and when

to prevent re-inclusion of rules as a result of their own consequences. Another rule attribute that can control this is lock-on-active

.

+14


source







All Articles