understanding lock-on-active with agenda-group

烂漫一生 提交于 2019-12-24 16:18:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!