使用StatefulKnowledgeSession我能够定义一个描述我想要执行的规则的过滤器:
session.fireAllRules(new RuleNameEqualsAgendaFilter(ruleName));
但是我无法使用StatelessKnowledgeSession找到一种方法来做同样的事情:
cmds.add(CommandFactory.newFireAllRules());
ExecutionResults results = session.execute(CommandFactory.newBatchExecution(cmds));
CommandFactory.newFireAllRules()可以使用 int max 和 String outIdentifier ,或者根本没有参数。
JBoss Drools的过多(!)文档对我没有帮助:
我的问题是这是否可行。 感谢。
答案 0 :(得分:1)
CommandFactory没有使用过滤器创建FireAllRulesCommand的方法,但您可以自己创建一个:
List<Command> cmds = new ArrayList<Command>();
cmds.add(CommandFactory.newInsert(new MyFact()));
cmds.add(new FireAllRulesCommand(new RuleNameEqualsAgendaFilter("MyRule")));
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(cmds));
private static class RuleNameEqualsAgendaFilter implements AgendaFilter {
private final String ruleName;
public RuleNameEqualsAgendaFilter(final String ruleName) {
this.ruleName = ruleName;
}
public boolean accept(final Activation activation) {
return activation.getRule().getName().equals(this.ruleName);
}
}