2019-06-10 13:32:45 +00:00
|
|
|
import logging
|
|
|
|
|
2018-03-25 13:43:59 +00:00
|
|
|
from tornado.web import Application
|
|
|
|
|
2019-07-30 13:17:29 +00:00
|
|
|
from tfw.internals.networking import ZMQListener
|
2019-07-24 13:17:16 +00:00
|
|
|
from tfw.internals.server import ZMQWebSocketRouter
|
2019-06-04 11:58:03 +00:00
|
|
|
from tfw.config import TFWENV
|
2018-07-25 13:46:39 +00:00
|
|
|
|
2018-03-25 14:06:59 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
2018-02-11 11:32:30 +00:00
|
|
|
|
|
|
|
|
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
|
2018-06-29 20:03:19 +00:00
|
|
|
SUB socket.
|
2018-04-18 17:44:26 +00:00
|
|
|
"""
|
2018-06-29 20:03:19 +00:00
|
|
|
def __init__(self):
|
2019-07-30 13:17:29 +00:00
|
|
|
self._listener = ZMQListener(
|
2019-06-04 11:58:03 +00:00
|
|
|
downlink_bind_addr=f'tcp://*:{TFWENV.PULL_PORT}',
|
|
|
|
uplink_bind_addr=f'tcp://*:{TFWENV.PUB_PORT}'
|
|
|
|
)
|
2018-06-04 20:16:44 +00:00
|
|
|
self.application = Application([(
|
2019-06-04 11:58:03 +00:00
|
|
|
r'/ws', ZMQWebSocketRouter, {
|
2019-07-30 13:17:29 +00:00
|
|
|
'listener': self._listener,
|
2018-07-30 13:16:03 +00:00
|
|
|
}
|
|
|
|
)])
|
2018-04-10 11:00:56 +00:00
|
|
|
|
2019-06-04 11:58:03 +00:00
|
|
|
def listen(self):
|
|
|
|
self.application.listen(TFWENV.WEB_PORT)
|