Originally posted by Jerome BG:
Hi,
I am an intern trying to use jess to create a rule engine that will control a persons profiile (answers to questions that corralate to services that will/wont be run. I am new to both java and jess and REALLY struggling to make progress in this. ive read your book and 2-3 on java in the last month ...
-Ive come to the conclusion that i need the engine in a continuous state to have this function properly ... My problem is that i cant find a simple example with the jess engine in its own thread
The "runUntilHalt()" method is, indeed, what you want to use if you need the engine to just sit there and fire rules forever in its own thread. Note that that's what it will do: fire rules. Calling "runUntilHalt()" in its own thread won't magically make Jess methods you can on other threads "jump" onto this thread. I say this only because one of your questions below makes it sound like you're unsure of that point.
Anyway, to call this method (or any method) in its own thread, you just need to define a "Runnable" class containing the code you want to execute. One way would look like this:
[qb]
Also in the gui i make a static method which is my main class
Then when the action is performed (ie button pressed) i simply call the method i wanna use with its parameters ...is this ok? as in will that still cause the gui to freeze even though RE will be in its own thread
Any method you call from the GUI thread will execute on the GUI thread. If you call a Jess method like, for example assertFact(), and then that method will run on the GUI thread, but if that method activates some rules, those rules will fire in your runUntilHalt() thread, because rules are fired by that method.
Finally ive read through every post i could find here at the ranch and you say that store and fetch are the best ways to transport info between java n jess ...now in my case will that hold true
store and fetch are a simple way to do this. There's no "best" way.
I think ONE of my major problems is knowing how to know when my varibles are ready for retrivable!
Doing this with Jess is no different than doing it without. Communication between threads in a Java program involves using the wait() and notify() methods. Schematically, you'd probably want to do something like this:
In your GUI event handler, start a new thread "T". On thread "T", assert your facts (or whatever you need to do to Jess), then call wait() on some object. Meanwhile, on the Jess thread, the rules will fire. When a rule wants to report results, it stores them, then calls notify() on that same object. Thread "T"'s call to wait() will return in response to calling notify(), and "T" can then confidently fetch the results.
Now, you have to ask yourself whether you actually need both threads. Maybe rather than having runUntilHalt() run on its own thread, you could simply call run() on "T" after asserting the facts, and then when run() returns, you could collect the results.
Finally, as I said, store/fetch is just one way. The Jess rule can call any Java method to report results. So you can provide a method in your Java code, and then call it from your Jess code; that Java method can then store the data for further processing by your Java code -- or it can actually do the processing itself!
Now, you have to ask yourself whether you actually need both threads. Maybe rather than having runUntilHalt() run on its own thread, you could simply call run() on "T" after asserting the facts, and then when run() returns, you could collect the results.
Note that that's what it will do: fire rules. Calling "runUntilHalt()" in its own thread won't magically make Jess methods you can on other threads "jump" onto this thread. I say this only because one of your questions below makes it sound like you're unsure of that point.
Originally posted by Jerome Butcher-Green:
-i dont really understand what limits your saying that running it this way would have
(and sorry about the name ...i rarly -aside from government papers- go through the trouble of typing/writing out my full name ...proly cause most databases/forms dont even have space for all the charaters)
I just had the craziest dream. This tiny ad was in it.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|