mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-15 06:07:17 +00:00
28 lines
696 B
Python
28 lines
696 B
Python
|
class EventHandler:
|
||
|
_instances = set()
|
||
|
|
||
|
def __init__(self, server_connector):
|
||
|
type(self)._instances.add(self)
|
||
|
self.server_connector = server_connector
|
||
|
|
||
|
def start(self):
|
||
|
self.server_connector.register_callback(self._event_callback)
|
||
|
|
||
|
def _event_callback(self, message):
|
||
|
self.handle_event(message, self.server_connector)
|
||
|
|
||
|
def handle_event(self, message, server_connector):
|
||
|
raise NotImplementedError()
|
||
|
|
||
|
@classmethod
|
||
|
def stop_all_instances(cls):
|
||
|
for instance in cls._instances:
|
||
|
instance.stop()
|
||
|
|
||
|
def stop(self):
|
||
|
self.server_connector.close()
|
||
|
self.cleanup()
|
||
|
|
||
|
def cleanup(self):
|
||
|
pass
|