Commit afbd38a2 authored by Vincent Pelletier's avatar Vincent Pelletier

Factorise master disconnection code.

Only close master_conn is it is set.
Add an assertion before closing to verify that if there is any master connection closed after primary master is set is the primary master connection itself.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@750 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 86fd4cc7
......@@ -61,6 +61,17 @@ class BaseHandler(EventHandler):
else:
queue.put((conn, packet))
class PrimaryBaseHandler(BaseHandler):
def _closePrimaryMasterConnection(self, conn):
"""
This method is not part of EvenHandler API.
"""
app = self.app
if app.master_conn is not None:
assert conn is app.master_conn
app.master_conn.close()
app.master_conn = None
app.primary_master_node = None
class PrimaryBootstrapHandler(BaseHandler):
""" Bootstrap handler used when looking for the primary master """
......@@ -198,16 +209,13 @@ class PrimaryBootstrapHandler(BaseHandler):
logging.info("handleAnswerNodeInformation")
class PrimaryNotificationsHandler(BaseHandler):
class PrimaryNotificationsHandler(PrimaryBaseHandler):
""" Handler that process the notifications from the primary master """
def connectionClosed(self, conn):
logging.critical("connection to primary master node closed")
# Close connection
app = self.app
app.master_conn.close()
app.master_conn = None
app.primary_master_node = None
self._closePrimaryMasterConnection(conn)
BaseHandler.connectionClosed(self, conn)
def timeoutExpired(self, conn):
......@@ -359,16 +367,13 @@ class PrimaryNotificationsHandler(BaseHandler):
class PrimaryAnswersHandler(BaseHandler):
class PrimaryAnswersHandler(PrimaryBaseHandler):
""" Handle that process expected packets from the primary master """
def connectionClosed(self, conn):
logging.critical("connection to primary master node closed")
# Close connection
app = self.app
app.master_conn.close()
app.master_conn = None
app.primary_master_node = None
self._closePrimaryMasterConnection(conn)
super(PrimaryAnswersHandler, self).connectionClosed(conn)
def timeoutExpired(self, conn):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment