RESTEasy + Asynchronous + Callback Method + Java -
i want support both synchronous , asynchronous call using resteasy-jaxrs. , asynchronous call should based on callback, async request have callbackuri, request gets processed asynchronously , upon completion makes call callbackuri operation status/result. can point me out correct place? see lot polling model, not callback resteasy.
i new asynchronous stuff...
thanks in advance!
thanks response rmlan.yes have support in jax-rs handle asynchronous using @suspended & asyncresponse. did following code, unable find way make callback client called api upon completion of task request.
@get @path("/async") public string checkasync(@suspended final asyncresponse response) { response.settimeouthandler(new timeouthandler() { @override public void handletimeout(asyncresponse asyncresponse) { response.resume(response.status(response.status.service_unavailable) .entity("operation time out.").build()); } }); response.settimeout(2, timeunit.seconds); new thread(new runnable() { @override public void run() { string result = veryexpensiveoperation(); response.resume(result); } private string veryexpensiveoperation() { try { thread.sleep(5000); } catch (interruptedexception e) { e.printstacktrace(); } logger.debug("task processed fully"); return "successful"; } }).start(); return "nothing"; }
every method in class has 1 return ( or maybe void ) . need callbacks method . solution .
public abstract class myclass { public abstract void mycallbackmethod(); public void mymethod(){ (int = 0; < 5; i++) { // somthing mycallbackmethod();// implements in future. } } } when make object myclass , must implement mycallbackmethod abstract method .
public class newmain { public static void main(string[] args) { myclass myclass=new myclass() { @override public void mycallbackmethod() { system.err.println("this call back"); } }; myclass.mymethod(); } } and result
this call back
this call back
this call back
this call back
this call back
it means can 5 call backs void method in class. way when not have idea body content of mycallbackmethod
the real example download file server in app .
you can call mycallbackmethod when bytes received , progress progressbar
Comments
Post a Comment