当lock-on-active设置为true时,规则不会触发一次。它应该发射一次吗?我希望规则1在使用lock-on-active时被触发一次。
(注意:我已经添加了用于执行规则的代码)
规则
rule "Rule 1"
lock-on-active true
ruleflow-group "Group A"
when
$c: Product()
then
System.out.println("Rule 1");
modify($c)
{
setAmount(1);
}
end
rule "Rule 2"
lock-on-active true
ruleflow-group "Group A"
when
$c: Product()
then
System.out.println("Rule 2");
modify($c){
setAmount($c.getAmount()+1)
}
end 用于执行规则的代码
KieServices kieServices=KieServices.Factory.get();
KieContainer kieContainer=kieServices.getKieClasspathContainer();
KieSession kieSession=kieContainer.newKieSession("ksession-lockOnActive");
Product product=new Product();
product.setName("Book");
product.setAmount(5);
((InternalAgenda)kieSession.getAgenda()).activateRuleFlowGroup("Group A");
kieSession.insert(product);
kieSession.fireAllRules();
kieSession.dispose(); 发布于 2017-12-14 15:51:18
首先,ruleflow-group属性用于在JBPM中使用规则作为业务流程的一部分。最新版本的Drools统一了ruleflow-group和agenda-group的行为,所以您使用哪一个都无关紧要(即使我推荐使用agenda-group)。
然后,你用来激活一个流组的方式在我看来是不正确的。
这就是我要做的:
1)在您的规则中使用agenda-group:
rule "Rule 1"
lock-on-active true
agenda-group "Group A"
when
$c: Product()
then
...
end
rule "Rule 2"
lock-on-active true
agenda-group "Group A"
when
$c: Product()
then
...
end 2)在触发规则之前,将焦点设置在议程组上:
kieSession.getAgenda().getAgendaGroup("Group A").setFocus();
kieSession.fireAllRules();这应该能起到作用。
这些规则在我看来仍然很奇怪,但可能是因为你只是在做POC。只需要提醒一下:您不应该依赖于您的规则在中的顺序来获得预期的输出DRL。
希望能有所帮助,
https://stackoverflow.com/questions/47806322
复制相似问题