Consider the following scenario in Drools:
We have a rule, matching objects of type A
and B
against each other.
rule 1
when
$a : A()
$b : B($a.matches($b), flagged == false)
then
mofidy($b) { flag($a) }
end
However, A
objects have a field called priority
, and when a B
arrives in the working memory, a matching A
with the highest priority should flag it, above all other matching A
s.
How is this possible in Drools? How does it affect performance?
Assuming that
B.flag()
is setting itsflagged
attribute to true, you can try something like this:One thing to notice in this example is that if an A object with a high priority is inserted, any B that was already flagged with a lower A will not be reflagged.
If you need to reflag yours Bs, then you can try something like this:
Hope it helps,