[Twisted-Python] keeping client data in sync with Twisted, mirroring some Axiom Items on the client-side
Robert Gravina
robert at gravina.com
Tue Oct 24 03:32:16 EDT 2006
Divmod and Twisted lists,
I think I've asked something similar before on the Divmod list, but
I'd like to ask again for some advice about using Divmod Axiom (an
object-relational DB) in a multi-user Twisted GUI application I'm
writing. This has as much to do with Twisted as it does Axiom, so I
felt it best to send to both lists. I apologise for the noise.
The problem I'm having is mainly architectural. I have about 15 Axiom
Item classes that live on a server-side database, and these are
Twisted pb.Copyable, so the clients end up with a pb.RemoteCopy which
has all of the attributes from the server-side Item. I now have about
1000 lines of code for the pb.Copyable Axiom Items and 500 lines of
code for all these pb.RemoteCopy objects, but essentially all they
are classes with the same attribute names as the Axiom Items. Apart
from being a pain to maintain, it feels like this is really wasted
code. There's also a lot of code to notify other clients when data in
these objects changes.
Basically, my app is starting to feel really bloated, and I think I'm
going about this the wrong way. Someone mentioned earlier that what I
really want is Zope Enterprise Objects, and they are right. A
distributed database that's simple keep all clients in sync is
exactly what I want, but now that I've invested so much time and
energy into Twisted I'd hate to throw it all away and begin the long
arduous task of learning and switching to Zope.
My basic goals are this:
1) Have a database which several clients can share and modify. For
example, if this is a contacts database, and I update someone's phone
number, I want all the other clients to get the new number.
Perhaps this can be implemented using pb.Cacheables? I already do
something like this using one Cacheable which I send pb.Copyable
objects to it's client-side RemoteCache as they are modified, and it
updates a dict of objects indexed by storeID.... but my
implementation is far from elegant :)
2) I'd like clients to be able to possibly one day "work offline".
Say for example they don't have network access, they could, instead
of logging in to the server, use their local cache of contacts. add/
edit/delete then and then have these changes reflected when they next
logon. I assume this would probably take some effort to implement
regardless of whether I used Twisted or ZEO, but my main stumbling
block at the moment is that I can't send Axiom Items down the wire,
since they have a Store reference and storeID etc. What I would
really like to do is send Axiom Items to clients and have them create
an Axiom Item *with the same storeID and details* as the one they
received. Sort of like mirroring the data, but not necessarily the
whole DB, just the objects they require.
I'm starting to wonder now if I should replace Twisted with ZEO in my
application. The main reason I didn't go with ZEO in the beginning is
I couldn't find any examples of it being used for mutli-user GUI
database-apps, only for mirroring/scaling Zope instances, so figured
it wasn't designed with this in mind. I do like Twisted, and I'm very
happy with it as a framework, I'm just struggling with how to deal
with this problem.
Thanks again all,
Robert
More information about the Twisted-Python
mailing list