Hasitha
Hasitha

Reputation: 588

Firing particular rule by rule name in drools without using Agenda Filters

I read the rule file and add them into my knowledgeBase then I want to fire a particular rule in that knowledgeBase. Is this task possible in current drools version?

Upvotes: 0

Views: 1520

Answers (1)

laune
laune

Reputation: 31300

If you have a rule base where rules should be made active dynamically according to some criterion you have several choices.

  1. Agenda filter. You say you don't want this, but why?
  2. Put the alternative rules into agenda groups. Select the agenda group "group_3" prior to inserting the fact by a call to
kieSession.getAgenda().getAgendaGroup( "group_3" ).setFocus();
  1. Write your rules to include a "selection" fact, e.g.
rule rule_3
when
    Select( rule == "rule_3" )
    Person( ... )
then ... end

The Select fact can be inserted along with the data fact but must be retracted after firing the rule.

Upvotes: 1

Related Questions