Add proper multikey support for EventHandlers with compatibility

This commit is contained in:
Kristóf Tóth 2018-07-14 20:06:34 +02:00
parent cfa8fc5ab6
commit d98ce58651
2 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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):
"""