Wolfgang,
thank you so much for your remarks! It's really interesting:
- I tried the approach to update the parent whenever a child is
modified before - without any success
- Now I changed my rule to your (definitely much better) suggestion
- and it works!
So despite of the fact that I'm really happy to have this one solved I would
really be interested in what the problem with the forall is.
Is it possible that a forall statement creates some kind of copy or "summary"
of the facts to be evaluated and is checked only once? Like an eval
statement?
Anyways - thank you so much for your help!
Best regards
Georg
Von: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] Im Auftrag von Wolfgang Laun
Gesendet: Montag, 2. August 2010 12:15
An: Rules Users List
Betreff: Re: [rules-users] Drools + EMF + CDO
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.
(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
-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