def startService(self):
"""
Register ourselves with the database and establish all outgoing
connections to other servers in the cluster.
"""
@inlineCallbacks
def startup(txn):
endpoint = TCP4ServerEndpoint(self.reactor, self.ampPort)
# If this fails, the failure mode is going to be ugly, just like
# all conflicted-port failures. But, at least it won't proceed.
self._listeningPort = yield endpoint.listen(self.peerFactory())
self.ampPort = self._listeningPort.getHost().port
yield Lock.exclusive(NodeInfo.table).on(txn)
nodes = yield self.activeNodes(txn)
selves = [node for node in nodes
if ((node.hostname == self.hostname) and
(node.port == self.ampPort))]
if selves:
self.thisProcess = selves[0]
nodes.remove(self.thisProcess)
yield self.thisProcess.update(pid=self.pid,
time=datetime.now())
else:
self.thisProcess = yield NodeInfo.create(
txn, hostname=self.hostname, port=self.ampPort,
pid=self.pid, time=datetime.now()
)
for node in nodes:
self._startConnectingTo(node)
self._startingUp = inTransaction(self.transactionFactory, startup)
@self._startingUp.addBoth
def done(result):
self._startingUp = None
super(PeerConnectionPool, self).startService()
self._lostWorkCheckLoop()
return result
评论列表
文章目录