I need to write some rule which will *only* fire on newly inserted
data
points in Working Memory. Does Drools support any
such feature which will help me to achieve this ? Any suggestion, how can
I
achieve this efficiently?
I am inserting 6 matching DataObjects into Working Memory. Rule is
getting fired once
But in subsequent rule executions after I insert 6 more matching
DataObjects
into Working Memory, Rule is getting fired couple of times
How can I avoid this ?
Hi,
here:
http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html/ch06s05.html#d...
the "exists" statement is described which has almost the functionality which
you want.
Unfortunately (but intuitively) you cannot access variable bindings from
inside the "exists" body. This is intuitive, because "exists" models
the
logical existential quantifier which gives true, if there exist some facts
supporting the truth of the formula !no matter, which facts that are!.
So for your purpose you have to think about, if you are really interested in
which objects trigger the rule. If so, I can imagine, that you don't want to
know only one portion of information but information about each activation.
Then the behaviour of your rule is correct.
But, I know about the problem. I faced it sometimes too. One way to a
solution would be to retract objects from the working memory, if you can
safely assume that they "have done their work". I.e. if you know, that these
objects should not cause activations of this rule again AND you know that no
other rule needs these objects, retract them in the rhs of your rule.
If other rules need the objects and you can't retract them therefore, the
only solution which I know is to mark the objects by yourself as "processed"
by the rule, e.g with your ruleID, and to test everytime in the lhs if the
object of interest is not processed... This is ugly, but it works.
Hope I could help you, but, let me know, if you have found a better
solution.
Alexander Claus