baseimage-tutorial-framework/tfw/main/tfw_server.py

31 lines
928 B
Python
Raw Normal View History

2019-06-10 13:32:45 +00:00
import logging
from tornado.web import Application
from tfw.internals.networking import EventHandlerConnector
from tfw.internals.server import ZMQWebSocketRouter
from tfw.config import TFWENV
2018-07-25 13:46:39 +00:00
LOG = logging.getLogger(__name__)
2019-05-26 16:26:33 +00:00
class TFWServer:
2018-04-18 17:44:26 +00:00
"""
This class handles the proxying of messages between the frontend and event handers.
It proxies messages from the "/ws" route to all event handlers subscribed to a ZMQ
SUB socket.
2018-04-18 17:44:26 +00:00
"""
def __init__(self):
self._event_handler_connector = EventHandlerConnector(
downlink_bind_addr=f'tcp://*:{TFWENV.PULL_PORT}',
uplink_bind_addr=f'tcp://*:{TFWENV.PUB_PORT}'
)
self.application = Application([(
r'/ws', ZMQWebSocketRouter, {
'event_handler_connector': self._event_handler_connector,
}
)])
2018-04-10 11:00:56 +00:00
def listen(self):
self.application.listen(TFWENV.WEB_PORT)