Implement EventHandler command mirroring (EH -> EH communication)

This commit is contained in:
Kristóf Tóth 2018-03-14 14:08:48 +01:00
parent 0361092f37
commit 69f03f7615

View File

@ -21,12 +21,23 @@ class ZMQWebSocketHandler(WebSocketHandler):
log.debug('WebSocket connection initiated') log.debug('WebSocket connection initiated')
self._event_handler_connector.register_callback(self.zmq_callback) self._event_handler_connector.register_callback(self.zmq_callback)
@staticmethod @classmethod
def zmq_callback(msg_parts): def zmq_callback(cls, msg_parts):
keyhandlers = {'mirror': cls.mirror}
key, data = deserialize_all(*msg_parts) key, data = deserialize_all(*msg_parts)
log.debug('Received on pull socket: {}'.format(data)) log.debug('Received on pull socket: {}'.format(data))
for instance in ZMQWebSocketHandler.instances: if key not in keyhandlers:
instance.write_message(data) for instance in cls.instances:
instance.write_message(data)
else:
try: keyhandlers[key](data['data'])
except KeyError: log.error('Invalid mirror message format! Ignoring.')
@classmethod
def mirror(cls, data):
key = data['key']
cls._event_handler_connector.send_message({'data': data}, key)
def on_message(self, message): def on_message(self, message):
log.debug('Received on WebSocket: {}'.format(message)) log.debug('Received on WebSocket: {}'.format(message))