0
votes

My use case is to return the first matched rule and not to match all other the rules. Is there a way to do this? what is the significance of knowledgeSession.fireAllRules(max) ?

1

1 Answers

2
votes

the fireAllRules(max) method basically takes the amount of rule matches that you want. All it does internally is creating an AgendaFilter that limits the amount of matches. (See AgendaFilter interface docs). Skipping the argument means using a filter that returns true for every possible rule, so you will match everything.

If you want to match exactly 1 rule, and you want to know which one it is, you can use this approach in combination with a AgendaEventListener.

What you can do is:

  1. implement AgendaEventListener to store which rule has been matched
  2. call fireAllRules(1) or write your own agenda filter to limit the amounts of matches to 1
  3. evaluate the Listener for which rules has been matched

This does not give you any control over what rule will be matched however. All rules that have NOT been matched when you use a filter, will be matched the next time you fire all rules (unless you limit the rule execution again and so on).