Adjust the whole framework to event handler dependency inversion

This commit is contained in:
Kristóf Tóth
2019-07-12 23:25:16 +02:00
parent 42beafcf04
commit de78f48930
26 changed files with 169 additions and 254 deletions

3
lib/tfw/main/__init__.py Normal file
View File

@ -0,0 +1,3 @@
from .tfw_connector import TFWUplinkConnector, TFWConnector
from .event_handler_factory import EventHandlerFactory
from .signal_handling import setup_signal_handlers

View File

@ -0,0 +1,8 @@
from tfw.event_handlers import EventHandlerFactoryBase
from .tfw_connector import TFWConnector
class EventHandlerFactory(EventHandlerFactoryBase):
def _build_server_connector(self):
return TFWConnector()

View File

@ -0,0 +1,11 @@
from signal import signal, SIGTERM, SIGINT
from tfw.event_handlers import EventHandler
def setup_signal_handlers():
def stop(*_):
EventHandler.stop_all_instances()
exit(0)
signal(SIGTERM, stop)
signal(SIGINT, stop)

View File

@ -0,0 +1,25 @@
from tfw.networking import ServerConnector, ServerUplinkConnector
from tfw.config import TFWENV
class ConnAddrMixin:
@property
def uplink_conn_addr(self):
return f'tcp://localhost:{TFWENV.PULL_PORT}'
@property
def downlink_conn_addr(self):
return f'tcp://localhost:{TFWENV.PUB_PORT}'
class TFWUplinkConnector(ServerUplinkConnector, ConnAddrMixin):
def __init__(self):
super().__init__(self.uplink_conn_addr)
class TFWConnector(ServerConnector, ConnAddrMixin):
def __init__(self):
super().__init__(
self.downlink_conn_addr,
self.uplink_conn_addr
)