I think Ashish Majmundar wrote:
> 
> Please pardon my ignorace, but I am having some
> difficulty with runUntilHalt(). When I execute the
> code with 'run()' it works, but when I use
> 'runUntilHalt()' it does not work. Here's the code:
> 
...

You did not look at the below output very carefully. It's just a
matter of timing. You start a separate Thread running with
runUntilHalt() (near the line I've marked ***1***) and then
immediately test CurrentState (at ***2***). At point ***2***, you
assume (falsely) that handle-up-rule has already fired. In fact, it is
activated (line ***4***) but doesn't fire until line ***3***. By then
you're already retracting handle-up and doing other things; you don't
check CurrentState again, although you can see at line ***5*** it has
the value you're expecting. The code continues to check for new values
before the rule has a chance to set them.

Anyhow, this is now not specifically a Jess issue but just a
multithreaded programming issue. If you want the engine running in a
separate Thread, then you'll need to interact with it according to the
usual principles of multithreaded programming. For example, you can
provide a synchronized method signal() which locks some object and calls
notify(), and your handle-up-rule can call this method. Meanwhile your
Java mainline can call wait() on that same object, and when it wakes
up it knows that the rule has fired.

> 
> =====================================================
> Output with Thread (runUntilHalt()) instead of 
> multiple run() commands
> =====================================================
> Reading batch files: scriptlib.clp, test.clp.
> handle-up-rule: +1+1+1+t
> end-exec: +1+1+1+t
>  ==> f-0 (initial-fact)
> Thread started with (run-until-halt) ;; ***1***
> Asserting fact 'handle-up'...
>  ==> f-1 (handle-up)
> ==> Activation: handle-up-rule :  f-1 ;; ***4***
> Facts after the asserting 'handle-up'
> 
> Listing facts...
> (initial-fact)
> (handle-up)
> Retrieved CurrentState object from JESS, current state 
> = 3 ;; ***2***
> 
> Listing facts...
> (initial-fact)
> FIRE 1 handle-up-rule f-1 ;; ***3***
> (handle-up)
> Executing handle-up-rule...
> CurrentState: setCurrentState: passed integer is 2 ***5***
> Retracting 'handle-up'
>  <== f-1 (handle-up)
> <== Activation: handle-up-rule :  f-1
> Facts after the retract
> 
> Listing facts...
> (initial-fact)
> CurrentState: setCurrentState: passed integer is 1
> Set currentState = 1 from the reference to the Java
> object
> Asserting fact 'handle-up'...
>  ==> f-2 (handle-up)
> ==> Activation: handle-up-rule :  f-2
> Facts after the asserting 'handle-up'
> 
> Listing facts...
> (initial-fact)
> (handle-up)
> Retrieved CurrentState object from JESS, current state
> = 1
> 
> Listing facts...
> (initial-fact)
> (handle-up)
> Retracting 'handle-up'
>  <== f-2 (handle-up)
> <== Activation: handle-up-rule :  f-2
> Facts after the retract
> 
> Listing facts...
> (initial-fact)
> 
> Issuing 'stop-exec'
>  ==> f-3 (stop-exec)
> ==> Activation: end-exec :  f-3
> FIRE 2 end-exec f-3
> 
> =====================================================
> Any help is greatly appreciated!!!!!!!!!!!!!!!!
> 
> Thanks,
> - Ashish
> 
 



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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