List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections
public void setMaxTotalConnections(int paramInt)
From source file:integration.HeavyLoad.java
public static void main(String[] args) throws IOException { url = args[0] + "/create.json"; final String specFile = args[1]; for (int i = 2; i < args.length; i++) { String server = args[i];/*from www.j ava 2 s. com*/ servers.add(new ServerStats(server)); } if (servers.isEmpty()) { servers.add(new ServerStats(DEFAULT)); } MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams params = connectionManager.getParams(); params.setSoTimeout(TIMEOUT); params.setConnectionTimeout(TIMEOUT); params.setDefaultMaxConnectionsPerHost(NB_THREADS); params.setMaxTotalConnections(NB_THREADS); httpClient = new HttpClient(connectionManager); spec = FileUtilities.readWholeTextFile(new File(specFile)); Thread[] threads = new Thread[NB_THREADS]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Reader(), "reader-" + i); threads[i].start(); } for (int i = 0; i < threads.length; i++) { try { threads[i].join(); } catch (InterruptedException e) { } } }
From source file:edu.ucsb.eucalyptus.transport.util.Defaults.java
public static MultiThreadedHttpConnectionManager getDefaultHttpManager() { MultiThreadedHttpConnectionManager httpConnMgr = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = httpConnMgr.getParams(); params.setDefaultMaxConnectionsPerHost(16); params.setMaxTotalConnections(16); params.setTcpNoDelay(true);//ww w . ja v a 2s . c o m params.setConnectionTimeout(120 * 1000); // params.setReceiveBufferSize( 8388608 ); // params.setSendBufferSize( 8388608 ); params.setStaleCheckingEnabled(true); params.setSoTimeout(120 * 1000); // params.setLinger( -1 ); return httpConnMgr; }
From source file:com.legstar.test.cixs.AbstractHttpClientTester.java
/** * Setup the static http connection pool. * /* w ww .ja v a2 s . com*/ * @return an http client instance */ protected static HttpClient createHttpClient() { HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS); connectionManagerParams.setDefaultMaxConnectionsPerHost(DEFAULT_MAX_CONNECTIONS_PER_HOST); connectionManagerParams.setTcpNoDelay(TCP_NO_DELAY); connectionManagerParams.setSoTimeout(SOCKET_TIMEOUT); connectionManagerParams.setConnectionTimeout(CONNECT_TIMEOUT); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(connectionManagerParams); connectionManager.closeIdleConnections(IDLE_CONNECTION_TIMEOUT); return new HttpClient(connectionManager); }
From source file:com.ms.commons.utilities.HttpClientUtils.java
public static synchronized void init() { if (connectionManager != null) { return;/*from w ww . j av a 2 s. c o m*/ } connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setConnectionTimeout(10000); params.setSoTimeout(20000); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 1000); params.setMaxTotalConnections(10000); connectionManager.setParams(params); client = new HttpClient(connectionManager); client.getParams().setParameter("http.protocol.max-redirects", 3); }
From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java
public static HttpClient makeHttpClient3(boolean usePool) { HttpClient httpClient;//from www. j ava2s . co m if (usePool) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); int maxTotalConnections = 100; try { maxTotalConnections = new Integer( EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_TOTAL_CONNECTIONS)) .intValue(); } catch (NumberFormatException e) { Engine.logEngine.warn("Unable to retrieve the max number of connections; defaults to 100."); } int maxConnectionsPerHost = 50; try { maxConnectionsPerHost = new Integer( EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_CONNECTIONS_PER_HOST)) .intValue(); } catch (NumberFormatException e) { Engine.logEngine .warn("Unable to retrieve the max number of connections per host; defaults to 100."); } HttpConnectionManagerParams httpConnectionManagerParams = new HttpConnectionManagerParams(); httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost); httpConnectionManagerParams.setMaxTotalConnections(maxTotalConnections); connectionManager.setParams(httpConnectionManagerParams); httpClient = new HttpClient(connectionManager); } else { httpClient = new HttpClient(); } HttpClientParams httpClientParams = (HttpClientParams) HttpClientParams.getDefaultParams(); httpClientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); /** #741 : belambra wants only one Set-Cookie header */ httpClientParams.setParameter("http.protocol.single-cookie-header", Boolean.TRUE); /** #5066 : httpClient auto retries failed request up to 3 times by default */ httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); httpClient.setParams(httpClientParams); return httpClient; }
From source file:edu.harvard.med.iccbl.screensaver.soaputils.PugSoapUtil.java
private static void updateStub(org.apache.axis2.client.Stub stub, int maxTotal, int maxPerHost) { MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = httpConnectionManager.getParams(); if (params == null) { params = new HttpConnectionManagerParams(); }/*w w w . j a v a 2 s . co m*/ params.setMaxTotalConnections(maxTotal); params.setDefaultMaxConnectionsPerHost(maxPerHost); // extra, not prescribed -sde4 params.setConnectionTimeout(600000); params.setSoTimeout(600000); httpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(httpConnectionManager); ServiceClient serviceClient = stub._getServiceClient(); ConfigurationContext context = serviceClient.getServiceContext().getConfigurationContext(); context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); }
From source file:ac.elements.io.Signature.java
/** * Configure HttpClient with set of defaults as well as configuration from * AmazonEC2Config instance./* w ww. j a v a 2 s.c om*/ * * @return the http client */ private static HttpClient configureHttpClient() { /* Set http client parameters */ HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setParameter(HttpMethodParams.USER_AGENT, USER_AGENT); httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) { if (executionCount > MAX_RETRY_ERROR) { log.warn("Maximum Number of Retry attempts " + "reached, will not retry"); return false; } log.warn("Retrying request. Attempt " + executionCount); if (exception instanceof NoHttpResponseException) { log.warn("Retrying on NoHttpResponseException"); return true; } if (exception instanceof InterruptedIOException) { log.warn("Will not retry on InterruptedIOException", exception); return false; } if (exception instanceof UnknownHostException) { log.warn("Will not retry on UnknownHostException", exception); return false; } if (!method.isRequestSent()) { log.warn("Retrying on failed sent request"); return true; } return false; } }); /* Set host configuration */ HostConfiguration hostConfiguration = new HostConfiguration(); /* Set connection manager parameters */ HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setConnectionTimeout(50000); connectionManagerParams.setSoTimeout(50000); connectionManagerParams.setStaleCheckingEnabled(true); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setMaxTotalConnections(MAX_CONNECTIONS); connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, MAX_CONNECTIONS); /* Set connection manager */ MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(connectionManagerParams); /* Set http client */ httpClient = new HttpClient(httpClientParams, connectionManager); /* Set proxy if configured */ // if (config.isSetProxyHost() && config.isSetProxyPort()) { // log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + // "Proxy Port: " + config.getProxyPort() ); // hostConfiguration.setProxy(config.getProxyHost(), // config.getProxyPort()); // if (config.isSetProxyUsername() && config.isSetProxyPassword()) { // httpClient.getState().setProxyCredentials (new AuthScope( // config.getProxyHost(), // config.getProxyPort()), // new UsernamePasswordCredentials( // config.getProxyUsername(), // config.getProxyPassword())); // // } // } httpClient.setHostConfiguration(hostConfiguration); return httpClient; }
From source file:fr.dutra.confluence2wordpress.xmlrpc.CommonsXmlRpcTransportFactory.java
public CommonsXmlRpcTransportFactory(URL url, String proxyHost, int proxyPort, int maxConnections) { this.url = url; HostConfiguration hostConf = new HostConfiguration(); hostConf.setHost(url.getHost(), url.getPort()); if (proxyHost != null && proxyPort != -1) { hostConf.setProxy(proxyHost, proxyPort); }/*from w w w . j av a2 s. co m*/ HttpConnectionManagerParams connParam = new HttpConnectionManagerParams(); connParam.setMaxConnectionsPerHost(hostConf, maxConnections); connParam.setMaxTotalConnections(maxConnections); MultiThreadedHttpConnectionManager conMgr = new MultiThreadedHttpConnectionManager(); conMgr.setParams(connParam); client = new HttpClient(conMgr); client.setHostConfiguration(hostConf); }
From source file:fr.aliasource.webmail.server.calendar.CalendarProxyImpl.java
private HttpClient createHttpClient() { HttpClient ret = new HttpClient(new MultiThreadedHttpConnectionManager()); HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams(); mp.setDefaultMaxConnectionsPerHost(4); mp.setMaxTotalConnections(8); return ret;// w ww. j a v a2 s. c o m }
From source file:com.taobao.metamorphosis.client.http.SimpleHttpClient.java
protected void initHttpClient(HttpClientConfig config) { HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(config.getHost(), config.getPort()); connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.closeIdleConnections(config.getPollingIntervalTime() * 4000); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(config.isConnectionStaleCheckingEnabled()); params.setMaxConnectionsPerHost(hostConfiguration, config.getMaxHostConnections()); params.setMaxTotalConnections(config.getMaxTotalConnections()); params.setConnectionTimeout(config.getTimeout()); params.setSoTimeout(60 * 1000);//from w ww . ja v a2 s.c o m connectionManager.setParams(params); httpclient = new HttpClient(connectionManager); httpclient.setHostConfiguration(hostConfiguration); }