Remove ZMQConnectorBase

This commit is contained in:
Kristóf Tóth 2019-05-27 20:02:09 +02:00
parent 82df8a8065
commit e44a99fa6d
3 changed files with 20 additions and 27 deletions

View File

@ -8,15 +8,13 @@ from tfw.config import TFWENV
from tfw.config.logs import logging
from .serialization import serialize_tfw_msg, with_deserialize_tfw_msg
from .zmq_connector_base import ZMQConnectorBase
LOG = logging.getLogger(__name__)
class EventHandlerDownlinkConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super(EventHandlerDownlinkConnector, self).__init__(zmq_context)
self._zmq_pull_socket = self._zmq_context.socket(zmq.PULL)
class EventHandlerDownlinkConnector():
def __init__(self):
self._zmq_pull_socket = zmq.Context.instance().socket(zmq.PULL)
self._zmq_pull_socket.setsockopt(zmq.RCVHWM, 0)
self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket)
address = f'tcp://*:{TFWENV.RECEIVER_PORT}'
@ -31,10 +29,9 @@ class EventHandlerDownlinkConnector(ZMQConnectorBase):
self._zmq_pull_stream.close()
class EventHandlerUplinkConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super(EventHandlerUplinkConnector, self).__init__(zmq_context)
self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB)
class EventHandlerUplinkConnector():
def __init__(self):
self._zmq_pub_socket = zmq.Context.instance().socket(zmq.PUB)
self._zmq_pub_socket.setsockopt(zmq.SNDHWM, 0)
address = f'tcp://*:{TFWENV.PUBLISHER_PORT}'
self._zmq_pub_socket.bind(address)
@ -48,6 +45,10 @@ class EventHandlerUplinkConnector(ZMQConnectorBase):
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
def __init__(self):
EventHandlerDownlinkConnector.__init__(self)
EventHandlerUplinkConnector.__init__(self)
def close(self):
EventHandlerDownlinkConnector.close(self)
EventHandlerUplinkConnector.close(self)

View File

@ -11,15 +11,13 @@ from tfw.config.logs import logging
from .scope import Scope
from .serialization import serialize_tfw_msg, with_deserialize_tfw_msg
from .zmq_connector_base import ZMQConnectorBase
LOG = logging.getLogger(__name__)
class ServerDownlinkConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super(ServerDownlinkConnector, self).__init__(zmq_context)
self._zmq_sub_socket = self._zmq_context.socket(zmq.SUB)
class ServerDownlinkConnector():
def __init__(self):
self._zmq_sub_socket = zmq.Context.instance().socket(zmq.SUB)
self._zmq_sub_socket.connect(f'tcp://localhost:{TFWENV.PUBLISHER_PORT}')
self._zmq_sub_socket.setsockopt(zmq.RCVHWM, 0)
self._zmq_sub_stream = ZMQStream(self._zmq_sub_socket)
@ -35,10 +33,9 @@ class ServerDownlinkConnector(ZMQConnectorBase):
self._zmq_sub_stream.close()
class ServerUplinkConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super(ServerUplinkConnector, self).__init__(zmq_context)
self._zmq_push_socket = self._zmq_context.socket(zmq.PUSH)
class ServerUplinkConnector():
def __init__(self):
self._zmq_push_socket = zmq.Context.instance().socket(zmq.PUSH)
self._zmq_push_socket.connect(f'tcp://localhost:{TFWENV.RECEIVER_PORT}')
self._zmq_push_socket.setsockopt(zmq.SNDHWM, 0)
@ -51,6 +48,10 @@ class ServerUplinkConnector(ZMQConnectorBase):
class ServerConnector(ServerUplinkConnector, ServerDownlinkConnector):
def __init__(self):
ServerUplinkConnector.__init__(self)
ServerDownlinkConnector.__init__(self)
def close(self):
ServerUplinkConnector.close(self)
ServerDownlinkConnector.close(self)

View File

@ -1,9 +0,0 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
import zmq
class ZMQConnectorBase:
def __init__(self, zmq_context=None):
self._zmq_context = zmq_context or zmq.Context.instance()