简体   繁体   中英

Drools: Why does this rule fire incorrectly?

My drl is:

rule "Active Orders"
    dialect "mvel"
    //no-loop
    when
        m: Order( status == Order.ENABLED, id : id )
    then
        System.out.println( "Order Id is: " + id );
        modify ( m ) 
        { 
            status = Order.DISABLED  
        };
end

I pass a single Order instance to the drools like this:

Order order = new Order();
order.setId(100);
order.setStatus( Order.ENABLED );
ksession.insert( order );

ksession.fireAllRules();

I am seeing that the rules are fired infinitely with message:

Order Id is: 100
Order Id is: 100
Order Id is: 100
.....

I can understand the infinite-loop, but the key thing is i am setting Order Status to DISABLED in modify block:
status = Order.DISABLED

Therefore, the when rule is fired again....The WHEN condition ie status == Order.ENABLED , should not be satisfied, and i should not see the system.out.println message more than once.

Any idea, what am i doing wrong?
(Pls note: My problem is not Infinite loop, but why rule is evaluated incorrectly after object modification)

The syntax in your modify block is wrong (actually I'm not sure why it even compiles and what it is doing). Try this:

modify(m){
    setStatus(Order.ENABLED);
}

Hope it helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM