From 80ada91cec133a30e31e73e40384302573a8dcdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 26 Jan 2018 15:16:34 +0100 Subject: [PATCH] Rename Messaging to ServerConnector --- src/event_handlers/event_handler_base.py | 16 ++++++++-------- src/event_handlers/event_handler_main.py | 2 +- .../{messaging.py => server_connector.py} | 4 ++-- src/event_handlers/stateful_event_handler.py | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) rename src/event_handlers/{messaging.py => server_connector.py} (97%) diff --git a/src/event_handlers/event_handler_base.py b/src/event_handlers/event_handler_base.py index 63e7919..8d949b3 100644 --- a/src/event_handlers/event_handler_base.py +++ b/src/event_handlers/event_handler_base.py @@ -1,16 +1,16 @@ import json -from messaging import Messaging +from server_connector import ServerConnector class EventHandlerBase: def __init__(self, anchor): - self.messaging = Messaging() + self.server_connector = ServerConnector() self.anchor = anchor self.subscriptions = set() self.subscribe(self.anchor) self.subscribe('reset') - self.messaging.register_callback(self.event_handler_callback) + self.server_connector.register_callback(self.event_handler_callback) def event_handler_callback(self, msg_parts): anchor, message = msg_parts @@ -18,7 +18,7 @@ class EventHandlerBase: response = self.handle_event(anchor, data_json) if anchor != b'reset' else self.handle_reset(data_json) if response is None: return encoded_response = json.dumps(response).encode('utf-8') - self.messaging.send(anchor, encoded_response) + self.server_connector.send(anchor, encoded_response) def handle_event(self, anchor, data_json): raise NotImplementedError @@ -33,21 +33,21 @@ class EventHandlerBase: 'data': data } encoded_message = json.dumps(message).encode('utf-8') - self.messaging.send(encoded_anchor, encoded_message) + self.server_connector.send(encoded_anchor, encoded_message) def subscribe(self, anchor): if anchor not in self.subscriptions: self.subscriptions.add(anchor) - self.messaging.subscribe(anchor) + self.server_connector.subscribe(anchor) def unsubscribe(self, anchor): try: self.subscriptions.remove(anchor) - self.messaging.unsubscribe(anchor) + self.server_connector.unsubscribe(anchor) except KeyError: pass def unsubscribe_all(self): for sub in self.subscriptions: - self.messaging.unsubscribe(anchor=sub) + self.server_connector.unsubscribe(anchor=sub) self.subscriptions.clear() diff --git a/src/event_handlers/event_handler_main.py b/src/event_handlers/event_handler_main.py index 1583cf3..036b00e 100644 --- a/src/event_handlers/event_handler_main.py +++ b/src/event_handlers/event_handler_main.py @@ -4,7 +4,7 @@ from functools import partial import source_code from event_handler_base import EventHandlerBase -from messaging import Messaging +from server_connector import ServerConnector from source_code_event_handler import SourceCodeEventHandler from terminado_event_handler import TerminadoEventHandler from tornado.ioloop import IOLoop diff --git a/src/event_handlers/messaging.py b/src/event_handlers/server_connector.py similarity index 97% rename from src/event_handlers/messaging.py rename to src/event_handlers/server_connector.py index fd21c92..ca7e77e 100644 --- a/src/event_handlers/messaging.py +++ b/src/event_handlers/server_connector.py @@ -9,7 +9,7 @@ from config import PUBLISHER_PORT, RECEIVER_PORT ioloop.install() -class Messaging: +class ServerConnector: def __init__(self): self._zmq_context = zmq.Context.instance() self._zmq_sub_socket = self._zmq_context.socket(zmq.SUB) @@ -21,6 +21,6 @@ class Messaging: self.subscribe = partial(self._zmq_sub_socket.setsockopt_string, zmq.SUBSCRIBE) self.unsubscribe = partial(self._zmq_sub_socket.setsockopt_string, zmq.UNSUBSCRIBE) self.register_callback = self._zmq_sub_stream.on_recv - + def send(self, anchor, response): self._zmq_push_socket.send_multipart([anchor, response]) diff --git a/src/event_handlers/stateful_event_handler.py b/src/event_handlers/stateful_event_handler.py index d7bee13..a9d2e34 100644 --- a/src/event_handlers/stateful_event_handler.py +++ b/src/event_handlers/stateful_event_handler.py @@ -29,9 +29,9 @@ class StatefulEventHandler(EventHandlerBase): 'data': response_data, }) response = [r.encode('utf-8') for r in (response_anchor, response_data)] - self.messaging.send(*response) + self.server_connector.send(*response) - self.messaging.register_callback(event_handler_callback) + self.server_connector.register_callback(event_handler_callback) def unsubscribe_all(self): super().unsubscribe_all()