I'm using an AgendaFilter to decide whether a rule activation should be executed or not.
As part of my working memory's facts I insert one "rule configuration" fact per rule which contains how often my rule is allowed to be executed (and a corresponding counter).
I noticed that Match.getFactHandles()
only returns the facts that 'created this match' (as per java doc).
Is there a way to access the WorkingMemory and all its facts or do I basically have to declare my "rule configuration" fact as part of my condition?
Example to illustrate: right now I do something like this (below) and I wonder if I can get around having to declare the $ruleConfig
fact in the rule but still be able to look it up in my AgendaFilter.
rule "abc"
@uid("1234")
when
$ruleConfig : RuleConfig(uid="1234")
// insert the actual rule conditions
...
Thanks! (I know I could solve this with control facts entirely inside the rule, but for architectural reasons I want to keep this out of the actual rule code as much as possible, hence the AgendaFilter)
An AgendaFilter is a Pojo, and you can create it with the KieSession being passed as an argument. This lets you access all the WM facts, according to the API documentation. Thus, it isn't necessary to have the appropriate RuleConfig as an extra condition with each rule. The only advantage of your approach is that you have this object readily available in the List of matched facts.
But it would be just as simple to pass a Map<String,RuleConfig>
to te AgendaFilter, without all of the RuleConfig objects being added to the Working Memory.
A slightly more sophisticated approach would be
rule "abc"
@uid("1234")
when
$ruleConfig : RuleConfig(uid="1234", counter > 0)
// ...
with the counter being decremented with each rule firing - not necessarily on each RHS but in a central place: a
RuleRuntimeEventListener
.