Refactor ZMQWSProxy filter and callback initialization

This commit is contained in:
Kristóf Tóth 2018-07-30 15:16:03 +02:00
parent 3bc30ab503
commit b6d72812c4
2 changed files with 20 additions and 16 deletions

View File

@ -32,13 +32,16 @@ class TFWServer(FSMAware):
self.application = Application([( self.application = Application([(
r'/ws', ZMQWebSocketProxy, { r'/ws', ZMQWebSocketProxy, {
'event_handler_connector': self._event_handler_connector, 'event_handler_connector': self._event_handler_connector,
'message_handlers': [ 'proxy_filters_and_callbacks': {
self.handle_trigger, 'message_handlers': [
self.handle_recover, self.handle_trigger,
self.handle_fsm_update self.handle_recover,
], self.handle_fsm_update
'frontend_message_handlers': [self.save_frontend_messages] ],
})]) 'frontend_message_handlers': [self.save_frontend_messages]
}
}
)])
self._frontend_messages = FrontendMessageStorage() self._frontend_messages = FrontendMessageStorage()

View File

@ -18,11 +18,7 @@ class ZMQWebSocketProxy(WebSocketHandler):
def initialize(self, **kwargs): # pylint: disable=arguments-differ def initialize(self, **kwargs): # pylint: disable=arguments-differ
self._event_handler_connector = kwargs['event_handler_connector'] self._event_handler_connector = kwargs['event_handler_connector']
self._proxy_filters_and_callbacks = kwargs.get('proxy_filters_and_callbacks', {})
self._message_handlers = kwargs.get('message_handlers', [])
self._frontend_message_handlers = kwargs.get('frontend_message_handlers', [])
self._eventhandler_message_handlers = kwargs.get('eventhandler_message_handlers', [])
self._proxy_filters = kwargs.get('proxy_filters', [])
self.proxy_eventhandler_to_websocket = TFWProxy( self.proxy_eventhandler_to_websocket = TFWProxy(
self.send_eventhandler_message, self.send_eventhandler_message,
@ -36,14 +32,19 @@ class ZMQWebSocketProxy(WebSocketHandler):
self.subscribe_proxy_callbacks() self.subscribe_proxy_callbacks()
def subscribe_proxy_callbacks(self): def subscribe_proxy_callbacks(self):
eventhandler_message_handlers = self._proxy_filters_and_callbacks.get('eventhandler_message_handlers', [])
frontend_message_handlers = self._proxy_filters_and_callbacks.get('frontend_message_handlers', [])
message_handlers = self._proxy_filters_and_callbacks.get('message_handlers', [])
proxy_filters = self._proxy_filters_and_callbacks.get('proxy_filters', [])
self.proxy_websocket_to_eventhandler.subscribe_proxy_callbacks_and_filters( self.proxy_websocket_to_eventhandler.subscribe_proxy_callbacks_and_filters(
self._eventhandler_message_handlers + self._message_handlers, eventhandler_message_handlers + message_handlers,
self._proxy_filters proxy_filters
) )
self.proxy_eventhandler_to_websocket.subscribe_proxy_callbacks_and_filters( self.proxy_eventhandler_to_websocket.subscribe_proxy_callbacks_and_filters(
self._frontend_message_handlers + self._message_handlers, frontend_message_handlers + message_handlers,
self._proxy_filters proxy_filters
) )
def prepare(self): def prepare(self):