use of org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager in project tutorials by eugenp.
the class HttpAsyncClientLiveTest method whenUseMultipleHttpAsyncClient_thenCorrect.
@Test
public void whenUseMultipleHttpAsyncClient_thenCorrect() throws Exception {
final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
final PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(ioReactor);
final CloseableHttpAsyncClient client = HttpAsyncClients.custom().setConnectionManager(cm).build();
client.start();
final String[] toGet = { "http://www.google.com/", "http://www.apache.org/", "http://www.bing.com/" };
final GetThread[] threads = new GetThread[toGet.length];
for (int i = 0; i < threads.length; i++) {
final HttpGet request = new HttpGet(toGet[i]);
threads[i] = new GetThread(client, request);
}
for (final GetThread thread : threads) {
thread.start();
}
for (final GetThread thread : threads) {
thread.join();
}
}
use of org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager in project SSM by Intel-bigdata.
the class HttpProxyClient method getAsyncConnectionManager.
private PoolingNHttpClientConnectionManager getAsyncConnectionManager() {
ConnectingIOReactor ioReactor = null;
PoolingNHttpClientConnectionManager cm = null;
try {
ioReactor = new DefaultConnectingIOReactor();
// ssl setup
SSLContext sslcontext = SSLContexts.createSystemDefault();
X509HostnameVerifier hostnameVerifier = new BrowserCompatHostnameVerifier();
@SuppressWarnings("deprecation") Registry<SchemeIOSessionStrategy> sessionStrategyRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create().register("http", NoopIOSessionStrategy.INSTANCE).register("https", new SSLIOSessionStrategy(sslcontext, hostnameVerifier)).build();
cm = new PoolingNHttpClientConnectionManager(ioReactor, sessionStrategyRegistry);
} catch (IOReactorException e) {
LOG.error("Couldn't initialize multi-threaded async client ", e);
return null;
}
return cm;
}
use of org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager in project SSM by Intel-bigdata.
the class HttpProxyClient method getAsyncProxyHttpClient.
private CloseableHttpAsyncClient getAsyncProxyHttpClient(URI proxyUri) {
LOG.info("Creating async proxy http client");
PoolingNHttpClientConnectionManager cm = getAsyncConnectionManager();
HttpHost proxy = new HttpHost(proxyUri.getHost(), proxyUri.getPort());
HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
if (cm != null) {
clientBuilder = clientBuilder.setConnectionManager(cm);
}
if (proxy != null) {
clientBuilder = clientBuilder.setProxy(proxy);
}
clientBuilder = setRedirects(clientBuilder);
return clientBuilder.build();
}
use of org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager in project incubator-gobblin by apache.
the class ApacheHttpAsyncClient method getNHttpConnManager.
private NHttpClientConnectionManager getNHttpConnManager(Config config) throws IOException {
NHttpClientConnectionManager httpConnManager;
String connMgrStr = config.getString(HTTP_CONN_MANAGER);
switch(ApacheHttpClient.ConnManager.valueOf(connMgrStr.toUpperCase())) {
case POOLING:
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
PoolingNHttpClientConnectionManager poolingConnMgr = new PoolingNHttpClientConnectionManager(ioReactor);
poolingConnMgr.setMaxTotal(config.getInt(POOLING_CONN_MANAGER_MAX_TOTAL_CONN));
poolingConnMgr.setDefaultMaxPerRoute(config.getInt(POOLING_CONN_MANAGER_MAX_PER_CONN));
httpConnManager = poolingConnMgr;
break;
default:
throw new IllegalArgumentException(connMgrStr + " is not supported");
}
LOG.info("Using " + httpConnManager.getClass().getSimpleName());
return httpConnManager;
}
Aggregations