thrift - How can I use TBinaryProtocol and TFramedTransport in Java for Async server and client? -
how can use tbinaryprotocol , tframedtransport in java async server , client? lot of examples form web fail , documentation not great. concrete example 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 following exception error :
java.io.ioexception: read call frame size failed @ org.apache.thrift.async.tasyncmethodcall.doreadingresponsesize(tasyncmethodcall.java:234) @ org.apache.thrift.async.tasyncmethodcall.transition(tasyncmethodcall.java:192) @ org.apache.thrift.async.tasyncclientmanager$selectthread.transitionmethods(tasyncclientmanager.java:143) @ org.apache.thrift.async.tasyncclientmanager$selectthread.run(tasyncclientmanager.java:113)
the error seem occur here in 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)); } }
Comments
Post a Comment