Firing selective rules from drool file
Is it possible to fire rules in drool file by rule na开发者_高级运维mes ? My requirement is, my rule file will contain list of all rules (S). But I've a separate config which contains list of rule names to be fired (A). Note (A) is a subset of (S). At run time, I want to fire only rules with names (A) from (S).
Thanks.
You can use AgendaFilters for this.
Here is how you set it:
StatelessSession session = ruleBase.newStatelessSesssion();
session.setAgendaFilter( new RuleNameMatches("<regexp to your rule name here>") );
This will allow only one rule with the specified name to fire.
In your case you will need to write your own AgendaFilter:
public class CustomAgendaFilter extends AgendaFilter{
private final Set<String> ruleNamesThatAreAllowedToFire;
public CustomAgendaFilter(Set<String> ruleNamesThatAreAllowedToFire){
this.ruleNamesThatAreAllowedToFire=ruleNamesThatAreAllowedToFire;
}
boolean accept(Activation activation){
return ruleNamesThatAreAllowedToFire.contains(activation.getRule().getName());
}
}
精彩评论