Question

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 i.e 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)

Was it helpful?

Solution

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,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top