Hi,

Trying to build net mgmt system but having problem with basic cause/effect (mostly not understanding the engine).

I have a a Port object that contains a Card object. They both have separate states (up or down). I want to have a Port go to down state if the containing Card goes to down state - very basic now until i get the feel of it.

The state of the Card changes if a Notification is injected into the session (at least this is my understanding)

Here are my rules:

rule "card going down"
    when
    $card : Card($name : name , state == State.UP)
        $notif : Notification( id == $name, type == NotificationType.CARD , state == State.DOWN )
    then
    System.out.println("  got notification for card down " + $card );
    modify($card) {
    setState(State.DOWN);
    }
    retract($notif);
end

// is the following rule correct??

rule "port going down"
    when
    $port : Port($name : name , state == State.UP, $card : card)
        Card ( state == State.DOWN) from $card
    then
    System.out.println("  port down because card is down  port: " + $port + " card: " + $card );
     modify($port) { 
    setState(State.DOWN);
    }
   
end

Here is the test case in a nutshell:

Port port1 = new Port();
Port port2 = new Port();
                        port1.setName("port1");
port2.setName("port2");

                        Card card1 = new Card();
card1.setName("port1 card1")
                        port1.setCard(card1);
                       // stateful session 
                        ksession.insert(port1);
ksession.insert(port2);
ksession.insert(card1);

System.out.println("  firing rules");
new Thread(new Runnable() {
public void run() {
ksession.fireUntilHalt();
}
}).start();

System.out.println("*** injecting notification down");
Notification notif = new Notification();
notif.setType(NotificationType.CARD);
notif.setState(State.DOWN);
notif.setId("port1 card1");
FactHandle notifHandle = ksession.insert(notif);


                        ksession.halt();
                        ksession.dispose()


I would expect the card down notification to cause the port to do down by the second rule above but it does not fire.

Here is output

  card1: Card [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b]
OBJECT ASSERTED value:Port [state=UP, name=port1, card=Card [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b]] factId: 1
OBJECT ASSERTED value:Port [state=UP, name=port2, card=Card [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b]] factId: 3
OBJECT ASSERTED value:Card [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b] factId: 5
  firing rules
3
*** injecting notification down
ACTIVATION CREATED rule:card going down activationId:card going down [6, 5] declarations: $name=port1 card1(5); $notif=org.plugtree.examples.model.Notification@4a9a7d(6); $card=Card [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b](5)
OBJECT ASSERTED value:org.plugtree.examples.model.Notification@4a9a7d factId: 6
BEFORE ACTIVATION FIRED rule:card going down activationId:card going down [6, 5] declarations: $name=port1 card1(5); $notif=org.plugtree.examples.model.Notification@4a9a7d(6); $card=Card [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b](5)
  got notification for card down Card [state=UP, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b]
OBJECT MODIFIED value:Card [state=DOWN, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b] factId: 5
OBJECT RETRACTED value:org.plugtree.examples.model.Notification@4a9a7d factId: 6
AFTER ACTIVATION FIRED rule:card going down activationId:card going down [-1, 5] declarations: $name=port1 card1(5); $card=Card [state=DOWN, name=port1 card1, ne=org.plugtree.examples.model.NE@1e2670b](5)



Is the second rule written incorrectly? or do i have a gap in my expectations of how the engine should work (or both)

Thanks in advance,

Joe.