使用StatelessKnowledgeSession运行一组规则

时间:2013-11-17 15:03:51

标签: jboss drools rule-engine rule

使用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的过多(!)文档对我没有帮助:

Documentation

我的问题是这是否可行。 感谢。

1 个答案:

答案 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);
    }
}