Hi Josh,
When you think about this, remember that PropertyChangeEvents are
processed synchronously -- i.e., Jess is all through updating the
shadow fact by the time your "firePropertyChange()" call returns.
There's no "event thread" or anything. It can get confusing thinking
about the sequence of events, I know. Note that you can therefore
only get this out-of-sequence problem if changes are happening on
multiple unsynchronized threads. Remember that this is a possible
problem right there. If two threads can be inside setX() at once, the
sequence of events is at best undefined; nothing Jess does can make
up for that.
But in any case, Jess will only query the object for the property
value if the value isn't available in the change event. If you put
the new value into the change event you send (i.e., no passing "null"
to firePropertyChange()) then Jess will use that value directly, and
this should mitigate the problem. Due to synchronization inside Jess,
this might actually fix the problem completely, but I haven't thought
it through completely and my office is noisy right now.
On Sep 27, 2007, at 2:17 PM, 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
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users
[EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify owner-jess-
[EMAIL PROTECTED]
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------