It looks like you need to explicitly model the changes in slot values with a
separate template if you don't want to lose track of the changes.
(deftemplate change-event
"age changed for person"
(declare (ordered FALSE))
(slot person (type OJBECT))
(slot old-age (type INTEGER))
(slot new-age (type INTEGER))
(slot time-stamp (type INTEGER)))
The Java thread making changes would create these instances, possibly in the
same place that the "person" shadowed object is changed. Jess can process the
changes in the order that they were created.
(defrule process-change-event
"Process earliest age change to person"
?change-event <- (change-event (person ?person) (time-stamp ?time-stamp)
(old-age ?old-age) (new-age ?new-age))
(not (change-event
(time-stamp
?earlier-time-stamp:(< ?earlier-time-stamp ?time-stamp))))
=>
(printout t "Process person " ?person " changed from "
?old-age " to " ?new-age " at " ?time-stamp crlf)
(retract ?change-event))
Perhaps your changes are happening so quickly that Jess may not be able to keep
up.
Bob Kirby
At 11:17 AM 9/27/2007, Joshua Undesser wrote:
>All,
>
>I am curious if anyone has a solution to the following problem i am seeing....
>
>I have a java project and to keep it simple we'll say it only has one java
>class - 'Person', and that Person class only has one attribute 'age'.
>Within my program I am creating a jess shadow fact which maps to the java
>Person object. So if you change the java object, the jess shadow fact gets
>updated. All is fine until there are rapid changes in attribute values.
>For example....if one of my client applications changes a persons age from say
>10 to 11, then 11 to 12, and then 12 to 13, really fast, my rules which
>pattern match on the Person.age attribute only fire once. I think i've
>tracked this down to the rete.update(instance, slotName) method. I what I
>think is happening is that after the first change from 10 to 11, the
>rete.update(instance, slotName) is called, which then goes back to the java
>object to get the value and by that time, the value has already changed two
>more times to 13. So the rete.update() grabs 13 and my shadow fact is
>updated with age=13. This is fine if all you care about is the end value of
>something, but in this case, I am interested in all changes, so I want my rule
>to fire each time it changes.
>
>The other problem I am seeing with rapidly changing attributes is that say I
>change the age of a person from 10 to 11, and then change my mind and change
>it back from 11 to 10. If this is done really fast, by the time the
>rete.update(instance, slotName) is called and grabs the value from the java
>object, it sees that it is back to the original value of 10 so no rules fire
>in this case because the shadow fact was never updated because it thinks the
>original and new values are the same.
>Again, though, I want to be aware that these things changed.
>
>Anyone have ideas on how to handle rapid changes in events?
>
>Thanks in advance!
>
>Joshua