[rules-users] Rules not firing when expected after retracting object in list

Swindells, Thomas TSwindells at nds.com
Wed Jul 21 11:38:59 EDT 2010


Why is rule 1 written the way it is? Why can't you just do:
rule "Rule 1 - Remove all A's that have property set to 123"
  salience 1000
when
  $anA : A( property == "123" )
then
      retract ($anA)
end

Thomas

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Justin Beltran
Sent: 21 July 2010 16:28
To: rules-users at lists.jboss.org
Subject: [rules-users] Rules not firing when expected after retracting object in list

Hi,

I'm coming across some weird behavior in Drools 4.0.7, but maybe it's just cause I don't understand I how Drools works.  Assume, there's a class "A" that has a property called "property".

As facts, I have the following list of A's:
A1, property = 123
A2, property = 345
A3, property = 123

I have two rules as follows:

rule "Rule 1 - Remove all A's that have property set to 123"
  salience 1000
  lock-on-active true
when
  $listOfAs : ArrayList collect(A( property == "123" ))
then
  for (Object a: $listOfAs ) {
      retract (a)
  }
end

rule "Rule 2 - Do stuff with remaining A's"
  salience 900
  lock-on-active true
when
  $listOfAs : ArrayList collect(A())
then
...
end

My understanding is "Rule 1" will remove the facts of class A that have property to 123.  When it gets to "Rule 2", shouldn't the "listOfAs" only have that one A that remains (i.e. the one where property is set to "345").   What I'm noticing is that "Rule 2" just doesn't execute at all even though I'm assuming there is still one "A" object that hasn't been retracted.  If I comment out the "retract" it executes "Rule 2" fine.

Am I missing something about these rules work?

Thanks.
Justin

________________________________

**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100721/463bc8cb/attachment.html 


More information about the rules-users mailing list