List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager()
From source file:dataServer.StorageRESTClientManager.java
public StorageRESTClientManager() { //HttpParams httpParameters = new BasicHttpParams(); //int timeoutConnection = 5000; //HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); //int timeoutSocket = 5000; //HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultMaxPerRoute(20); connManager.setMaxTotal(40);//from w w w . ja v a2 s .c o m client = HttpClients.custom().setConnectionManager(connManager).build(); requestUrl = null; params = null; queryString = null; //get storage IPs, URLs and Ports from environment variables StreamPipes = System.getenv("StreamPipes"); storageLocation = System.getenv("StorageLocation"); storagePortReadC = System.getenv("StoragePortReadC"); storagePortRegistryC = System.getenv("StoragePortRegistryC"); System.out.println("Environment variables:"); System.out.println("StreamPipes: " + StreamPipes); System.out.println("storageLocation: " + storageLocation); System.out.println("storagePortReadC: " + storagePortReadC); System.out.println("storagePortRegistryC: " + storagePortRegistryC); }
From source file:io.seldon.external.ExternalItemRecommendationAlgorithm.java
@Autowired public ExternalItemRecommendationAlgorithm(ItemService itemService) { cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100);//from w ww . j a v a 2 s.c om cm.setDefaultMaxPerRoute(20); RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(DEFAULT_REQ_TIMEOUT) .setConnectTimeout(DEFAULT_CON_TIMEOUT).setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build(); httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build(); this.itemService = itemService; }
From source file:monasca.persister.repository.influxdb.InfluxV9RepoWriter.java
@Inject public InfluxV9RepoWriter(final PersisterConfig config) { this.influxName = config.getInfluxDBConfiguration().getName(); this.influxUrl = config.getInfluxDBConfiguration().getUrl() + "/write"; this.influxUser = config.getInfluxDBConfiguration().getUser(); this.influxPass = config.getInfluxDBConfiguration().getPassword(); this.influxCreds = this.influxUser + ":" + this.influxPass; this.influxRetentionPolicy = config.getInfluxDBConfiguration().getRetentionPolicy(); this.gzip = config.getInfluxDBConfiguration().getGzip(); this.baseAuthHeader = "Basic " + new String(Base64.encodeBase64(this.influxCreds.getBytes())); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(config.getInfluxDBConfiguration().getMaxHttpConnections()); if (this.gzip) { this.httpClient = HttpClients.custom().setConnectionManager(cm) .addInterceptorFirst(new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); }//w w w . j a va 2s .c o m } }).addInterceptorFirst(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); if (entity != null) { Header ceheader = entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } } }).build(); } else { this.httpClient = HttpClients.custom().setConnectionManager(cm).build(); } }
From source file:fi.helsinki.opintoni.config.OodiConfiguration.java
private ClientHttpRequestFactory clientHttpRequestFactory() { HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); factory.setReadTimeout(appConfiguration.getInteger("httpClient.readTimeout")); factory.setConnectTimeout(appConfiguration.getInteger("httpClient.connectTimeout")); PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(); poolingHttpClientConnectionManager.setMaxTotal(appConfiguration.getInteger("httpClient.maxTotal")); poolingHttpClientConnectionManager//from ww w. jav a 2s . c om .setDefaultMaxPerRoute(appConfiguration.getInteger("httpClient.defaultMaxPerRoute")); CloseableHttpClient httpClient = HttpClientBuilder.create() .setConnectionManager(poolingHttpClientConnectionManager).build(); factory.setHttpClient(httpClient); return new BufferingClientHttpRequestFactory(factory); }
From source file:co.tuzza.swipehq.transport.ManagedHttpTransport.java
protected ManagedHttpTransport(int connectionTimeout, int socketTimeout) throws NoSuchAlgorithmException { this.connectionTimeout = connectionTimeout; this.socketTimeout = socketTimeout; this.sslContext = SwipeHQClient.getSSLContext(); this.clientConnectionManager = new PoolingHttpClientConnectionManager(); this.clientConnectionManager.setDefaultMaxPerRoute(200); this.clientConnectionManager.setMaxTotal(200); }
From source file:gobblin.compaction.audit.KafkaAuditCountHttpClient.java
/** * Constructor/*from w ww . j av a 2s .c o m*/ */ public KafkaAuditCountHttpClient(State state) { int maxTotal = state.getPropAsInt(CONNECTION_MAX_TOTAL, DEFAULT_CONNECTION_MAX_TOTAL); int maxPerRoute = state.getPropAsInt(MAX_PER_ROUTE, DEFAULT_MAX_PER_ROUTE); cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(maxTotal); cm.setDefaultMaxPerRoute(maxPerRoute); httpClient = HttpClients.custom().setConnectionManager(cm).build(); this.baseUrl = state.getProp(KAFKA_AUDIT_REST_BASE_URL); this.maxNumTries = state.getPropAsInt(KAFKA_AUDIT_REST_MAX_TRIES, 5); this.startQueryString = state.getProp(KAFKA_AUDIT_REST_START_QUERYSTRING_KEY, KAFKA_AUDIT_REST_START_QUERYSTRING_DEFAULT); this.endQueryString = state.getProp(KAFKA_AUDIT_REST_END_QUERYSTRING_KEY, KAFKA_AUDIT_REST_END_QUERYSTRING_DEFAULT); }
From source file:mobi.jenkinsci.server.core.net.PooledHttpClientFactory.java
private PoolingHttpClientConnectionManager getHttpConnectionManager() { final PoolingHttpClientConnectionManager httpConnManager = new PoolingHttpClientConnectionManager(); httpConnManager.setMaxTotal(config.getHttpMaxConnections()); return httpConnManager; }
From source file:io.seldon.external.ExternalPluginServer.java
@Override public void configUpdated(String configKey, String configValue) { if (configValue != null && configValue.length() > 0) { ObjectMapper mapper = new ObjectMapper(); try {//from ww w .ja v a 2 s . c o m PredictionServerConfig config = mapper.readValue(configValue, PredictionServerConfig.class); cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(config.maxConnections); cm.setDefaultMaxPerRoute(config.maxConnections); httpClient = HttpClients.custom().setConnectionManager(cm).build(); logger.info("Updated httpclient to use " + config.maxConnections + " max connections"); } catch (Exception e) { throw new RuntimeException(String.format("* Error * parsing statsd configValue[%s]", configValue), e); } } }
From source file:org.esigate.test.cases.PerformanceTestCase.java
/** * Execute la tache avec plusieurs Threads * //ww w .j ava 2 s .c om * @param request * @return * @throws Exception */ private long execute(HttpGetRequestRunnable request, int numberOfRequests, int threads) throws Exception { connectionManager = new PoolingHttpClientConnectionManager(); httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).setMaxConnTotal(threads) .setMaxConnPerRoute(threads).setDefaultRequestConfig( RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).build()) .build(); // Warm up request.run(); BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(); ThreadPoolExecutor threadPool = new ThreadPoolExecutor(threads, threads, 5, TimeUnit.SECONDS, queue); long start = System.currentTimeMillis(); threadPool.prestartAllCoreThreads(); for (int i = 0; i < numberOfRequests; i++) { threadPool.submit(request); } threadPool.shutdown(); // wait maximum 20 s threadPool.awaitTermination(200, TimeUnit.SECONDS); connectionManager.shutdown(); if (request.exception != null) { throw new AssertionFailedError( "Exception for request " + request.url + " after " + request.count + " requests", request.exception); } if (threadPool.getCompletedTaskCount() < threadPool.getTaskCount()) { // All task were not executed String msg = request.url + " : Only " + threadPool.getCompletedTaskCount() + "/" + threadPool.getTaskCount() + " have been renderered " + " => Maybe a performance issue"; threadPool.shutdownNow(); fail(msg); } long end = System.currentTimeMillis(); long execTime = end - start; LOG.debug("Executed request " + request.url + " " + numberOfRequests + " times with " + threads + " threads in " + execTime + "ms"); return execTime; }