Commit 9a169bf2 authored by Vincent Pelletier's avatar Vincent Pelletier

Factorise Dispatcher.retrieve access.

Rename Dispatcher.retrieve into Dispatcher.pop.
When a pop'ing a non-registered connection, don't return a None, but raise a KeyError (rule of repair).


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1028 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ab42ebf8
......@@ -40,8 +40,8 @@ class Dispatcher:
def register(self, msg_id, conn, kw=None):
self.message_table[msg_id] = conn, kw
def retrieve(self, msg_id):
return self.message_table.pop(msg_id, None)
def pop(self, msg_id):
return self.message_table.pop(msg_id)
def registered(self, msg_id):
return self.message_table.has_key(msg_id)
......
......@@ -167,37 +167,38 @@ class MasterBaseEventHandler(EventHandler):
class MasterRequestEventHandler(MasterBaseEventHandler):
""" This class handle all answer from primary master node"""
def __answerNeoCTL(self, msg_id, packet):
client_conn, kw = self.app.dispatcher.pop(msg_id)
# XXX: Notify method is not intended for this use. This must be
# fixed !
client_conn.notify(packet, kw['msg_id'])
def handleAnswerClusterState(self, conn, packet, state):
logging.info("handleAnswerClusterState for a conn")
self.app.cluster_state = state
client_conn, kw = self.app.dispatcher.retrieve(packet.getId())
client_conn.notify(protocol.answerClusterState(state), kw['msg_id'])
self.__answerNeoCTL(packet.getId(),
protocol.answerClusterState(state))
def handleAnswerNewNodes(self, conn, packet, uuid_list):
logging.info("handleAnswerNewNodes for a conn")
client_conn, kw = self.app.dispatcher.retrieve(packet.getId())
client_conn.notify(protocol.answerNewNodes(uuid_list), kw['msg_id'])
self.__answerNeoCTL(packet.getId(),
protocol.answerNewNodes(uuid_list))
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list):
logging.info("handleAnswerPartitionTable for a conn")
client_conn, kw = self.app.dispatcher.retrieve(packet.getId())
client_conn, kw = self.app.dispatcher.pop(packet.getId())
# sent client the partition table
self.app.sendPartitionTable(client_conn, **kw)
def handleAnswerNodeState(self, conn, packet, uuid, state):
client_conn, kw = self.app.dispatcher.retrieve(packet.getId())
p = protocol.answerNodeState(uuid, state)
client_conn.notify(p, kw['msg_id'])
self.__answerNeoCTL(packet.getId(),
protocol.answerNodeState(uuid, state))
def handleNoError(self, conn, packet, msg):
client_conn, kw = self.app.dispatcher.retrieve(packet.getId())
p = protocol.noError(msg)
client_conn.notify(p, kw['msg_id'])
self.__answerNeoCTL(packet.getId(), protocol.noError(msg))
def handleProtocolError(self, conn, packet, msg):
client_conn, kw = self.app.dispatcher.retrieve(packet.getId())
p = protocol.protocolError(msg)
client_conn.notify(p, kw['msg_id'])
self.__answerNeoCTL(packet.getId(), protocol.protocolError(msg))
class MasterMonitoringEventHandler(MasterBaseEventHandler):
......
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