Exemple #1
0
    def __init__(self):
        signal.signal(signal.SIGINT, self.signal_handler)
        # signal.signal(signal.SIGQUIT, self.sigquit_handler)
        self.do_exit = False
        self.hbeat_id = 0
        self.hbeat = 0
        # self.do_restart = False

        self.xserver = xstream.Server()
        parse_command_line()

        self.web_app = ServerWebApplication()
        # Add handlers for default services here so they can be destroyed if
        # needed. Handlers installed in the web_app __init__ cannot be destroyed.
        recipes = self.get_recipes()
        for recipe in recipes:
            tornado_handler = construct.construct(recipe)

            self.web_app.add_handlers(
                r".*",  # match any host
                tornado_handler)
        self.web_server = self.web_app.listen(options.port)
        self.ws_app = tornado.web.Application([(r"/", WebSocketHandler)])
        self.ws_server = self.ws_app.listen(options.wsport)

        self.xspub = xstream.Publisher()
        self.xs2server = threading.Thread(target=ServerApp.xstream2server)
        self.xs2server.start()
        self.heartbeat_thread = threading.Thread(target=ServerApp.heartbeat,
                                                 args=(lambda: self.do_exit, ))
        self.heartbeat_thread.start()
Exemple #2
0
    def post(self, *args):
        """
        Parse JSON arguments in POST body. In Requests module, use json key to
        pass in arguments, not data (which may clobber JSON objects)
        """
        recipe = json.loads(self.request.body, object_hook=hinted_tuple_hook)

        tornado_handler = construct.construct(recipe)
        name = str(recipe['name'])
        url = str(recipe['url'])

        self.application.add_handlers(
            r".*",  # match any host
            tornado_handler)
        self.write("service %s constructed at /serve/%s" % (name, url))