On 2 August 2010 12:14, Wolfgang Laun <wolfgang.laun(a)gmail.com> wrote:
Several remarks:
(1) Make sure that a parent is asserted after all of its children.
Otherwise initial evaluation will not comprise the entire children's list.
What I meant is: after all children have been adder to the parent's list,
and *then* insert the parent.
(2) After changing a child's state, update the parent.
(3) The rule as you have it now is somewhat circumstantial. A simpler
approach would be
rule NoUpChild
when
$p : Device( $children : eContents, eContents.size > 0 )
not( Device( state == "UP" ) from $children )
then
System.out.println( $p.getId() + ": no child up" );
end
(4) If you have a "parent" field, this could even be written:
rule NoUpChild
when
$p : Device( children.size > 0 )
not( Device( parent == $p, state == "UP" ) )
then
System.out.println( $p.getId() + ": no child up" );
end
And this would make the additional update according to (2) unnecessary.
-W
2010/8/2 Georg Maier <Georg.Maier(a)cjt.de>
> Hi,
>
>
>
> I’m trying to figure out an issue for three days now and I’m getting kind
> of desperate, so I hope someone can help.
>
> I’m using Drools in combination with an EMF model which is modeling a
> computer network. On init, I read the whole structure of the model and
> insert all elements into the working memory. Some of the entities share the
> super class “Device” which has an attribute “state”.
>
>
>
> Now I’m having the following rule to change an attribute of one of the
> model entities:
>
>
>
> *rule* "Set received status to model"
>
> *when*
>
> $event : SomeEvent (
>
> $hostname : hostname,
>
> $hoststate : hoststate,
>
> $timestamp : timestamp
>
> )
>
>
>
> $device : Device (
>
> name == $hostname
>
> )
>
>
>
> *then*
>
> *modify*($device) {
>
> setState($hoststate);
>
> }
>
> db.commit(*false*);
>
>
>
> *retract*($event);
>
> System.err.println("Set status of " + $device + " to
" +
> $hoststate);
>
> *end*
>
>
>
> … which works perfectly fine. Anyway, what I want to do in this test case
> is to *react whenever all child devices of a mutual parent device* (e.g.
> hosts on one switch) are no longer reachable. I thought of a rule like the
> following:
>
>
>
> *rule* "Parent Children Test"
>
> *when*
>
> $parent : Device (
>
> $children : eContents,
>
> eContents.size > 0
>
> )
>
>
>
> *forall* (
>
> $child : Device (
>
> state == "DOWN"
>
> ) *from* $children
>
> )
>
>
>
> *then*
>
> …
>
> *end*
>
> * *
>
> … which by the way worked perfectly fine as long as I was not using
> objects from a model. My first idea was that for some strange reason the
> object might get copied so that I actually would have two different
> references after modifying it, but this is not the case. When I initialize
> the rule base with the circumstances that the second rule would fire, it
> really does. It just seems as it would not being evaluated after changing
> the attribute, but this is not the case either! So all I can think of is
> some strange caching, maybe in combination with the *forall *statement?
> Maybe someone has some experience when using Drools with EMF + CDO and
> experienced as similar issue?
>
> Any help would be very very very much appreciated!
>
> Thanks in advance
>
>
>
> Georg
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>