[Twisted-Python] Is it possible to use ReconnectingClientFactory with pb.ClientFactory
Brian Warner
warner at lothar.com
Fri Sep 16 19:25:27 MDT 2005
Martin Möllenbeck <martin at moellenbecks.de> writes:
>
> Is it possible to use ReconnectingClientFactory with pb.ClientFactory?
Sure thing. I have a utility class that does this.. take a look at
ReconnectingPBClientFactory in the Buildbot (http://buildbot.sf.net) source
tree, current CVS version is:
http://cvs.sourceforge.net/viewcvs.py/buildbot/buildbot/buildbot/pbutil.py?rev=1.10&view=auto
The only catch is to realize that pb.ClientFactory's getRootObject() and
login() methods return a single-use Deferred, and if you're reconnecting all
the time, you need something that can be fired multiple times. So
ReconnectingPBClientFactory offers a gotRootObject()/gotPerspective() method,
which are invoked each time the connection is established. You have to
override one of these in your subclass. If you're using cred, you override
gotPerspective() (and also call startLogin() or getPerspective() to start the
process, for newcred and oldcred respectively). If you aren't using cred at
all, you just override gotRootObject().
If you grep around the rest of the buildbot you can find an example of how
this factory gets used. I think buildbot.slave.bot.BotFactory is useful: it
includes a keepalive timer that pings the other end and abandons the
connection (thus triggering a reconnect) if the ping is lost. I added this to
deal with some buildslaves that were behind NAT boxes which timed out their
connection table after 10 minutes of inactivity: the symptom was that both
ends thought the connection was still established, no FINs had been seen, but
no packets could get from one side to the other. Sending a ping every 9
minutes tended to keep the connection table entry alive, while dropping the
connection if the ping got lost helped trigger a reconnect when that
keepalive failed.
cheers,
-Brian
More information about the Twisted-Python
mailing list