Use fresh messaging instances for each event handler

This commit is contained in:
Bálint Bokros 2018-01-25 15:24:42 +01:00
parent 6246baa675
commit 8244e22479
5 changed files with 15 additions and 13 deletions

View File

@ -1,9 +1,11 @@
import json import json
from messaging import Messaging
class EventHandlerBase: class EventHandlerBase:
def __init__(self, messaging, anchor): def __init__(self, anchor):
self.messaging = messaging self.messaging = Messaging()
self.anchor = anchor self.anchor = anchor
self.messaging.subscribe(self.anchor) self.messaging.subscribe(self.anchor)
self.subscriptions = {self.anchor} self.subscriptions = {self.anchor}

View File

@ -85,10 +85,10 @@ class LoginHandler(EventHandlerBase):
if __name__ == '__main__': if __name__ == '__main__':
messaging = Messaging() messaging = Messaging()
anchor_a = ChangeCaseHandler(messaging, 'anchor_a') anchor_a = ChangeCaseHandler('anchor_a')
anchor_b = Rot13Handler(messaging, 'anchor_b') anchor_b = Rot13Handler('anchor_b')
anchor_c = ReverseHandler(messaging, 'anchor_c') anchor_c = ReverseHandler('anchor_c')
anchor_webide = SourceCodeEventHandler(messaging, 'anchor_webide', 'login_component.py', 'login') anchor_webide = SourceCodeEventHandler('anchor_webide', 'login_component.py', 'login')
anchor_terminado = TerminadoEventHandler(messaging, 'anchor_terminado', 'terminado') anchor_terminado = TerminadoEventHandler('anchor_terminado', 'terminado')
IOLoop.instance().start() IOLoop.instance().start()

View File

@ -9,8 +9,8 @@ from event_handler_base import EventHandlerBase
class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
def __init__(self, messaging, anchor, filename, process_name=None): def __init__(self, anchor, filename, process_name=None):
super().__init__(messaging, anchor) super().__init__(anchor)
self.working_directory = LOGIN_APP_DIR self.working_directory = LOGIN_APP_DIR
self.filename = filename self.filename = filename
self.language = map_file_extension_to_language(filename) self.language = map_file_extension_to_language(filename)

View File

@ -4,8 +4,8 @@ from event_handler_base import EventHandlerBase
class StatefulEventHandler(EventHandlerBase): class StatefulEventHandler(EventHandlerBase):
def __init__(self, messaging, anchor, event_handler_function): def __init__(self, anchor, event_handler_function):
super().__init__(messaging, anchor) super().__init__(anchor)
self.event_handler_function = event_handler_function self.event_handler_function = event_handler_function
self.generator = None self.generator = None
self.subscribe('reset') self.subscribe('reset')

View File

@ -9,8 +9,8 @@ from config import TERMINADO_DIR
class TerminadoEventHandler(EventHandlerBase, SupervisorMixin): class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
def __init__(self, messaging, anchor, process_name): def __init__(self, anchor, process_name):
super().__init__(messaging, anchor) super().__init__(anchor)
self.working_directory = TERMINADO_DIR self.working_directory = TERMINADO_DIR
self.process_name = process_name self.process_name = process_name
self.setup_terminado_server() self.setup_terminado_server()