[rules-users] Drools + EMF + CDO

Wolfgang Laun wolfgang.laun at gmail.com
Mon Aug 2 06:14:34 EDT 2010


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 at 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 at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100802/27ada64b/attachment.html 


More information about the rules-users mailing list