Now I am really confused, when I try to set some condition on the MyDataObject itself like this
rule "Identify Java Objects"
lock-on-active
when
$mo : MyDataObject($mf:testFieldData < 20);
$c : Cycle();
then
System.err.println("MYOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData());
end
Then this still fires every single time, even when testFieldData is over 20….
-Chris
From:
rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Greg Barton
Sent: Wednesday, September 23,
2009 10:02 AM
To: Rules
Users List
Subject: Re: [rules-users]
persistent java objects in working memory
You've answered your own
question. :) The rule you've given will only fire when the object is
asserted or modified. (And you have to inform the engine of the
modification.) You have to inform the engine that the object has been
modified every cycle. (And if you want the engine to fire that rule even if the
object has not been modified, you can still inform the engine. All that
does is force the rules to reconsider the object.)
However, the way I'd do it is to have a new object that is inserted on each
iteration. Let's call it "Cycle" and give it a count. Then your
rule would look like this:
rule "Identify Java Objects"
lock-on-active
when
$mo : MyDataObject();
$c : Cycle();
then
System.err.println("MYOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData() + " on Cycle " + $c.getCount());
end
When the iteration is over, you would retract the Cycle object. (Only one
Cycle should be in working memory at once, and it's a good idea to have a rule
that enforces that invariant.) You should follow this pattern for any
rule you want to guarantee to fire on each iteration.
From: Chris
Richmond <crichmond@referentia.com>
To: Rules
Users List <rules-users@lists.jboss.org>
Sent: Wednesday, September 23,
2009 2:15:35 PM
Subject: [rules-users] persistent
java objects in working memory
Hello,
I am trying to create a set of java objects, which I insert into the session at startup. Then at regular timed iterations I want to examine the values of those objects. During the timer iteration, some fields may have been changed by the primary program. So I have a rule for now that is just trying to identify that the do indeed exist on each iteration:
rule "Identify Java Objects"
lock-on-active
when
$mo : MyDataObject();
then
System.err.println("MYOBJECT in system: " + $mo.getID + " | " + $mo.getTestFieldData);
end
As I said, at startup I insert 3 of these objects into my session, then every 10 seconds I just want to ensure they are there. However the output from this rule only fires on the firet iteration, after that the rule doesn’t fire. I am not retrcating the objects or even concerning myself with the FactHandle, as I plan to leave them in working memory and change values on those 3 objects from the main application in each application loop, then make decisions in the rule engine based on the values of those 3 objects. However, for now I just nee to find out why the objects only live for my first loop and call of session.fireAllRules().
Any ideas or what I am doing wrong?
Thanks,
Chris