节俭TNonblockingServer EOF例外

时间:2015-04-23 09:46:46

标签: java groovy thrift

我有用java编写的服务器应用程序,以及groovy中的客户端应用程序。 我的服务器获取请求并做某事。我使用Thrift和TNonBlockingServer。

    public static void nonBlockingServer(HbaseLayerService.Processor processor) {
            try {
                final Integer serverPort = ConfigurationManager.instance().getServerPort();
                TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(serverPort);
                TServer server = new TNonblockingServer(new TNonblockingServer.Args(serverTransport).processor(processor));

                server.serve();
            } catch (Exception e) {
                Throwables.propagate(e);
            }
        }

我的客户端发送~100Mb数据

TTransport transport = new TFramedTransport(new TSocket('localhost', 12345, 100000))
transport.open()
TProtocol protocol = new TBinaryProtocol(transport);
HbaseLayerService.Client client = new HbaseLayerService.Client(protocol);
def putList = [] //~1500000 objects (string, string, string, int, byte[])
client.putEvent(new PutEventsOperation(putsToSend));

在此操作期间我出错:

Exception in thread "main" org.apache.thrift.transport.TTransportException
    at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
    at org.apache.thrift.transport.TFramedTransport.readFrame(TFramedTransport.java:129)
    at org.apache.thrift.transport.TFramedTransport.read(TFramedTransport.java:101)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
    at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:429)
    at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:318)
    at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:219)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)
    at communication_struct.thrift.HbaseLayerService$Client.recv_putEvent(HbaseLayerService.java:96)

此例外的类型为4: END_OF_FILE

使用TSimpleServer一切正常,但我想采取一些连接并在一个线程中进行队列操作。

1 个答案:

答案 0 :(得分:2)

最后我找到了解决方案。 在这种特殊情况下,您应该将新尺寸添加到TFramedTransport.Factory,如下所示:

TServer server = new TNonblockingServer(new TNonblockingServer.Args(serverTransport)
                    .processor(processor)
                    .transportFactory(new TFramedTransport.Factory(MAX_FRAMED_TRANSPORT_SIZE))
                    .protocolFactory(new TBinaryProtocol.Factory())
            );

应在客户端进行相同的操作:

TTransport transport = new TFramedTransport(new TSocket('localhost', 12345), MAX_FRAMED_TRANSPORT_SIZE)

就我而言MAX_FRAMED_TRANSPORT_SIZE = 256 * 1024 * 1024