Re: [rules-users] persistent java objects in working memory
Chris, I believe in one of your earlier emails you said that there were several MyDataObject instances in working memory. (I seem to recall you saying there were 3). When you do an "update" (or a retract, or insert) you're notifying Drools that the state of it's working memory has changed. At that time, the RuleBase is rescanned and the Agenda for rule firing is reset. During this rulebase scan, rules are Pattern matched to data in working memory. So let's say you have 2 MyDataObjects: Obj1.testDataField = 10 Obj2.testDataField = 25 If both are in working memory, both meet the criteria for "Identify My Object" so it will fire twice. Assuming nothing changed on Obj1 during the update that would modify the value above 20, it would cause rule 2 "Identify Problem" to fire. However, and this may be where your problem is, I notice that you have "lock-on-active" set for both Rule 1 and Rule 2. Looking at the Drools docs we see the following statement regarding "lock-on-active": Whenever a ruleflow-group becomes active or an agenda-group receives the focus, any rule within that group that has lock-on-active set to true will not be activated any more; irrespective of the origin of the update, the activation of a matching rule is discarded. This is a stronger version of no-loop, because the change could now be caused not only by the rule itself. It's ideal for calculation rules where you have a number of rules that modify a fact and you don't want any rule re-matching and firing again. Only when the ruleflow-group is no longer active or the agenda-group loses the focus those rules with lock-on-active set to true become eligible again for their activations to be placed onto the agenda. So I believe because "lock-on-active" is "true" the second rule will not fire as a result of an "Update". It would have to already be true at the point when you call "fireAllRules()" for it to actually run. -Original Message- From: rules-users-boun...@lists.jboss.org on behalf of Chris Richmond Sent: Wed 9/23/2009 5:33 PM To: 'Rules Users List' Subject: Re: [rules-users] persistent java objects in working memory Yes..I have these rules and the problem was I wasn't including the $c: cycle in the second rule ( I bolded it). So any rule I write subsequently has to have that $c : cycle() check in order to fire now? Not just the first rule which identifies all in memory objects and calls update on them? That seems counterintuitive..it seems like if I simply call update() on each object in the first rule, that the second should fire withought checking the Cycle object as well. Chris rule "Identify MyObject" lock-on-active when $mo : MyDataObject(); $c : Cycle(); then System.err.println("MYDATAOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData(); update($sb); end rule "Identify Problem" lock-on-active when $mo : MyDataObject($td:testFieldData < 20); $c : Cycle(); then System.err.println("OUT OF SPEC MYDATAOBJECT: " + $mo.getID() + " | " + $mo.getTestFieldData() + " | " + $td); end _____ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 11:01 AM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. _ From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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. (An
Re: [rules-users] persistent java objects in working memory
--- On Wed, 9/23/09, Chris Richmond wrote: > So you are saying I should preferably do > the update in the outer application loop rather than in the > rule action even though I am using the lock-on-active statement Basically, yes. The update statement should be used to indicate that an object has changed. Using it for other purposes is of course possible, but I'd avoid it unless there was good reason. See the attached sample project. Is this what you're doing? I put in a rule that checks the value of an object that is modified externally: rule "Conditional Match" when c : Cycle() d : Data( value < 5 ) then System.out.println( "Conditional Match: " + c + " with " + d ); end Works fine. DroolsCycle.tar.gz Description: GNU Zip compressed data ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] persistent java objects in working memory
So you are saying I should preferably do the update in the outer application loop rather than in the rule action even though I am using the lock-on-active statement session.update(FactHandle from MyDataObject, MyDataObjectThatHasChangedThisIteration) ? Also, I hope you saw.that update($sb) is a typo.. Thanks, Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 12:06 PM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory What is the $sb in the action of the rule "Identify MyObject"? Again, the "testFieldData < 20" condition will not apply properly unless you update the MyDataObject object at some point after testFieldDatahas been set. Also, it wouldn't be a good idea to call "update($mo);" in the action of "Identify MyObject," if that's what you were attempting. Without the lock-on-active directive that would result in an infinite loop. _ From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 4:41:47 PM Subject: Re: [rules-users] persistent java objects in working memory Correction to this.this does not work either..it was coincidental that I was seeing output on the 2nd rule, but it fires no matter the value of testFieldData and does not fire at all ever without the $c : Cycle() ; statement. I am talking about the second rule. The first rule fires, but my combination of upate and 2nd rule is not working and not sure why. Thanks, Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Chris Richmond Sent: Wednesday, September 23, 2009 11:34 AM To: ' Rules Users List ' Subject: Re: [rules-users] persistent java objects in working memory Yes..I have these rules and the problem was I wasn't including the $c: cycle in the second rule ( I bolded it). So any rule I write subsequently has to have that $c : cycle() check in order to fire now? Not just the first rule which identifies all in memory objects and calls update on them? That seems counterintuitive..it seems like if I simply call update() on each object in the first rule, that the second should fire withought checking the Cycle object as well. Chris rule "Identify MyObject" lock-on-active when $mo : MyDataObject(); $c : Cycle(); then System.err.println("MYDATAOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData(); update($sb); end rule "Identify Problem" lock-on-active when $mo : MyDataObject($td:testFieldData < 20); $c : Cycle(); then System.err.println("OUT OF SPEC MYDATAOBJECT: " + $mo.getID() + " | " + $mo.getTestFieldData() + " | " + $td); end _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 11:01 AM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. _____ From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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 gi
Re: [rules-users] persistent java objects in working memory
What is the $sb in the action of the rule "Identify MyObject"? Again, the "testFieldData < 20" condition will not apply properly unless you update the MyDataObject object at some point after testFieldDatahas been set. Also, it wouldn't be a good idea to call "update($mo);" in the action of "Identify MyObject," if that's what you were attempting. Without the lock-on-active directive that would result in an infinite loop. From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 4:41:47 PM Subject: Re: [rules-users] persistent java objects in working memory Correction to this…this does not work either..it was coincidental that I was seeing output on the 2nd rule, but it fires no matter the value of testFieldData and does not fire at all ever without the $c : Cycle() ; statement. I am talking about the second rule. The first rule fires, but my combination of upate and 2nd rule is not working and not sure why. Thanks, Chris From:rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Chris Richmond Sent: Wednesday, September 23, 2009 11:34 AM To: ' Rules Users List ' Subject: Re: [rules-users] persistent java objects in working memory Yes..I have these rules and the problem was I wasn’t including the $c: cycle in the second rule ( I bolded it). So any rule I write subsequently has to have that $c : cycle() check in order to fire now? Not just the first rule which identifies all in memory objects and calls update on them? That seems counterintuitive..it seems like if I simply call update() on each object in the first rule, that the second should fire withought checking the Cycle object as well. Chris rule "Identify MyObject" lock-on-active when $mo : MyDataObject(); $c : Cycle(); then System.err.println("MYDATAOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData(); update($sb); end rule "Identify Problem" lock-on-active when $mo : MyDataObject($td:testFieldData < 20); $c : Cycle(); then System.err.println("OUT OF SPEC MYDATAOBJECT: " + $mo.getID() + " | " + $mo.getTestFieldData() + " | " + $td); end From:rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 11:01 AM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. ____________ From:Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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
Re: [rules-users] persistent java objects in working memory
update($sb) is actually udate($mo) in my code, that is a type on my example Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Chris Richmond Sent: Wednesday, September 23, 2009 11:34 AM To: 'Rules Users List' Subject: Re: [rules-users] persistent java objects in working memory Yes..I have these rules and the problem was I wasn't including the $c: cycle in the second rule ( I bolded it). So any rule I write subsequently has to have that $c : cycle() check in order to fire now? Not just the first rule which identifies all in memory objects and calls update on them? That seems counterintuitive..it seems like if I simply call update() on each object in the first rule, that the second should fire withought checking the Cycle object as well. Chris rule "Identify MyObject" lock-on-active when $mo : MyDataObject(); $c : Cycle(); then System.err.println("MYDATAOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData(); update($sb); end rule "Identify Problem" lock-on-active when $mo : MyDataObject($td:testFieldData < 20); $c : Cycle(); then System.err.println("OUT OF SPEC MYDATAOBJECT: " + $mo.getID() + " | " + $mo.getTestFieldData() + " | " + $td); end _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 11:01 AM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. _ From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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 To: Rules Users List 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
Re: [rules-users] persistent java objects in working memory
Another correction. It doesn't fire every time, it fires many times when the value is not below 20. It's strange, it fires correctly for a while, but once it identifies a problem value, then it seems to fire on all values for a few iterations. It's erratic and incorrect to say the least. Perhaps my update is improperly done.. Thanks, Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Chris Richmond Sent: Wednesday, September 23, 2009 11:42 AM To: 'Rules Users List' Subject: Re: [rules-users] persistent java objects in working memory Correction to this.this does not work either..it was coincidental that I was seeing output on the 2nd rule, but it fires no matter the value of testFieldData and does not fire at all ever without the $c : Cycle() ; statement. I am talking about the second rule. The first rule fires, but my combination of upate and 2nd rule is not working and not sure why. Thanks, Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Chris Richmond Sent: Wednesday, September 23, 2009 11:34 AM To: 'Rules Users List' Subject: Re: [rules-users] persistent java objects in working memory Yes..I have these rules and the problem was I wasn't including the $c: cycle in the second rule ( I bolded it). So any rule I write subsequently has to have that $c : cycle() check in order to fire now? Not just the first rule which identifies all in memory objects and calls update on them? That seems counterintuitive..it seems like if I simply call update() on each object in the first rule, that the second should fire withought checking the Cycle object as well. Chris rule "Identify MyObject" lock-on-active when $mo : MyDataObject(); $c : Cycle(); then System.err.println("MYDATAOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData(); update($sb); end rule "Identify Problem" lock-on-active when $mo : MyDataObject($td:testFieldData < 20); $c : Cycle(); then System.err.println("OUT OF SPEC MYDATAOBJECT: " + $mo.getID() + " | " + $mo.getTestFieldData() + " | " + $td); end _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 11:01 AM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. _____ From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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 ite
Re: [rules-users] persistent java objects in working memory
Correction to this.this does not work either..it was coincidental that I was seeing output on the 2nd rule, but it fires no matter the value of testFieldData and does not fire at all ever without the $c : Cycle() ; statement. I am talking about the second rule. The first rule fires, but my combination of upate and 2nd rule is not working and not sure why. Thanks, Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Chris Richmond Sent: Wednesday, September 23, 2009 11:34 AM To: 'Rules Users List' Subject: Re: [rules-users] persistent java objects in working memory Yes..I have these rules and the problem was I wasn't including the $c: cycle in the second rule ( I bolded it). So any rule I write subsequently has to have that $c : cycle() check in order to fire now? Not just the first rule which identifies all in memory objects and calls update on them? That seems counterintuitive..it seems like if I simply call update() on each object in the first rule, that the second should fire withought checking the Cycle object as well. Chris rule "Identify MyObject" lock-on-active when $mo : MyDataObject(); $c : Cycle(); then System.err.println("MYDATAOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData(); update($sb); end rule "Identify Problem" lock-on-active when $mo : MyDataObject($td:testFieldData < 20); $c : Cycle(); then System.err.println("OUT OF SPEC MYDATAOBJECT: " + $mo.getID() + " | " + $mo.getTestFieldData() + " | " + $td); end _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 11:01 AM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. _ From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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 To: Rules Users List 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
Re: [rules-users] persistent java objects in working memory
Yes..I have these rules and the problem was I wasn't including the $c: cycle in the second rule ( I bolded it). So any rule I write subsequently has to have that $c : cycle() check in order to fire now? Not just the first rule which identifies all in memory objects and calls update on them? That seems counterintuitive..it seems like if I simply call update() on each object in the first rule, that the second should fire withought checking the Cycle object as well. Chris rule "Identify MyObject" lock-on-active when $mo : MyDataObject(); $c : Cycle(); then System.err.println("MYDATAOBJECT in system: " + $mo.getID() + " | " + $mo.getTestFieldData(); update($sb); end rule "Identify Problem" lock-on-active when $mo : MyDataObject($td:testFieldData < 20); $c : Cycle(); then System.err.println("OUT OF SPEC MYDATAOBJECT: " + $mo.getID() + " | " + $mo.getTestFieldData() + " | " + $td); end _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Greg Barton Sent: Wednesday, September 23, 2009 11:01 AM To: Rules Users List Subject: Re: [rules-users] persistent java objects in working memory Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. _ From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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 To: Rules Users List 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,
Re: [rules-users] persistent java objects in working memory
Did you inform the engine that testFieldData had changed? You need to either call update(MyDataObject) from the action of a rule, or if you're outside the engine, update() or asyncUpdate() on the session. Otherwise, as far as the engine is concerned, the value hasn't changed. From: Chris Richmond To: Rules Users List Sent: Wednesday, September 23, 2009 3:35:46 PM Subject: Re: [rules-users] persistent java objects in working memory 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-boun...@lists.jboss.org [mailto:rules-users-boun...@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 To: Rules Users List 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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] persistent java objects in working memory
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-boun...@lists.jboss.org [mailto:rules-users-boun...@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 To: Rules Users List 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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] persistent java objects in working memory
Well my little test seems to confirm that this does indeed work, although I am not clear as to exactly why? Also, how do I prevent modifications made to a MyObject in another rule from making this one fire again? Can I do it by always having this one with the highest salience to ensure it runs first? Or would it be preferable to set a "dirty" flag on the object and make this rule make sure that hasn't been checked. That might not be an option an an object you can't mofidy for specific rule engine usage. Thanks, Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@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 To: Rules Users List 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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] persistent java objects in working memory
But in your example, wouldn't the rule still not fire since the when: $mo : MyDataObject(); $c : Cycle(); Would be satisfied as far as the $c : cycle() But the $mo : MyDataObject() : would still not be satisfied would it? I am writing up a test of this, but I am confused.why would $mo : MyDataObject() suddenly be satisfied just because $c : Cycle() is? Thanks, Chris _ From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@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 To: Rules Users List 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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
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 To: Rules Users List 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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[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 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users