Skip to content

Instantly share code, notes, and snippets.

@s0j0urn
Last active February 12, 2016 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s0j0urn/5289027e801ec14c82e6 to your computer and use it in GitHub Desktop.
Save s0j0urn/5289027e801ec14c82e6 to your computer and use it in GitHub Desktop.
HTTP/1.1 asynchronous requests
for(int i=0 ; i<urlsListSize ; i++ )
{
Request req_with_headers = client.newRequest(urlsList.get(i)).header(HttpHeader.ACCEPT, accept);
req_with_headers.header(HttpHeader.ACCEPT_ENCODING, accept_encoding);
req_with_headers.header(HttpHeader.ACCEPT_LANGUAGE, accept_language);
req_with_headers.header(HttpHeader.CACHE_CONTROL, cache_control);
req_with_headers.header(HttpHeader.CONNECTION, connection);
req_with_headers.header(HttpHeader.HOST,host);
req_with_headers.header(HttpHeader.PRAGMA, pragma);
req_with_headers.header(HttpHeader.REFERER, referrer);
//Lets do asynchronous requests
AtomicBoolean counted=new AtomicBoolean(false);
req_with_headers
.send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result) {
// TODO Auto-generated method stub
if (result.isFailed())
{
result.getFailure().printStackTrace();
failuresList.add("Result failed " + result);
}
else if (result.isSucceeded())
{
if(result.getResponse().getStatus()==200)
{
success_status_count.getAndIncrement();
}
}
if(!counted.getAndSet(true))
{
latch.countDown();
//System.out.println("countdown");
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment