本文介绍了了解议程组的主动锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一个示例示例,以查看主动锁定的工作方式.当我在不使用议程小组的情况下发出规则时,一切似乎都很好.但是,当我在以下代码中取消注释该议程组并将焦点设置为"B组"时,则不会触发任何规则.

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 "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

用于触发规则的代码

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();

没有议程组的输出

21-->22
11-->12
22-->23

推荐答案

我使用的是Drools的旧版本(最终版6.2.0).当我将其更改为7.4.1.代码有效

I was using older version of Drools ( 6.2.0 Final) . When I changed it to 7.4.1. The code worked

这篇关于了解议程组的主动锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 20:09