我们前面有说道drools指定规则运行,具体使用是在kieSession.fireAllRules()时,通过指定方法来实现运行会指定的规则,下面具体开始讲解如何指定规则。
int fireAllRules(org.kie.api.runtime.rule.AgendaFilter agendaFilter);
public interface AgendaFilter {
boolean accept(org.kie.api.runtime.rule.Match match);
}
//运行规则名称以指定字符串结束的规则
kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter(""));
//运行规则名称与指定字符串相等的规则
kieSession.fireAllRules(new RuleNameEqualsAgendaFilter(""));
//运行规则名称符合正则表达式的规则
kieSession.fireAllRules(new RuleNameMatchesAgendaFilter(""));
//运行规则名称以指定字符串开头的规则
kieSession.fireAllRules(new RuleNameStartsWithAgendaFilter(""));
我们也可以自定义过滤规则,只需要实现AgendaFilter 接口
public class MyRuleFilter implements AgendaFilter {
private List<String> names;
public MyRuleFilter(List<String> names)

本文详细介绍了如何在Drools中利用AgendaFilter来精确指定规则运行,包括按名称匹配、正则表达式和自定义过滤,帮助开发者高效管理规则执行。
最低0.47元/天 解锁文章
658

被折叠的 条评论
为什么被折叠?



