List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setDefaultMaxConnectionsPerHost
public void setDefaultMaxConnectionsPerHost(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];// ww w.j av a 2 s.co m 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);/*from w ww .ja v a 2 s. c o m*/ params.setTcpNoDelay(true); 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.twinsoft.convertigo.engine.util.HttpUtils.java
public static HttpClient makeHttpClient3(boolean usePool) { HttpClient httpClient;/*from w w w.j av a2s .c o 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:com.legstar.test.cixs.AbstractHttpClientTester.java
/** * Setup the static http connection pool. * //from ww w . j a v a 2s . c o m * @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: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(); }/*from w w w . j a va2 s .c o 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: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);/* w w w.j a v a 2 s . c o m*/ return ret; }
From source file:com.duowan.common.rpc.client.CommonsHttpInvokerRequestExecutor.java
/** * Create a new CommonsHttpInvokerRequestExecutor with a default * HttpClient that uses a default MultiThreadedHttpConnectionManager. * Sets the socket read timeout to {@link #DEFAULT_READ_TIMEOUT_MILLISECONDS}. * @see org.apache.commons.httpclient.HttpClient * @see org.apache.commons.httpclient.MultiThreadedHttpConnectionManager */// w w w. j av a2 s . c o m public CommonsHttpInvokerRequestExecutor() { MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(300); params.setMaxTotalConnections(500); httpConnectionManager.setParams(params); this.httpClient = new HttpClient(httpConnectionManager); this.setReadTimeout(getReadTimeout()); this.setConnectionTimeout(getConnectionTimeout()); }
From source file:com.creditease.bdp.axis2.transport.http.HTTPSender.java
@Override protected HttpClient getHttpClient(MessageContext msgContext) { ConfigurationContext configContext = msgContext.getConfigurationContext(); HttpClient httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); if (httpClient == null) { httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); }//from w w w. j av a 2 s .co m if (httpClient != null) { return httpClient; } synchronized (this) { httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); if (httpClient == null) { httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); } if (httpClient != null) { return httpClient; } HttpConnectionManager connManager = (HttpConnectionManager) msgContext .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER); if (connManager == null) { connManager = (HttpConnectionManager) msgContext .getProperty(HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER); } if (connManager == null) { // reuse HttpConnectionManager synchronized (configContext) { connManager = (HttpConnectionManager) configContext .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER); if (connManager == null) { log.trace("Making new ConnectionManager"); connManager = new MultiThreadedHttpConnectionManager(); // NOTE: Added by CJ Integer maxConnectionPerHostConf = (Integer) msgContext .getProperty(Constants.MAX_CONNECTIONS_PER_HOST); Integer maxConnectionTotalConf = (Integer) msgContext .getProperty(Constants.MAX_CONNECTIONS_TOTAL); if (maxConnectionPerHostConf != null || maxConnectionTotalConf != null) { HttpConnectionManagerParams param = new HttpConnectionManagerParams(); if (maxConnectionPerHostConf != null) { param.setDefaultMaxConnectionsPerHost(maxConnectionPerHostConf); } if (maxConnectionTotalConf != null) { param.setMaxTotalConnections(maxConnectionTotalConf); } connManager.setParams(param); } configContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager); } } } /* * Create a new instance of HttpClient since the way * it is used here it's not fully thread-safe. */ httpClient = new HttpClient(connManager); // Set the default timeout in case we have a connection pool starvation to 30sec httpClient.getParams().setConnectionManagerTimeout(30000); // Get the timeout values set in the runtime initializeTimeouts(msgContext, httpClient); return httpClient; } }
From source file:com.itude.mobile.mobbl.server.http.HttpDelegate.java
private HttpDelegate() { logger.debug("HttpDelegate.HttpDelegate()"); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connectionParameters = connectionManager.getParams(); connectionParameters.setDefaultMaxConnectionsPerHost(CONNECTIONS_PER_HOST); connectionParameters.setMaxTotalConnections(TOTAL_CONNECTIONS); connectionParameters.setConnectionTimeout(CONNECTION_TIMEOUT); httpClient = new HttpClient(connectionManager); }
From source file:HTTPChunkLocator.java
public HTTPChunkLocator(final HttpClient client, URI aUri) { final HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams(); params.setConnectionTimeout(10000);/*from ww w. j av a 2 s.c o m*/ params.setTcpNoDelay(true); params.setDefaultMaxConnectionsPerHost(10); client.getHttpConnectionManager().setParams(params); this.client = client; this.endpoint = aUri; }