[rules-users] Problem using 'not contains'
Bagwell, Allen F
afbagwe at sandia.gov
Tue Apr 21 16:06:45 EDT 2009
It turns out that our Satellite class was refactored and along the way it lost its equals and hashCode methods (previously inherited).
After putting Eclipse-generated methods into the class, the rule worked as expected.
Thanks!
-A
-----Original Message-----
From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Greg Barton
Sent: Monday, April 20, 2009 7:28 PM
To: Rules Users List
Subject: Re: [rules-users] Problem using 'not contains'
It must be another factor. In the attached code, the rule only fires once, as it should. (Using drools 5)
Allen, are your equals/hashCode methods for Satellite consistent? A problem in those could cause this kind of behavior. The ones in the attached code are generated from eclipse. They're overkill, but always work well. :)
--- On Mon, 4/20/09, Edson Tirelli <tirelli at post.com> wrote:
> From: Edson Tirelli <tirelli at post.com>
> Subject: Re: [rules-users] Problem using 'not contains'
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Monday, April 20, 2009, 6:16 PM
> Allen,
>
> I am not sure what is happening, because the correct way is to call
> a modify/update on $sm:
>
> when
> $sat : Satellite(isOverhead == true)
> $sm : SatManager($ls : listOfOverheadSats not contains
> $sat)
> then
> $ls.add($sat);
> update( $sm );
> end
>
> This should not loop because of the condition itself, since now the
> "not contains" condition will be false and will prevent the loop.
>
> Can you double check there isn't another rule that is causing the
> loop?
> Otherwise, please open a JIRA.
>
> Regarding the question, drools manages collections as attributes in
> the same way it manages any other kind of "Object"
> attribute. Although, in
> drools 4, shadow facts do a shallow copy on collection attributes that
> sometimes require some care when working with evals(). But this is not
> your case.
>
> []s
> Edson
>
>
>
> 2009/4/20 Bagwell, Allen F <afbagwe at sandia.gov>
>
> >
> > This is in Drools 4.0.7
> >
> > I have a class called SatManager with a field:
> >
> > ArrayList<Satellite> listOfOverheadSats
> >
> > That has an appropriate getter method.
> >
> > I have a relatively simple rule that goes something
> like this:
> >
> > when
> > $sat : Satellite(isOverhead == true)
> > $sm : SatManager($ls : listOfOverheadSats not
> contains $sat)
> > then
> > $ls.add($sat);
> >
> > My problem is that Drools doesn't understand that
> the ArrayList has been
> > modified, therefore this rule always fires on the same
> satellite if the sat
> > object changes in any other way.
> >
> > I've tried adding:
> >
> > update($sm);
> >
> > To the consequence, but that only caused the rule to
> re-fire infinitely --
> > even with the no-loop keyword applied.
> >
> > So my question is how does Drools manage its knowledge
> of changes to
> > Collections embedded in fact objects? The documention
> for the 'contains/not
> > contains' keyword did not explain this.
> >
> > I'm really stumped here.
> >
> > Allen F. Bagwell
> > e-mail: afbagwe at sandia.gov
> > phone: 505/284-4517
> > fax: 505/ 844-7886
> >
> > Ask your doctor if medical advice from a TV commercial
> is right for you.
> >
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
>
> --
> Edson Tirelli
> JBoss Drools Core Development
> JBoss, a division of Red Hat @ www.jboss.com
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list