Wolfgang, thanks much. Helps me understand what's going on under the hood a little better.<div><br></div><div>I'm having a similar issue with the next higher container. I have say, PathElements which contain a collection of Ports. Same problem as before - if one Port goes down then the PathElement goes down. I can't seem to express it properly in DRL<br>
<br>The only thing that comes to me is:</div><div><br></div><div><div>rule "pe down"</div><div> when</div><div> // pe is active </div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>$pe : PathElement(state == State.UP )</div>
<div> <span class="Apple-tab-span" style="white-space:pre">        </span>// and any one of the ports are down</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>Port ( state == State.DOWN ) from $pe.ports</div>
<div> then</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>System.out.println(" setting pe down" + $pe );</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>modify($pe) {</div>
<div> <span class="Apple-tab-span" style="white-space:pre">                </span>setState( State.DOWN);</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>end</div><div><br></div><div>However, like my other naive attempts, it is not firing after the Notification is inserted into WM. I tried many variations using a 'collect' clause, etc to no avail. Any additional insight would be greatly appreciated.</div>
<div><br></div><div>BTW, once i get a handle on the one-to-many associations I promise I'll stop :-)</div><div><br></div><div><br></div><div class="gmail_quote">On Mon, Apr 2, 2012 at 11:47 PM, Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">See inline.<br>
<div class="im"><br>
On 02/04/2012, Joe Zendle <<a href="mailto:jzendle@zentechinc.net">jzendle@zentechinc.net</a>> wrote:<br>
><br>
><br>
> Here are my rules:<br>
><br>
> rule "card going down"<br>
> when<br>
</div> // There is a Card in state UP and...<br>
<div class="im">> $card : Card($name : name , state == State.UP)<br>
</div> // a matching notification to DOWN<br>
<div class="im">> $notif : Notification( id == $name, type == NotificationType.CARD ,<br>
> state == State.DOWN )<br>
> then<br>
> System.out.println(" got notification for card down " + $card );<br>
> modify($card) {<br>
> setState(State.DOWN);<br>
> }<br>
> retract($notif);<br>
> end<br>
><br>
> // is the following rule correct??<br>
<br>
</div>No.<br>
<div class="im"><br>
><br>
> rule "port going down"<br>
> when<br>
<br>
</div> // There is a Port in State UP and...<br>
<div class="im"><br>
> $port : Port($name : name , state == State.UP, $card : card)<br>
</div> // ...take its Card and if this is DOWN<br>
<div class="im"><br>
> Card ( state == State.DOWN) from $card<br>
> then<br>
> System.out.println(" port down because card is down port: " + $port +<br>
> " card: " + $card );<br>
> modify($port) {<br>
> setState(State.DOWN);<br>
> }<br>
<br>
</div>The difference between these two rules is that the first one is triggered by<br>
a change in WM - the emergence of a matching Notification. The second,<br>
however, is evaluated when the Port enters WM, presumably with its<br>
Card in working order. Subsequently, Port doesn't change and so evaluation<br>
is never retried.<br>
<br>
<br>
Two correct versions:<br>
<br>
when<br>
$card : Card( state == State.DOWN )<br>
$port : Port($name : name , state == State.UP, card == $card)<br>
then<br>
<div class="im"><br>
when<br>
$port : Port($name : name , state == State.UP, $card: card )<br>
</div> Card( this == $card, state == State.DOWN )<br>
then<br>
<br>
Or, assuming that Port must follow Card, for going UP and DOWN:<br>
<br>
when<br>
$card : Card( $stateCard: state )<br>
$port : Port($name : name , state != $stateCard, card == $card)<br>
then<br>
modify($port) {<br>
setState($stateCard)<br>
<div><div class="h5">}<br>
<br>
<br>
><br>
> end<br>
><br>
> Here is the test case in a nutshell:<br>
><br>
> Port port1 = new Port();<br>
> Port port2 = new Port();<br>
> port1.setName("port1");<br>
> port2.setName("port2");<br>
><br>
> Card card1 = new Card();<br>
> card1.setName("port1 card1")<br>
> port1.setCard(card1);<br>
> // stateful session<br>
> ksession.insert(port1);<br>
> ksession.insert(port2);<br>
> ksession.insert(card1);<br>
><br>
> System.out.println(" firing rules");<br>
> new Thread(new Runnable() {<br>
> public void run() {<br>
> ksession.fireUntilHalt();<br>
> }<br>
> }).start();<br>
><br>
> System.out.println("*** injecting notification down");<br>
> Notification notif = new Notification();<br>
> notif.setType(NotificationType.CARD);<br>
> notif.setState(State.DOWN);<br>
> notif.setId("port1 card1");<br>
> FactHandle notifHandle = ksession.insert(notif);<br>
><br>
><br>
> ksession.halt();<br>
> ksession.dispose()<br>
><br>
><br>
> I would expect the card down notification to cause the port to do down by<br>
> the second rule above but it does not fire.<br>
><br>
> Here is output<br>
><br>
> card1: Card [state=UP, name=port1 card1,<br>
> ne=org.plugtree.examples.model.NE@1e2670b]<br>
> OBJECT ASSERTED value:Port [state=UP, name=port1, card=Card [state=UP,<br>
> name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b]] factId: 1<br>
> OBJECT ASSERTED value:Port [state=UP, name=port2, card=Card [state=UP,<br>
> name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b]] factId: 3<br>
> OBJECT ASSERTED value:Card [state=UP, name=port1 card1,<br>
> ne=org.plugtree.examples.model.NE@1e2670b] factId: 5<br>
> firing rules<br>
> 3<br>
> *** injecting notification down<br>
> ACTIVATION CREATED rule:card going down activationId:card going down [6, 5]<br>
> declarations: $name=port1 card1(5);<br>
> $notif=org.plugtree.examples.model.Notification@4a9a7d(6); $card=Card<br>
> [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b](5)<br>
> OBJECT ASSERTED value:org.plugtree.examples.model.Notification@4a9a7dfactId:<br>
> 6<br>
> BEFORE ACTIVATION FIRED rule:card going down activationId:card going down<br>
> [6, 5] declarations: $name=port1 card1(5);<br>
> $notif=org.plugtree.examples.model.Notification@4a9a7d(6); $card=Card<br>
> [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b](5)<br>
> got notification for card down Card [state=UP, name=port1 card1,<br>
> ne=org.plugtree.examples.model.NE@1e2670b]<br>
> OBJECT MODIFIED value:Card [state=DOWN, name=port1 card1,<br>
> ne=org.plugtree.examples.model.NE@1e2670b] factId: 5<br>
> OBJECT RETRACTED<br>
</div></div>> value:org.plugtree.examples.model.Notification@4a9a7dfactId: 6<br>
<div class="im">> AFTER ACTIVATION FIRED rule:card going down activationId:card going down<br>
> [-1, 5] declarations: $name=port1 card1(5); $card=Card [state=DOWN,<br>
> name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b](5)<br>
><br>
><br>
><br>
> Is the second rule written incorrectly? or do i have a gap in my<br>
> expectations of how the engine should work (or both)<br>
><br>
> Thanks in advance,<br>
><br>
> Joe.<br>
><br>
</div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br></div>