2011-08-11 20 views
2

是否可以通過規則名稱激發流口水文件中的規則? 我的要求是,我的規則文件將包含所有規則(S)的列表。但我有一個單獨的配置,其中包含要觸發的規則名稱列表(A)。注(A)是(S)的子集。在運行時,我只想從(S)開始使用名稱(A)的規則。從流口水文件中激發選擇性規則

謝謝。

回答

7

您可以使用這個AgendaFilters。

這裏是你如何設置:

StatelessSession session = ruleBase.newStatelessSesssion(); 

session.setAgendaFilter(new RuleNameMatches("<regexp to your rule name here>")); 

這將允許使用指定的名稱火只有一個規則。

在你的情況,你需要編寫自己的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()); 
    } 
} 
+1

在Drools中的未來版本,它也應該能夠使用Drools的規則來控制哪些規則可以觸發HTTP://blog.athico .com/2011/08/declarative-agenda-and-control-rules.html –

+0

我一定會試一試。這應該解決我的問題。謝謝。 –