Ejemplo n.º 1
0
def make_server(host="localhost", port=9090, unix_socket=None,
                proto_factory=TBinaryProtocolFactory(),
                trans_factory=TBufferedTransportFactory(),
                client_timeout=3000, certfile=None):
    """Creates a Thrift RPC server and serves it with configuration"""
    processor = create_processor()

    if unix_socket:
        server_socket = TServerSocket(unix_socket=unix_socket)
        if certfile:
            warnings.warn("SSL only works with host:port, not unix_socket.")
    elif host and port:
        if certfile:
            server_socket = TSSLServerSocket(
                host=host, port=port, client_timeout=client_timeout,
                certfile=certfile)
        else:
            server_socket = TServerSocket(
                host=host, port=port, client_timeout=client_timeout)
    else:
        raise ValueError("Either host/port or unix_socket must be provided.")

    server = TThreadedServer(processor, server_socket,
                             iprot_factory=proto_factory,
                             itrans_factory=trans_factory)

    print('Starting Thrift RPC server running @ %s:%s' % (host, port))

    try:
        server.serve()
    except KeyboardInterrupt:
        print()
        print("Stopping Server from Keyboard Interruption")
        exit()
Ejemplo n.º 2
0
def main():
    dd_proc = TProcessor(dd_thrift.DingService, DingDispatcher())
    pp_proc = TProcessor(pp_thrift.PingService, PingDispatcher())

    mux_proc = TMultiplexedProcessor()
    mux_proc.register_processor(DD_SERVICE_NAME, dd_proc)
    mux_proc.register_processor(PP_SERVICE_NAME, pp_proc)

    server = TThreadedServer(mux_proc, TServerSocket(),
                             iprot_factory=TBinaryProtocolFactory(),
                             itrans_factory=TBufferedTransportFactory())
    server.serve()
Ejemplo n.º 3
0
def make_server(service,
                handler,
                host="localhost",
                port=9090,
                unix_socket=None,
                proto_factory=TBinaryProtocolFactory(),
                trans_factory=TBufferedTransportFactory(),
                client_timeout=3000,
                certfile=None):
    processor = TProcessor(service, handler)

    if unix_socket:
        server_socket = TServerSocket(unix_socket=unix_socket)
        if certfile:
            warnings.warn("SSL only works with host:port, not unix_socket.")
    elif host and port:
        if certfile:
            server_socket = TSSLServerSocket(host=host,
                                             port=port,
                                             client_timeout=client_timeout,
                                             certfile=certfile)
        else:
            server_socket = TServerSocket(host=host,
                                          port=port,
                                          client_timeout=client_timeout)
    else:
        raise ValueError("Either host/port or unix_socket must be provided.")

    server = TThreadedServer(processor,
                             server_socket,
                             iprot_factory=proto_factory,
                             itrans_factory=trans_factory)
    return server
Ejemplo n.º 4
0
def server(request):
    p1 = TProcessor(mux.ThingOneService, DispatcherOne())
    p2 = TProcessor(mux.ThingTwoService, DispatcherTwo())

    mux_proc = TMultiplexingProcessor()
    mux_proc.register_processor(p1)
    mux_proc.register_processor(p2)

    _server = TThreadedServer(mux_proc,
                              TServerSocket(unix_socket=sock_path),
                              iprot_factory=TBinaryProtocolFactory(),
                              itrans_factory=TBufferedTransportFactory())
    ps = multiprocessing.Process(target=_server.serve)
    ps.start()
    time.sleep(0.1)

    def fin():
        if ps.is_alive():
            ps.terminate()
        try:
            os.remove(sock_path)
        except IOError:
            pass

    request.addfinalizer(fin)
Ejemplo n.º 5
0
def make_server(service, handler, host, port,
                proto_factory=TBinaryProtocolFactory()):
    processor = TProcessor(service, handler)
    transport = TServerSocket(host=host, port=port)
    server = TThreadedServer(processor, transport,
                             iprot_factory=proto_factory)
    return server
Ejemplo n.º 6
0
def _make_server(app, host, port, daemon=True):
    processor = TProcessor(app.service, app)
    server_socket = TServerSocket(host=host, port=port)
    server = TThreadedServer(processor, server_socket,
                             iprot_factory=TBinaryProtocolFactory(),
                             itrans_factory=TBufferedTransportFactory(),
                             daemon=daemon)
    return server
Ejemplo n.º 7
0
def make_server(service, handler,
                host="localhost", port=9090, unix_socket=None,
                proto_factory=TBinaryProtocolFactory(),
                trans_factory=TBufferedTransportFactory()):
    processor = TProcessor(service, handler)
    if unix_socket:
        server_socket = TServerSocket(unix_socket=unix_socket)
    elif host and port:
        server_socket = TServerSocket(host=host, port=port)
    else:
        raise ValueError("Either host/port or unix_socket must be provided.")

    server = TThreadedServer(processor, server_socket,
                             iprot_factory=proto_factory,
                             itrans_factory=trans_factory)
    return server
Ejemplo n.º 8
0
def make_server(host="localhost",
                port=9090,
                unix_socket=None,
                proto_factory=TBinaryProtocolFactory(),
                trans_factory=TBufferedTransportFactory(),
                client_timeout=3000,
                certfile=None):
    """Creates a Thrift RPC server and serves it with configuration
    """
    _init_django()

    processor = get_rpc_application()

    if unix_socket:
        server_socket = TServerSocket(unix_socket=unix_socket)
        if certfile:
            logging.error("SSL only works with host:port, not unix_socket.")
    elif host and port:
        if certfile:
            server_socket = TSSLServerSocket(host=host,
                                             port=port,
                                             client_timeout=client_timeout,
                                             certfile=certfile)
        else:
            server_socket = TServerSocket(host=host,
                                          port=port,
                                          client_timeout=client_timeout)
    else:
        raise ValueError("Either host/port or unix_socket must be provided.")

    server = TThreadedServer(processor,
                             server_socket,
                             iprot_factory=proto_factory,
                             itrans_factory=trans_factory)

    try:
        return server
    except KeyboardInterrupt:
        print()
        print("Stopping Server from Keyboard Interruption")
        exit()
Ejemplo n.º 9
0
def make_server(service,
                handler,
                fd=None,
                host=None,
                port=None,
                unix_socket=None,
                address_family=socket.AF_INET,
                proto_factory=None,
                trans_factory=None,
                client_timeout=None,
                backlog=128):
    processor = TProcessor(service, handler)
    if unix_socket is not None:
        logger.info('Setting up server bound to %s', unix_socket)
        server_socket = TServerSocket(unix_socket=unix_socket,
                                      socket_family=address_family,
                                      client_timeout=client_timeout,
                                      backlog=backlog)
    elif fd is not None:
        logger.info('Setting up server bound to socket fd %s', fd)
        server_socket = TFDServerSocket(fd=fd,
                                        socket_family=address_family,
                                        client_timeout=client_timeout,
                                        backlog=backlog)
    elif host is not None and port is not None:
        logger.info('Setting up server bound to %s:%s', host, str(port))
        server_socket = TServerSocket(host=host,
                                      port=port,
                                      socket_family=address_family,
                                      client_timeout=client_timeout,
                                      backlog=backlog)
    else:
        raise ValueError('Insufficient params')

    server = TThreadedServer(processor,
                             server_socket,
                             iprot_factory=proto_factory,
                             itrans_factory=trans_factory)
    return server