java - Thrift Async Client will not stop -
i wonder why without code remarked 1
, result not null
, application keeps running , never stop, , code remarked 2
doesn't print expected result.
but code remarked 1
, application finishes when result not null
,and prints code remarked 2
.
asyncmethodcallback
private object response=null; public object getresponse() { return response; } @override public void oncomplete(object response) { this.response=response; } @override public void onerror(exception exception) { exception.printstacktrace(); }
async server
public static void main(string[] args) { try { tnonblockingserversocket serversocket=new tnonblockingserversocket(10005); hello.processor<hello.iface> processor=new hello.processor<>(new helloserviceimpl()); tnonblockingserver.args serverargs=new tnonblockingserver.args(serversocket); tprotocolfactory factory=new tbinaryprotocol.factory(); serverargs.transportfactory(new tframedtransport.factory()); serverargs.processor(processor); serverargs.protocolfactory(factory); tserver server=new tnonblockingserver(serverargs); system.out.println("server start...."); server.serve(); } catch (ttransportexception e) { e.printstacktrace(); } }
async client
public static void main(string[] args) { try { tasyncclientmanager clientmanager=new tasyncclientmanager(); tnonblockingsocket socket=new tnonblockingsocket("localhost",10005); tprotocolfactory protocolfactory=new tbinaryprotocol.factory(); hello.asyncclient asyncclient=new hello.asyncclient(protocolfactory,clientmanager,socket); system.out.println("client calls...."); methodcallback<integer> methodcallback=new methodcallback<>(); asyncclient.helloint(14,methodcallback); object result=methodcallback.getresponse(); while (result==null){ result=methodcallback.getresponse(); // system.out.println("result "+result); //1 } system.out.println(result); //2 } catch (ioexception | texception e) { e.printstacktrace(); } }
Comments
Post a Comment