[rules-users] @PropertyReactive optimizations broken when using 'this' keyword

mikegai mike.d.gai at gmail.com
Tue Jun 5 20:16:38 EDT 2012


I'm getting activations that I shouldn't when using the 'this' keyword on
@propertyReactive objects. Here's a simplified example:

package bug
dialect "mvel"

declare Monkey
    @propertyReactive
    name:String
    emotion:String
    hot : boolean
end

declare Barrel
    @propertyReactive
    topMonkey:Monkey
end

rule "Initial Facts" when
then
    monkey =new Monkey("Thomas","sad", false)
    insert (monkey)
    insert (new Barrel(monkey))
    insert (new MonkeySuit(monkey, false))
end

//This will loop forever even it shouldn't (it's not modifying any of the
properties in the constraint)
//To fix, reinstate the watch annotation below to correct the watched
property list
rule "When a monkey is on top and his name is Thomas he should be made
happy" when
    Barrel($monkey: topMonkey)
    Monkey(this==$monkey, name=="Thomas" ) //@watch(!*,name)
then
    System.out.println($monkey.getName() + " should be happy!")
    modify ($monkey) {
        setEmotion("happy")
    }
end

It's only when using the "this" keyword. Apparently it is including the
"this" in the inferred property watch list since when I clear the watch list
and rebuild it correctly using the @watch annotation, all works fine.

Has the "this" keyword been deprecated? I can't see any sign that it has so
this appears to be a bug. For now I'm getting it to work by matching my
facts on unique Ids instead of "this" but "this" is handier when an Id
property is unavailable.

--
View this message in context: http://drools.46999.n3.nabble.com/PropertyReactive-optimizations-broken-when-using-this-keyword-tp4017766.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list