Hi!
 
rete.run() or rete.executeCommand("(run)") both return only after all activated rules have fired. If you can infer from this fact, that all commands have been executed, this is it.
 
On the other hand I'm not sure if your pseudo code correctly states what you are trying to do. rete.run() just runs the engine once, firing 0 to N rules (see above), and then exits. After having defined another instance after rete.run() has exited, you need to call rete.run() again. You might possibly want to run the engine continuously in a separate thread using Rete::runUntilHalt(). In that case, you'd need some synchronization mechanism (e.g., the flags you mentioned).
 
Note that you can use the following Rete methods directly: Rete::clear(), Rete::reset(), and Rete::run(). Further, you need to call Funcall::execute(...) in order execute the (definstance) function call.
 
Thomas
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Raj Ganesan
Sent: Tuesday, October 17, 2000 7:49 PM
To: [EMAIL PROTECTED]
Subject: JESS: Thread question

Jess experts:
 
How do I know if Jess has completed a scan of all the rules in its knowledge base?
I am trying to build a command-response framework, where the commands are (short-lived) beans that are instantiated prior to a Jess run(), and then are released after the results are obtained. I'm trying to figure out if there is some way I can tell if Jess is "done" (perhaps set a field in the bean itself).
 
Specifically, I want to know if the following design/pseudocode will work:
 
public class RuleEngine extends Thread
{
    private Rete rete;
    public RuleEngine()
    {
          rete = new Rete();
         rete.addUserpackage(new MiscFunctions());
          rete.addUserpackage(new jess.ReflectFunctions());
        // Read in the rules
          rete.executeCommand("(clear)");
          rete.executeCommand("(batch sample.clp)");
    }
    public void run()
    {
         // create bean instance
        Funcall f = new Funcall("definstance", rete);    
         f.add(new Value("Command", RU.ATOM));
         f.add(new Value(command));
        // code to "lock" the bean
         rete.executeCommand("(reset)");
         rete.executeCommand("(run)");
        // code to release this instance
        // code to "unlock" bean
        {
            sleep for some time
        }
   
    }
}

Reply via email to