开发者

Firing selective rules from drool file

开发者 https://www.devze.com 2023-03-27 00:05 出处:网络
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 na

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());
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号