def set_factory(self):
        if settings.THRIFTSERVER_BUFFERED:
            self._tfactory = TTransport.TBufferedTransportFactory()
        if settings.THRIFTSERVER_ZLIB:
            self._tfactory = TZlibTransport.TZlibTransportFactory()
        if settings.THRIFTSERVER_FRAMED:
            self._tfactory = TTransport.TFramedTransportFactory()

        if settings.THRIFTSERVER_PROTOCOL == Protocol.BINARY:
            self._pfactory = TBinaryProtocol.TBinaryProtocolFactory()
        elif settings.THRIFTSERVER_PROTOCOL == Protocol.COMPACT:
            self._pfactory = TCompactProtocol.TCompactProtocolFactory()
        elif settings.THRIFTSERVER_PROTOCOL == Protocol.JSON:
            self._pfactory = TJSONProtocol.TJSONProtocolFactory()
        else:
            raise RuntimeError(
                "invalid configuration for THRIFTSERVER_PROTOCOL: {}".format(
                    settings.THRIFTSERVER_PROTOCOL))
Beispiel #2
0
 def __initialize(self):
     pfactory = ThriftServer.__protocol_type[self._protocol]()
     if self._server_type == 'http':
         self._server = THttpServer.THttpServer(\
         self._processor, (self._ip, self._port), pfactory)
         return
     transport = TSocket.TServerSocket(self._ip, self._port)
     if self._transport == 'zlib':
         transport = TZlibTransport.TZlibTransport(transport)
         tfactory = TZlibTransport.TZlibTransportFactory()
     else:
         tfactory = TTransport.TBufferedTransportFactory()
     if self._server_type == 'noblock':
         self._server = TNonblockingServer.TNonblockingServer(\
         self._processor, transport, inputProtocolFactory=pfactory)
     else:
         self._server_type = ThriftServer.__server_type.get(self._server_type, 'TSimpleServer')
         ServerClass = getattr(TServer, self._server_type)
         self._server = ServerClass(self._processor, transport, tfactory, pfactory)
Beispiel #3
0
                                            certfile=abs_key_path)
else:
    transport = TSocket.TServerSocket(host, options.port)
tfactory = TTransport.TBufferedTransportFactory()
if options.trans == 'buffered':
    tfactory = TTransport.TBufferedTransportFactory()
elif options.trans == 'framed':
    tfactory = TTransport.TFramedTransportFactory()
elif options.trans == '':
    raise AssertionError('Unknown --transport option: %s' % options.trans)
else:
    tfactory = TTransport.TBufferedTransportFactory()
# if --zlib, then wrap server transport, and use a different transport factory
if options.zlib:
    transport = TZlibTransport.TZlibTransport(transport)  # wrap  with zlib
    tfactory = TZlibTransport.TZlibTransportFactory()

# do server-specific setup here:
if server_type == "TNonblockingServer":
    server = TNonblockingServer.TNonblockingServer(
        processor, transport, inputProtocolFactory=pfactory)
elif server_type == "TProcessPoolServer":
    import signal
    from thrift.server import TProcessPoolServer
    server = TProcessPoolServer.TProcessPoolServer(processor, transport,
                                                   tfactory, pfactory)
    server.setNumWorkers(5)

    def set_alarm():
        def clean_shutdown(signum, frame):
            for worker in server.workers: