Commit 14eafdd4 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Clarify use of _nodeLost/_dropIt methods by:

- Renaming _nodeLost to _handleConnectionLost and removing the node parameter
whose the computation was done before each call to it.
- Renaming _dropIt to handleNodeLost, currently called only from the base
service handler, so the abstract definition as moved into it. In this case, a
call ensure that the node is not None.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1090 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a2a4aa35
...@@ -23,27 +23,20 @@ from neo.handler import EventHandler ...@@ -23,27 +23,20 @@ from neo.handler import EventHandler
class MasterHandler(EventHandler): class MasterHandler(EventHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
def _nodeLost(self, conn, node): # XXX: this may be defined/done in the generic handler
def _handleConnectionLost(self, conn, node, new_state):
# override this method in sub-handlers to do specific actions when a # override this method in sub-handlers to do specific actions when a
# node is lost # node is lost
pass pass
def _dropIt(self, conn, node, new_state):
# This method provides a hook point overridable by service classes.
# It is triggered when a connection to a node gets lost.
pass
def connectionClosed(self, conn): def connectionClosed(self, conn):
node = self.app.nm.getNodeByUUID(conn.getUUID()) self._handleConnectionLost(conn, protocol.TEMPORARILY_DOWN_STATE)
self._dropIt(conn, node, protocol.TEMPORARILY_DOWN_STATE)
def timeoutExpired(self, conn): def timeoutExpired(self, conn):
node = self.app.nm.getNodeByUUID(conn.getUUID()) self._handleConnectionLost(conn, protocol.TEMPORARILY_DOWN_STATE)
self._dropIt(conn, node, protocol.TEMPORARILY_DOWN_STATE)
def peerBroken(self, conn): def peerBroken(self, conn):
node = self.app.nm.getNodeByUUID(conn.getUUID()) self._handleConnectionLost(conn, protocol.BROKEN_STATE)
self._dropIt(conn, node, protocol.BROKEN_STATE)
def handleProtocolError(self, conn, packet, message): def handleProtocolError(self, conn, packet, message):
logging.error('Protocol error %s %s' % (message, conn.getAddress())) logging.error('Protocol error %s %s' % (message, conn.getAddress()))
...@@ -93,7 +86,13 @@ class MasterHandler(EventHandler): ...@@ -93,7 +86,13 @@ class MasterHandler(EventHandler):
class BaseServiceHandler(MasterHandler): class BaseServiceHandler(MasterHandler):
"""This class deals with events for a service phase.""" """This class deals with events for a service phase."""
def _dropIt(self, conn, node, new_state): def handleNodeLost(self, conn, node):
# This method provides a hook point overridable by service classes.
# It is triggered when a connection to a node gets lost.
pass
def _handleConnectionLost(self, conn, new_state):
node = self.app.nm.getNodeByUUID(conn.getUUID())
if node is None or node.getState() == new_state: if node is None or node.getState() == new_state:
return return
if new_state != protocol.BROKEN_STATE and node.getState() == protocol.PENDING_STATE: if new_state != protocol.BROKEN_STATE and node.getState() == protocol.PENDING_STATE:
...@@ -102,9 +101,9 @@ class BaseServiceHandler(MasterHandler): ...@@ -102,9 +101,9 @@ class BaseServiceHandler(MasterHandler):
logging.info('drop a pending node from the node manager') logging.info('drop a pending node from the node manager')
self.app.nm.remove(node) self.app.nm.remove(node)
node.setState(new_state) node.setState(new_state)
# clean node related data in specialized handlers
self.app.broadcastNodeInformation(node) self.app.broadcastNodeInformation(node)
self._nodeLost(conn, node) # clean node related data in specialized handlers
self.handleNodeLost(conn, node)
def handleAskLastIDs(self, conn, packet): def handleAskLastIDs(self, conn, packet):
app = self.app app = self.app
......
...@@ -26,7 +26,7 @@ from neo.util import dump ...@@ -26,7 +26,7 @@ from neo.util import dump
class AdministrationHandler(MasterHandler): class AdministrationHandler(MasterHandler):
"""This class deals with messages from the admin node only""" """This class deals with messages from the admin node only"""
def _nodeLost(self, conn, node): def handleNodeLost(self, conn, node):
self.app.nm.remove(node) self.app.nm.remove(node)
def handleAskPrimaryMaster(self, conn, packet): def handleAskPrimaryMaster(self, conn, packet):
......
...@@ -68,7 +68,7 @@ class ClientServiceHandler(BaseServiceHandler): ...@@ -68,7 +68,7 @@ class ClientServiceHandler(BaseServiceHandler):
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
pass pass
def _nodeLost(self, conn, node): def handleNodeLost(self, conn, node):
app = self.app app = self.app
for tid, t in app.finishing_transaction_dict.items(): for tid, t in app.finishing_transaction_dict.items():
if t.getConnection() is conn: if t.getConnection() is conn:
......
...@@ -23,7 +23,7 @@ from neo.master.handlers import MasterHandler ...@@ -23,7 +23,7 @@ from neo.master.handlers import MasterHandler
class IdentificationHandler(MasterHandler): class IdentificationHandler(MasterHandler):
"""This class deals with messages from the admin node only""" """This class deals with messages from the admin node only"""
def _nodeLost(self, conn, node): def handleNodeLost(self, conn, node):
logging.warning('lost a node in IdentificationHandler : %s' % node) logging.warning('lost a node in IdentificationHandler : %s' % node)
def handleRequestNodeIdentification(self, conn, packet, node_type, def handleRequestNodeIdentification(self, conn, packet, node_type,
......
...@@ -43,7 +43,7 @@ class SecondaryMasterHandler(MasterHandler): ...@@ -43,7 +43,7 @@ class SecondaryMasterHandler(MasterHandler):
class PrimaryMasterHandler(MasterHandler): class PrimaryMasterHandler(MasterHandler):
""" Handler used by secondaries to handle primary master""" """ Handler used by secondaries to handle primary master"""
def _nodeLost(self, conn, node): def handleNodeLost(self, conn, node):
# XXX: why in down state ? # XXX: why in down state ?
self.app.primary_master_node.setState(DOWN_STATE) self.app.primary_master_node.setState(DOWN_STATE)
raise PrimaryFailure, 'primary master is dead' raise PrimaryFailure, 'primary master is dead'
......
...@@ -34,7 +34,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -34,7 +34,7 @@ class StorageServiceHandler(BaseServiceHandler):
if node.getState() == protocol.RUNNING_STATE: if node.getState() == protocol.RUNNING_STATE:
conn.notify(protocol.startOperation()) conn.notify(protocol.startOperation())
def _nodeLost(self, conn, node): def handleNodeLost(self, conn, node):
logging.info('storage node lost') logging.info('storage node lost')
if not self.app.pt.operational(): if not self.app.pt.operational():
raise OperationFailure, 'cannot continue operation' raise OperationFailure, 'cannot continue operation'
......
...@@ -27,7 +27,7 @@ class VerificationHandler(MasterHandler): ...@@ -27,7 +27,7 @@ class VerificationHandler(MasterHandler):
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
pass pass
def _nodeLost(self, conn, node): def handleNodeLost(self, conn, node):
if not self.app.pt.operational(): if not self.app.pt.operational():
raise VerificationFailure, 'cannot continue verification' raise VerificationFailure, 'cannot continue verification'
......
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