hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Micky Lee" <micky_...@cyberpowersystems.com.tw>
Subject Is there any simple Asynchronous Http Client can use?
Date Wed, 27 Oct 2010 09:00:45 GMT
Hi,

I want an asynchronous http client, and I found the svn repository: http://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/

I want a notify when the request has response with a callback function, but the AsyncHttpClient
only has the API to do "awaitResponse ()" method to wait and block until there is response.

I think the using of it may not be called an asynchronous http client.

The test case in example org.apache.http.examples.nio.client. AsyncClientRequest is 

----
...
HttpHost target = new HttpHost("www.google.ch", 80);
BasicHttpRequest request = new BasicHttpRequest("GET", "/"); 

HttpExchange[] httpx = new HttpExchange[10]; 
for (int i = 0; i < httpx.length; i++) {
      httpx[i] = asynchttpclient.execute(target, request);
}
        
for (int i = 0; i < httpx.length; i++) {
      HttpResponse response = httpx[i].awaitResponse();		// block here
      if (response != null) {
          System.out.println("Response: " + response.getStatusLine());
      }
}
...
----

When I change the code to following, it blocks one by one and not the one I want, because
I don't know which one will have response quickly.


----
...
HttpHost target = new HttpHost("www.google.ch", 80);
BasicHttpRequest request = new BasicHttpRequest("GET", "/"); 

HttpExchange[] httpx = new HttpExchange[10]; 
for (int i = 0; i < httpx.length; i++) {
    httpx[i] = asynchttpclient.execute(target, request);
	HttpResponse response = httpx[i].awaitResponse();	// block here
    if (response != null) {
        System.out.println("Response: " + response.getStatusLine());
    }
} 

...
----

Any suggestion is welcome, thanks in advance.


Sincerely,
Micky



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message