Scorpio
Scorpio

Reputation: 511

Find rules fired/matched for each fact

Is there a way to find out which rules were matched (fired) whenever I insert a fact (POJO) (or whenever I fire all the rules). I need to figure out for which facts none of the rules got fired and for each fact which of the rules got fired for some visualisation activity.

Upvotes: 0

Views: 1359

Answers (1)

laune
laune

Reputation: 31290

Implement method void beforeMatchFired(BeforeMatchFiredEvent event) of the interface org.kie.api.event.rule.AgendaEventListener. The event will tell you a match: Match getMatch(), and the match informs you about facts: List<? extends FactHandle> getFactHandles() and the rule: Rule getRule().

If you want to use another listener for keeping track of inserted facts, there is org.kie.api.event.rule.DebugRuleRuntimeEventListener, but you could do this just as well in the application code where you insert facts.

I guess you can imagine the rest: storing this information in a Map and evaluating it is a simple exercise.

Upvotes: 1

Related Questions