2

How can I use TBinaryProtocol and TFramedTransport in Java for Async server and client? Lot of the examples I get form web just fail and the documentation is not great. Any help with concrete example would be great!

public class NonblockingServer {

    private void start() {
        try {
            TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(7911);
            ArithmeticService.Processor processor = new ArithmeticService.Processor(new ArithmeticServiceImpl());


            TThreadPoolServer.Args serverArgs = newTThreadPoolServer.Args(serverTransport);
            serverArgs.processor(processor);
            serverArgs.protocolFactory(protocolFactory);
                TServer server = new TThreadPoolServer(serverArgs)
                System.out.println("Starting server on port 7911 ...");
                server.serve();
        } catch (TTransportException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        NonblockingServer srv = new NonblockingServer();
        srv.start();
    }
}

AsyncClient

public class AsyncClient {

    private void invoke() {
        try {
            ArithmeticService.AsyncClient client = new ArithmeticService.
                    AsyncClient(new TBinaryProtocol.Factory(), new TAsyncClientManager(),
                                new TNonblockingSocket("localhost", 7911));

            client.add(200, 400, new AddMethodCallback());

            client = new ArithmeticService.
                    AsyncClient(new TBinaryProtocol.Factory(), new TAsyncClientManager(),
                                new TNonblockingSocket("localhost", 7911));
            client.multiply(20, 50, new MultiplyMethodCallback());

        } catch (TTransportException e) {
            e.printStackTrace();
        } catch (TException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        AsyncClient c = new AsyncClient();
        c.invoke();

    }

I get the following exception Error :

java.io.IOException: Read call frame size failed
    at org.apache.thrift.async.TAsyncMethodCall.doReadingResponseSize(TAsyncMethodCall.java:234)
    at org.apache.thrift.async.TAsyncMethodCall.transition(TAsyncMethodCall.java:192)
    at org.apache.thrift.async.TAsyncClientManager$SelectThread.transitionMethods(TAsyncClientManager.java:143)
    at org.apache.thrift.async.TAsyncClientManager$SelectThread.run(TAsyncClientManager.java:113)

The Error seem occur here in the Thrift Source code

  private void doReadingResponseSize() throws IOException {
    if (transport.read(sizeBuffer) < 0) {
      throw new IOException("Read call frame size failed");
    }
    if (sizeBuffer.remaining() == 0) {
      state = State.READING_RESPONSE_BODY;
      frameBuffer = ByteBuffer.allocate(TFramedTransport.decodeFrameSize(sizeBufferArray));
    }
  }
user1870400
  • 6,028
  • 13
  • 54
  • 115
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – Jim Garrison Feb 06 '16 at 03:20
  • Please include the examples you tried. – Aaron Gillion Feb 06 '16 at 03:42
  • I just uploaded some examples that I kept trying but it never seems to work out. All I need is Async Client and Async Threadpool server in java – user1870400 Feb 06 '16 at 04:01
  • I was wrong, the error message did mislead me. Forgetting an implicitly expected "framed" is a quite common error (and the need for it is not very clearly documented), but it seems not to be the case here. First, the Java classes you use should already take care about this. Next, the error manifests on the client side (not on the server) while trying to read the response frame size (not the request). The big question is now, whether there are any (possibly wrong) data returned or if the client simply times out? I'd suggest to post that problem also on the mailing list. – JensG Feb 06 '16 at 22:20
  • Client doesn't time out and I also dont think wrong data is being returned by the server. – user1870400 Feb 06 '16 at 23:28
  • Did it ever got solved? I am stuck at the same issue. – Rahul Kushwaha Dec 11 '18 at 05:53

0 Answers0