.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.USER_AGENT, "Test/1.1");
final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, params);
// Limit total number of connections to just two
pool.setDefaultMaxPerRoute(2);
pool.setMaxTotal(2);
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
new RequestContent(),
new RequestTargetHost(),
new RequestConnControl(),
new RequestUserAgent(),
new RequestExpectContinue()});
// Initialize default SSL context
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, null, null);
BufferingHttpClientHandler handler = new BufferingHttpClientHandler(
httpproc,
new MyHttpRequestExecutionHandler(),
new DefaultConnectionReuseStrategy(),
params);
final IOEventDispatch ioEventDispatch = new SSLClientIOEventDispatch(
handler,
sslcontext,
params);
Thread t = new Thread(new Runnable() {
public void run() {
try {
ioReactor.execute(ioEventDispatch);
} catch (InterruptedIOException ex) {
System.err.println("Interrupted");
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
}
});
t.start();
CountDownLatch requestCount = new CountDownLatch(3);
pool.lease(new HttpHost("www.verisign.com", 443), null,
new AsyncRequestExecutor(new BasicHttpRequest("GET", "/"), pool, requestCount));
pool.lease(new HttpHost("www.yahoo.com", 443), null,
new AsyncRequestExecutor(new BasicHttpRequest("GET", "/"), pool, requestCount));
pool.lease(new HttpHost("apache.org", 443), null,
new AsyncRequestExecutor(new BasicHttpRequest("GET", "/"), pool, requestCount));
// Block until all connections signal
// completion of the request execution
requestCount.await(30, TimeUnit.SECONDS);