从drool文件中解雇选择性规则

Man*_*ani 2 drools

是否可以通过规则名称在drool文件中触发规则?我的要求是,我的规则文件将包含所有规则(S)的列表.但我有一个单独的配置,其中包含要触发的规则名称列表(A).注(A)是(S)的子集.在运行时,我想只触发(S)中带有名称(A)的规则.

谢谢.

Ton*_*ola 7

您可以使用AgendaFilters.

这是你如何设置它:

StatelessSession session = ruleBase.newStatelessSesssion();

session.setAgendaFilter( new RuleNameMatches("<regexp to your rule name here>") );
Run Code Online (Sandbox Code Playgroud)

这将只允许触发具有指定名称的一个规则.

在您的情况下,您需要编写自己的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());
  }
}
Run Code Online (Sandbox Code Playgroud)