-
-
Save s0j0urn/5289027e801ec14c82e6 to your computer and use it in GitHub Desktop.
HTTP/1.1 asynchronous requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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