Skip to content

Instantly share code, notes, and snippets.

@kgs
Last active December 19, 2015 16:39
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 kgs/7fec9f1367be32e53b99 to your computer and use it in GitHub Desktop.
Save kgs/7fec9f1367be32e53b99 to your computer and use it in GitHub Desktop.
jetty-async-client
public class Test {
public static void main(String[] args) throws Exception {
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setValidateCerts(false);
sslContextFactory.setValidatePeerCerts(false);
final HttpClient client = new HttpClient(sslContextFactory);
client.setMaxConnectionsPerDestination(250);
client.setMaxRequestsQueuedPerDestination(50);
client.setConnectTimeout(4000);
client.setIdleTimeout(5000);
client.setFollowRedirects(true);
client.start();
client.newRequest("http://google.com")
.timeout(10, TimeUnit.SECONDS)
.onRequestQueued(new Request.QueuedListener() {
@Override
public void onQueued(Request request) {
System.out.println("thread=" + Thread.currentThread().getName());
}
})
.onRequestHeaders(new Request.HeadersListener() {
@Override
public void onHeaders(Request request) {
System.out.println("thread=" + Thread.currentThread().getName());
}
})
.onRequestSuccess(new Request.SuccessListener() {
@Override
public void onSuccess(Request request) {
System.out.println("thread=" + Thread.currentThread().getName());
}
})
.send(new BufferingResponseListener() {
@Override
public void onComplete(Result result) {
System.out.println("thread=" + Thread.currentThread().getName());
}
});
Thread.sleep(5000);
client.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment