mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:51:31 +00:00
Add proper multikey support for EventHandlers with compatibility
This commit is contained in:
parent
cfa8fc5ab6
commit
d98ce58651
@ -38,7 +38,6 @@ class ProcessManagingEventHandler(EventHandlerBase):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, key, dirmonitor=None, log_tail=0):
|
def __init__(self, key, dirmonitor=None, log_tail=0):
|
||||||
super().__init__(key)
|
super().__init__(key)
|
||||||
self.key = key
|
|
||||||
self.monitor = dirmonitor
|
self.monitor = dirmonitor
|
||||||
self.processmanager = ProcessManager()
|
self.processmanager = ProcessManager()
|
||||||
self.log_tail = log_tail
|
self.log_tail = log_tail
|
||||||
|
@ -20,10 +20,17 @@ class EventHandlerBase(ABC):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, key):
|
def __init__(self, key):
|
||||||
self.server_connector = ServerConnector()
|
self.server_connector = ServerConnector()
|
||||||
self.key = key
|
self.keys = [key]
|
||||||
self.subscribe(self.key)
|
self.subscribe(*self.keys)
|
||||||
self.server_connector.register_callback(self.event_handler_callback)
|
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):
|
def event_handler_callback(self, message):
|
||||||
"""
|
"""
|
||||||
Callback that is invoked when receiving a message.
|
Callback that is invoked when receiving a message.
|
||||||
@ -48,7 +55,7 @@ class EventHandlerBase(ABC):
|
|||||||
subscribed to 'fsm' will receive 'fsm_update'
|
subscribed to 'fsm' will receive 'fsm_update'
|
||||||
messages as well.
|
messages as well.
|
||||||
"""
|
"""
|
||||||
return self.key == message['key']
|
return message['key'] in self.keys
|
||||||
|
|
||||||
def dispatch_handling(self, message):
|
def dispatch_handling(self, message):
|
||||||
"""
|
"""
|
||||||
@ -80,6 +87,7 @@ class EventHandlerBase(ABC):
|
|||||||
"""
|
"""
|
||||||
for key in keys:
|
for key in keys:
|
||||||
self.server_connector.subscribe(key)
|
self.server_connector.subscribe(key)
|
||||||
|
self.keys.append(key)
|
||||||
|
|
||||||
def unsubscribe(self, *keys):
|
def unsubscribe(self, *keys):
|
||||||
"""
|
"""
|
||||||
@ -89,6 +97,7 @@ class EventHandlerBase(ABC):
|
|||||||
"""
|
"""
|
||||||
for key in keys:
|
for key in keys:
|
||||||
self.server_connector.unsubscribe(key)
|
self.server_connector.unsubscribe(key)
|
||||||
|
self.keys.remove(key)
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user