<div dir="ltr"><div><div><div><div><div><div><div><div>Hi, <br><br>>> Is simultaneously sub-classing Viewable and Cacheable a good idea?<br></div>I am not sure it would work, at least not as you expect.<br></div>Viewable and Cacheable both implement a different version of jellyFor (which will decides how object is seen on the other side of the connection).<br>
If you sub-class both of them your resulting class will act either as a cacheable or as a viewable depending on how you sub-class them -- at least for the serialization part. <br><br></div>For your problem, It seems to me that you're trying to do 2 things:<br>
</div>1 - manage a server side object of stockroom(s) <br></div>2 - keep a copy of that object(s) synchronized in clients. <br><br></div>So may be (IMHO) you could have one viewable object acting like a stockroom-manager that clients will (remote)call to make changes on the server side stockroom-object, <br>
And a cacheable stockroom-object, that you will sync with client. <br><br>That said, note that, there is no magic in the sync process when using 
cacheable, you will have to propagate the change made to the cacheable 
object yourself, by implementing the observe_ methods.<br>And when you make any changes to the server copy you will have to call those observe_ methods on all clients, just as you said you would do in your example.<br><br>
Another option would be to stockroom object with copyable items and implement getter method in the stockroom-manager, so clients would be able to query only data that they need, when they need it, and then do not fire all the sync stuff each time your stockroom is updates.<br>
</div><div>Besides cacheable object are said to be used for big object that do not change frequently, which is not the case of your stockroom I guess.<br><br></div><div>Hope this help.<br></div><div>--<br></div><div>Nacim.<br>
</div><br></div><div><br></div><div><div><div><div><div><div><div><br><div><div><div><div><br></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2013/11/12 Daniel Sank <span dir="ltr"><<a href="mailto:sank.daniel@gmail.com" target="_blank">sank.daniel@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Suppose I want to make a networked stockroom program with perspective<br>
broker. We have a user side client object,<br>
<br>
class Client(pb.Referenceable):<br>
    def connect(self):<br>
        # host, port, factory, and credentials come from elsewhere<br>
        reactor.connectTCP(host, port, factory)<br>
        d = self.factory.login(credentials, self)<br>
        d.addCallback(self.connected)<br>
<br>
    def connected(self, perspective):<br>
        if perspective:<br>
            self.perspective = perspective<br>
<br>
and a "corresponding" server side User,<br>
<br>
class User(pb.Avatar):<br>
    def __init__(self, name, server, mind):<br>
        <a href="http://self.name" target="_blank">self.name</a> = name<br>
        self.server = server<br>
        self.client = mind #This is a remote reference to a Client<br>
<br>
    def logout(self):<br>
        ...logic...<br>
<br>
We have the IRealm implementer,<br>
<br>
@implementer(portal.IRealm)<br>
class Server(object):<br>
    """I manage games and produce Avatars"""<br>
    def __init__(self, loggingPath):<br>
        self.users = {}<br>
        self.stockrooms = set()<br>
<br>
    def requestAvatar(self, avatarId, mind, *interfaces):<br>
        assert pb.IPerspective in interfaces<br>
        user = self.users.setdefault(avatarId, User(avatarId, self, mind))<br>
        return pb.IPerspective, user, user.logout<br>
<br>
and finally we have the Stockroom<br>
<br>
class Stockroom(object):<br>
    ...logic...<br>
<br>
Now I'd like for my Clients to be able to remove/add items to the<br>
stockroom. Using only the code above I'd have to add perspective_*<br>
methods to the User. These methods would direct the Client's intent to<br>
the appropriate Stockroom. Changes made to the Stockroom would then<br>
have to be announced to any interested Clients by invoking the<br>
appropriate Users' mind property.<br>
<br>
This seems very awkward. I'd rather just have the Stockrooms be<br>
Viewable so that Clients can invoke methods on them directly. If the<br>
Stockroom were _also_ Cacheable then changes on a Stockroom would<br>
automatically propagate to the client process.<br>
<br>
Is simultaneously sub-classing Viewable and Cacheable a good idea?<br>
<br>
Am I thinking about this properly?<br>
<br>
Regards and thanks in advance,<br>
Daniel Sank<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Department of Physics<br>
Broida Hall<br>
University of California<br>
Santa Barbara, CA 93117<br>
<a href="tel:%28805%29893-3899" value="+18058933899">(805)893-3899</a><br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</font></span></blockquote></div><br></div>