users@grizzly.java.net

Re: Async http calls

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Mon, 18 Jul 2011 10:54:57 +0200

Hi Denis,

> My question is about grizzly-http-webserver 1.9. Currently I work on
> the highload web-service. I want to make asynchronouse http calls. As
> a http-client I chosen the com.ning async-http-client. Can I do the
> current thread be yielded after the async call and the request
> processing be finished after getting http response?
Sure, you have to use response.suspend/resume methods.
Schematically it will look following:

/*response.suspend(...)*
asyncHttpClient.execute(myHttpRequest, new MyCompletionHandler() {
             public void onComplete() {
*response.resume()*;
             }
}/

You may want to use Grizzly 2.0, where we have also implemented NIO
streams, so your impl. wouldn't block on read or write.
Here you can find more docs:

http://grizzly.java.net/nonav/docs/docbkx2.0/html/hsf-suspend-resume.html
http://grizzly.java.net/nonav/docs/docbkx2.0/html/hsf-nio-streams.html

Thanks.

WBR,
Alexey.