0

I'm trying to return the numbers of retracts that a drools session execution have.

I can obtain the number of executions:

...
final Command fireAllRulesCmd = CommandFactory.newFireAllRules("executed-rules");
cmds.add(fireAllRulesCmd);
...
session.execute(CommandFactory.newBatchExecution(cmds));
final Integer executedRules = (Integer) execute.getValue("executed-rules");
....

Are there a similar way to obtain all "retracted-rules"?

Thanks!!

Regards

Ganchix
  • 315
  • 4
  • 13

1 Answers1

1

Implement org.kie.api.event.kiebase.KieBaseEventListener, and in method afterRuleRemoved count the events:

class MyKieBaseEventListener implements KieBaseEventListener {
    private int removedRules;
    public void afterRuleRemoved(AfterRuleRemovedEvent event){
        removedRules++;
    }
    public int getRemovedRules(){
        return removedRules;
    }
    // other methods
}

You have to attach this listener to the KieBase.

kieBase.addEventListener( new MyKieBaseEventListener() );
laune
  • 31,114
  • 3
  • 29
  • 42
  • I'm using the version 5.4.0.Final of drools, the KieBaseEventListener is the same that KnowledgeAgentEventListener? Thanks!!! – Ganchix Sep 15 '14 at 12:14
  • In 5.4 the names are KnowledgeBase... in `org.drools.event.knowledgebase` – laune Sep 15 '14 at 12:19