I have a java class which is a bean and fires events when properties
change. My rules fire when this property attains certain values. The
property is a timer which calculates the elapsed time since some
previous event happened. This is implemented in a loop within the
java class. My jess rule needs to fire when the timer gets to a
particular elapsed time.

Problem: The rule doesn't fire until the method returns, by which
time the timer has run further than it needs to. I have checked with
watch facts and the facts are being asserted in jess continuously but
yet the rule doesn't fire until the caclTime() method exits.

In the examle below, when the Terminates rule fires the timer has
reached a bit over 10000 instead of 7000. Any suggestions would be
greatly appreciated of course. I hope the following is clear enough
to follow...

The java code
-------------
Class PropTime

   public void calcTime()
    {
        long etime = getElapsedTime();
        // Loop condition only for test purposes at the moment
        while(etime < 10000)
        {
                etime = getElapsedTime();
        }
    }
   
    /** Returns elapsed time in milliseconds.
      * PROBLEM: 'Terminates' rule not firing until calcTime() returns
      */
    
    public long getElapsedTime() 
    {
       if (startTime == -1) 
       {
           elapsedTime = 0;
           System.out.println("0");
       }
       if (running)
       {
           oldElapsedTime = elapsedTime;
           elapsedTime = System.currentTimeMillis() - startTime;
           // Terminate rule should fire when this reaches a given
value
           eventSupport.firePropertyChange("elapsedTime", new
Long(oldElapsedTime), new Long(elapsedTime));              
       } 
       else 
       {
           elapsedTime = stopTime-startTime;
       }
       return elapsedTime;
    }

The jess code
-------------

(defclass pTime PropTime);; create deftemplate from javabean
(bind ?pT (new PropTime));; create bean
(definstance pTime ?pT);; add bean (shadow fact) to jess memory

; PROBLEM: This rule doesn't fire until the calcTime() method
; finishes
 
(defrule Terminates
    ; Terminate when timer reaches 7000
    (pTime(elapsedTime ?et&:(>= ?et 7000)))     
     =>
    (printout t ">>>>>>>Terminates: Elapsed time:  "?et  crlf)
    (call ?pT stopPropTimer))



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to