3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
6 from twisted.spread import pb
7 from twisted.internet import reactor
10 rootobj_def = pb.getObjectAt("localhost", 8800, 30)
11 rootobj_def.addCallbacks(got_rootobj)
12 obj2_def = getSomeObjectAt("localhost", 8800, 30, "two")
13 obj2_def.addCallbacks(got_obj2)
14 obj3_def = getSomeObjectAt("localhost", 8800, 30, "three")
15 obj3_def.addCallbacks(got_obj3)
18 def got_rootobj(rootobj):
19 print "got root object:", rootobj
20 print "telling root object to do foo(A)"
21 rootobj.callRemote("foo", "A")
24 print "got second object:", obj2
25 print "telling second object to do foo(B)"
26 obj2.callRemote("foo", "B")
29 print "got third object:", obj3
30 print "telling third object to do foo(C)"
31 obj3.callRemote("foo", "C")
33 class my_ObjectRetrieval(pb._ObjectRetrieval):
34 def __init__(self, broker, d, objname):
35 pb._ObjectRetrieval.__init__(self, broker, d)
36 self.objname = objname
37 def connectionMade(self):
38 assert not self.term, "How did this get called?"
39 x = self.broker.remoteForName(self.objname)
42 self.deferred.callback(x)
44 def getSomeObjectAt(host, port, timeout=None, objname="root"):
45 from twisted.internet import defer
46 from twisted.spread.pb import Broker, BrokerClientFactory
49 bf = BrokerClientFactory(b)
50 my_ObjectRetrieval(b, d, objname)
52 # every time you use this, God kills a kitten
53 reactor.connectUNIX(port, bf, timeout)
55 reactor.connectTCP(host, port, bf, timeout)