Esempio n. 1
0
    def mk_server(self):
        self.io_loop = ioloop.IOLoop()
        server = make_server(addressbook.AddressBookService, Dispatcher(self.io_loop), io_loop=self.io_loop)

        self.server = server
        sock = self.server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind(("localhost", 0))
        sock.setblocking(0)
        self.port = sock.getsockname()[-1]
        self.server_thread = threading.Thread(target=self.listen)
        self.server_thread.setDaemon(True)
        self.server_thread.start()
Esempio n. 2
0
    def mk_server(self):
        server = make_server(addressbook.AddressBookService, Dispatcher(self.io_loop),
                             io_loop=self.io_loop)

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind(('localhost', 0))
        sock.setblocking(0)
        sock.listen(128)

        server.add_socket(sock)
        self.port = sock.getsockname()[-1]
        return server
Esempio n. 3
0
 def listen(self):
     self.server_sock.listen(128)
     if asyncio:
         # In Tornado 5.0+, the asyncio event loop will be used
         # automatically by default
         asyncio.set_event_loop(asyncio.new_event_loop())
     self.io_loop = ioloop.IOLoop.current()
     server = make_server(addressbook.AddressBookService,
                          Dispatcher(self.io_loop),
                          io_loop=self.io_loop)
     server.add_socket(self.server_sock)
     self.io_loop.start()
Esempio n. 4
0
    def mk_server(self):
        server = make_server(addressbook.AddressBookService,
                             Dispatcher(self.io_loop),
                             io_loop=self.io_loop)

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind(('localhost', 0))
        sock.setblocking(0)
        sock.listen(128)

        server.add_socket(sock)
        self.port = sock.getsockname()[-1]
        return server
Esempio n. 5
0
    def mk_server(self):
        self.io_loop = ioloop.IOLoop()
        server = make_server(addressbook.AddressBookService,
                             Dispatcher(self.io_loop), io_loop=self.io_loop)

        self.server = server
        sock = self.server_sock = socket.socket(socket.AF_INET,
                                                socket.SOCK_STREAM)
        sock.bind(('localhost', 0))
        sock.setblocking(0)
        self.port = sock.getsockname()[-1]
        self.server_thread = threading.Thread(target=self.listen)
        self.server_thread.setDaemon(True)
        self.server_thread.start()
Esempio n. 6
0
def serve_forever(_api, _port):
    try:
        dep = {}
        __import__(_api.module_name)
        server = make_server(okapi_thrift.InvokeService, Dispatcher(), transport_read_timeout=timedelta(seconds=10))
        server.bind(_port)
        server.start(1)
        print('deploy success')

        if api_id == 'okapi/storage/1':
            resp = InvokeService("okapi/services/1/%s/deploy/%s" % (api_id.replace("/", "."), CONTAINER), method='put',
                                 args={"port": str(_port)})
            print("invoke deploy %s" % resp)
        if api_id != 'okapi/services/1':
            _api_detail = []
            for rule in url_map.iter_rules():
                ms = rule.methods - set(["OPTIONS", "HEAD"])
                _api_detail.append({'rule': rule.rule, 'methods': list(ms), 'function': rule.endpoint})
            InvokeService("okapi/services/1/%s/api" % api_id.replace("/", "."), method='post', body=_api_detail)

            dep["status"] = "running"
            dep["debug"] = ""
            dep["message"] = ""
            InvokeService("okapi/services/1/%s/deploy" % api_id.replace('/', '.'), method='put', body=dep)

        ioloop.IOLoop.instance().start()

    except Exception as e:
        traceback.print_exc()
        dep["status"] = "exited"
        dep["message"] = str(e)
        dep["debug"] = traceback.format_exc()
        if api_id != 'okapi/services/1':
            print("deploy exited: %s" % dep)
            reps = InvokeService("okapi/services/1/%s/deploy" % api_id.replace('/', '.'), method='put', body=dep)
            print(resp)
Esempio n. 7
0
class PlayHandler(object):
    def __init__(self):
        self._count = 0
        self._st_time = time.time()

    def ping(self):
        self._count += 1
        if self._count % 10000 == 0:
            right_now = time.time()
            print self._count / (right_now - self._st_time)
            self._st_time = right_now
            self._count = 0

        #print "ping!"
        return 123


if __name__ == '__main__':
    #server = make_server(play_thrift.Play, PlayHandler(), '127.0.0.1', 9090)
    #server.serve()

    server = make_server(play_thrift.Play, PlayHandler())
    server.listen(9090)

    # client = ioloop.IOLoop.current().run_sync(
    #         lambda: make_client(play_thrift.Play, '127.0.0.1', 9090))
    # ioloop.IOLoop.current().run_sync(client.ping)

    ioloop.IOLoop.current().start()