Off the top of my head, I'm not sure Jess (or other clients of your
class) will react to change events being fired during a call to a
getter method; not only calcTime(), but also presumably Jess will be
calling getElapsedTime(), and the results might be odd.
But from your description, I suspect the problem is more pedestrian.
How many threads are involved? For it to work the way you're
expecting, there would need to be two: one calling calcTime(), and
the other calling Rete.run() (or the equivalent.) It sounds to me as
if you just have one that calls run() after calling calcTime(). If
I'm wrong, then will you please describe what you're doing?
On Jan 4, 2007, at 7:37 PM, Mike Stacey wrote:
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 owner-jess-
[EMAIL PROTECTED]
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
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]
--------------------------------------------------------------------