[Zope] Catch Object Changes
Holger Schmidt
hs at keppler-it.de
Sun Nov 30 09:17:35 EST 2003
Hello,
am Freitag, 28. November 2003 um 22:44 schrieben Sie:
DM> Holger Schmidt wrote at 2003-11-28 01:47 +0100:
>> I have a list of objects.
>> The list can contain objects like Folders, PropertyObjects or just every
>> product that you have installed (but has to be accessible via the ZMI).
>>
>> My problem is that I want to do some XML-RPC to another Zope instance
>> whenever some object of my list has changed (the XML-RPC depends on
>> the object which has changed, that means that I also need to get the
>> (commited?) changed object at this time).
>>
>> My idea to solve this problem:
>> 1.) get to know when ANY object in Zope is changed
>> 2.) check if this object is in my list
>> 3.) if the list contains the object: start a thread managing the XML-RPC
>>
>> Problem is step 1 ... how can Zope tell me that ANY object is changed ...?
DM> Looks like you want a specialized transaction or ZODB connection.
DM> Whenever an object is changed, it registers with the transaction.
DM> When the transaction is about to commit, it informs
DM> the object's ZODB connection that the object was modified.
DM> Zope uses a two level commit protocol, thus one affected
DM> connection may vote against the commit.
DM> This means, the hook you are looking for is somewhere in
DM> transaction or two level commit handling.
do you mean a monkey-patch like this?
or is this bad for any reasons ...?
--------------------------------------------------------------------
--------------------------------------------------------------------
from ZODB import Connection
old_commit = Connection.Connection.commit
def new_commit(self, object, transaction):
print "catched ZODB-Modification (commit) ..."
old_commit(self, object, transaction)
Connection.Connection.commit = new_commit
old_commit_sub = Connection.Connection.commit_sub
def new_commit_sub(self, t):
print "catched ZODB-Modification (commit_sub) ..."
old_commit_sub(self, t)
Connection.Connection.commit_sub = new_commit_sub
--------------------------------------------------------------------
--------------------------------------------------------------------
I patched the commit and the commit_sub because I think these methods
are called after 2PC has succeded, has it?
--
Thanks,
Holger
More information about the Zope
mailing list