问题
I tried a sample example to see how lock-on-active works. When I fire the rule without using agenda-group everything seems fine. But when i uncomment the agenda-group in the below code and set focus to group "Group B" no rules are fired.
Rule
rule "Additional Rs.1 tax for books above Rs.10"
//agenda-group "Group B"
lock-on-active true
when
$o: Product(name=="Book",amount>10)
then
System.out.print($o.getAmount()+"-->");
modify ($o) {
setAmount($o.getAmount()+1);
}
System.out.println($o.getAmount());
end
rule "Additional Rs.2 tax for books above Rs.20"
//agenda-group "Group B"
lock-on-active true
when
$o: Product(name=="Book",amount>20)
then
System.out.print($o.getAmount()+"-->");
modify ($o) {
setAmount($o.getAmount()+1);
}
System.out.println($o.getAmount());
end
Code used for firing rules
KieServices kieServices=KieServices.Factory.get();
KieContainer kieContainer=kieServices.getKieClasspathContainer();
KieSession kieSession=kieContainer.newKieSession("ksession-lockOnActive");
Product product=new Product();
product.setName("Book");
product.setAmount(11);
Product product2=new Product();
product2.setName("Book");
product2.setAmount(21);
kieSession.getAgenda().getAgendaGroup("Group B").setFocus();
kieSession.insert(product);
kieSession.insert(product2);
kieSession.fireAllRules();
Output without agenda-group
21-->22
11-->12
22-->23
回答1:
I was using older version of Drools ( 6.2.0 Final) . When I changed it to 7.4.1. The code worked
来源:https://stackoverflow.com/questions/47827625/understanding-lock-on-active-with-agenda-group