[rules-users] RE: Newbie help for rule that won't fire. What am I missing?

Bagwell, Allen F afbagwe at sandia.gov
Tue Apr 22 18:01:52 EDT 2008


So I at least got my rule to activate after trying something a little different. But now I'm confused.

So here is how I changed the LHS of the rule.

Original:
when
   $rt : RuleTimer(timedOut == true)

Changed to:
when
   $rt : RuleTimer()
   eval($rt.timedOut == true)


So I'm left scratching my head asking why does the first one not work when timedOut changes from false to true, but the second one does? I thought they would be doing exactly the same thing? I have examples of other simple rules where the in-line eval statement wasn't needed. For example:

when
   $brightness : MyVariable(uniqueName == "ds1 at brightness", currentValue >= 0.5)

This works/activates as-is when the current value changes to 0.5 or above. In both cases I created each object and inserted them into working memory as dynamic facts.  So why does one type of object/fact require an in-line eval and the other doesn't?

Thanks!
-Allen


-----Original Message-----
From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Bagwell, Allen F
Sent: Tuesday, April 22, 2008 8:19 AM
To: Rules Users List
Subject: [rules-users] Newbie help for rule that won't fire. What am I missing?


Drools newbie here in need of help.  I'm missing something fundamental here, and I just can't see it.  The following doesn't work for me:

In my rule file:

---------------------------------
rule "timer goes off"
        when
                $rt : RuleTimer(timedOut == true)
        then
                System.out.println( $rt.getUniqueName() + " went off.");
end
--------------------------------

Here's what I'm doing in the code after all the usual setup of compiling the rule file (which drools reports having no errors).
Additionally I can report that yes I HAVE loaded the compiled rule file into the session, because I have several other simple rules in it, and they do activate and fire when the conditions are met.  I've just isolated the above rule which is part of the problem.

----------------------------------------------------------
// make a timer lasting two seconds.
RuleTimer timer1 = new RuleTimer("Timer1",0,0,2);
// make a timer lasting five seconds.
RuleTimer timer2 = new RuleTimer("Timer2",0,0,5);

// insert my RuleTimers to be dynamically updated.
session.insert( timer1, true );
session.insert( timer2, true );

// sleep 2.5 seconds, timer 1 should time out
Thread.sleep(2500);

timer1.calculateTimeLeft();
timer2.calculateTimeLeft();

session.fireAllRules();

//sleep another 2.750 seconds, timer 2 should time out.
Thread.sleep(2750);

timer2.calculateTimeLeft();

session.fireAllRules();
logger.writeToDisk();
session.dispose();
------------------------------------------------

For reference, here's some of the methods being called in the RuleTimer class...

-------------------------------------------------

public void calculateTimeLeft()
{
        if (expireInterval >= 0)
            timeLeft = expireInterval - (Tut.getWallTime() - timeBegin);

        if (timeLeft <= 0)
        {
            setTimedOut(true);
        }
}

public void setTimedOut(boolean b)
{
        boolean oldTimedOut = timedOut;
        timedOut = b;
        changes.firePropertyChange("timedOut", oldTimedOut, timedOut); }

public final boolean isTimedOut()
{
        return timedOut;
}

---------------------------------------------------

And finally here's the audit log output for the drools session. The objects were inserted. They were dynamically updated. But their was no rule activation (see the rule at top of post):

---------------------------------------------------

Object inserted (1):
uniqueName: Timer1
timedOut: false

Object inserted (2):
uniqueName: Timer2
timedOut: false

Object updated (1):
uniqueName: Timer1
timedOut: true

Object updated (2):
uniqueName: Timer2
timedOut: true

------------------------------------------------

So can any sharp eye tell me what I'm doing wrong here? It seems pretty simple and straightforward, but I'm confounded as to why I get no rule activation.

thanks!
Allen


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users






More information about the rules-users mailing list