1

I have event driven architecture. Say about 1000 event types and each event type can have multiple listeners. Averaging around 2 per event. giving 2000 handlers. For each event handler I have rule to be evaluated further to see if that event handling is required or not.

handle(MyEvent xxx){
 kisession.execute( xxx.getPayload());
 // Here I want the rules that are named/identified againt my Event alone to be fired
}

I could add MyEvent to be part of LHS of the specific rule.

But I want the matching to be preprocessed to save on processing time after event is fired. Is there a better way to fire a specific rule only rather than allowing the underlying engine evaluate all the 2000 rules to figure out which one is applicable for the Payload fact?

I could identify the rules for specific event handlers at design time itself and want to exploit this advantage for better performance.

ubreddy
  • 815
  • 2
  • 8
  • 19
  • AFAIK, the underlying Rete algorithm should take care of this. It matches the object in the fact base to the conditions in the rules, so that only those rules that could be affected by some fact base update get evaluated. – tobias_k Dec 05 '14 at 08:58

1 Answers1

2

If you select which rule to fire from outside the rules engine, then there is absolutely no point in using a rules engine!

Evaluating which rules should activate is what Drools is designed to do. Fast. Drools does not need to evaluate 2000 rules every time you call fireAllRules, just because you have 2000 rules. When you create a knowledge base, the rules are compiled into a graph which lets the engine determine which rules might fire for certain matches. The graph is updated every time a fact is inserted, modified or retracted. It's a bit like having an indexed database table.

Of course, you can technically do this. Use the fireAllRules(AgendaFilter) method to filter the rules which may fire.

Steve
  • 9,270
  • 5
  • 47
  • 61
  • 1
    (to complete @Steve 's last paragraph),,,which is very likely going to make everything less efficient. – laune Dec 05 '14 at 12:41