From d98ce5865162f69f44588df6483b986514c6ecc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 14 Jul 2018 20:06:34 +0200 Subject: [PATCH] Add proper multikey support for EventHandlers with compatibility --- .../components/process_managing_event_handler.py | 1 - lib/tfw/event_handler_base.py | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 3ccf6b1..040995e 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -38,7 +38,6 @@ class ProcessManagingEventHandler(EventHandlerBase): """ def __init__(self, key, dirmonitor=None, log_tail=0): super().__init__(key) - self.key = key self.monitor = dirmonitor self.processmanager = ProcessManager() self.log_tail = log_tail diff --git a/lib/tfw/event_handler_base.py b/lib/tfw/event_handler_base.py index 511af7c..41f6105 100644 --- a/lib/tfw/event_handler_base.py +++ b/lib/tfw/event_handler_base.py @@ -20,10 +20,17 @@ class EventHandlerBase(ABC): """ def __init__(self, key): self.server_connector = ServerConnector() - self.key = key - self.subscribe(self.key) + self.keys = [key] + self.subscribe(*self.keys) self.server_connector.register_callback(self.event_handler_callback) + @property + def key(self): + """ + Returns the oldest key this EventHandler was subscribed to. + """ + return self.keys[0] + def event_handler_callback(self, message): """ Callback that is invoked when receiving a message. @@ -48,7 +55,7 @@ class EventHandlerBase(ABC): subscribed to 'fsm' will receive 'fsm_update' messages as well. """ - return self.key == message['key'] + return message['key'] in self.keys def dispatch_handling(self, message): """ @@ -80,6 +87,7 @@ class EventHandlerBase(ABC): """ for key in keys: self.server_connector.subscribe(key) + self.keys.append(key) def unsubscribe(self, *keys): """ @@ -89,6 +97,7 @@ class EventHandlerBase(ABC): """ for key in keys: self.server_connector.unsubscribe(key) + self.keys.remove(key) def cleanup(self): """