def setUpClass(cls): """ SetUp the whole class. """ cls._clients = {} cls._servers = {} cls._handlers = {} cls._RANGE = 4 for x in range(1, cls._RANGE): endpoint = "ipc:///tmp/%d.ipc" % x cls._clients[x] = DefaultChannel(endpoint) cls._servers[x] = DefaultChannel(endpoint) cls._clients[x].connect() cls._servers[x].bind() handler_table = {} for x in range(1, cls._RANGE): server = cls._servers[x] handler = Handler(x, server) cls._handlers[x] = handler handler_table[server.socket] = handler control_channel = DefaultChannel('ipc:///tmp/control.ipc') control_channel.bind() control_handler = SimpleControlHandler(control_channel, name='Control') my_dispatcher = Dispatcher(handler_table) my_dispatcher.control_handler = control_handler threading.Thread(target=my_dispatcher.dispatch_events).start()
def main(): """" Main execution code. """ setup_dirs(detours_context['detours']['dirs']) config.dictConfig(detours_context['logging']) logger = getLogger(__name__) # COnfiguring constructors for custom tags yaml.add_constructor(u'!control_handler', control_handler_constructor) yaml.add_constructor(u'!io_handler', io_handler_constructor) yaml.add_constructor(u'!channel', channel_constructor) dispatch_layer = detours_context['detours']['dispatch_layer'] with open(dispatch_layer, 'r') as f: handlers_conf = yaml.load(f) table = create_handlers(handlers_conf) reactor_dispatcher = Dispatcher(table) reactor_dispatcher.control_handler = handlers_conf['handlers']['control'] reactor_dispatcher.dispatch_events() logger.info('Detours service terminated.') get_Zcontext().term()