示例#1
0
    def handle_request(self, action, input, output):
        print('generic handler %s' % action)
        ip, port = self.__resolve_config(action)
        transport = TSocket.TSocket(ip, port)  # Make socket
        try:
            transport = TTransport.TBufferedTransport(
                transport)  # Buffering is critical. Raw sockets are very slow
            protocol = TBinaryProtocol.TBinaryProtocol(
                transport)  # Wrap in a protocol
            client = GenericPiThriftService.Client(
                protocol)  # Create a client to use the protocol encoder
            transport.open()  # Connect!
            output[action] = client.handleRequest(input=input)
            transport.close()

        except Thrift.TException as tx:
            print('%s' % (tx.message))
            raise ThriftServiceException(serviceName='generic',
                                         message=tx.message)
        except ThriftServiceException as tex:
            print('thrift exception request %s' % tex)
            raise tex
        except ExternalEndpointUnavailable as endEx:
            print('endpoint exception request %s' % endEx)
            raise endEx
        except Exception as ex:
            print('whot generic thrift??? %s' % ex)
            raise ex
        finally:
            transport.close()
示例#2
0
def create_server():
    handler = LightPiThriftHandler()
    return TServer.TSimpleServer(GenericPiThriftService.Processor(handler),
                                 TSocket.TServerSocket(port=port),
                                 TTransport.TBufferedTransportFactory(),
                                 TBinaryProtocol.TBinaryProtocolFactory())