List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams MAX_HOST_CONNECTIONS
String MAX_HOST_CONNECTIONS
To view the source code for org.apache.commons.httpclient.params HttpConnectionManagerParams MAX_HOST_CONNECTIONS.
Click Source Link
From source file:com.discursive.jccook.httpclient.MultithreadedExample.java
public void start() throws InterruptedException { HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = connectionManager.getParams(); params.setIntParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 2); params.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 4); List retrievers = new ArrayList(); for (int i = 0; i < 20; i++) { HttpClient client = new HttpClient(connectionManager); Thread thread = new Thread(new PageRetriever(client)); retrievers.add(thread);/*from www . jav a 2 s. co m*/ } Iterator threadIter = retrievers.iterator(); while (threadIter.hasNext()) { Thread thread = (Thread) threadIter.next(); thread.start(); } }
From source file:com.datos.vfs.provider.http.HttpFileSystemConfigBuilder.java
/** * The maximum number of connections allowed to any host. * @param opts The FileSystem options.// ww w . j ava 2 s. co m * @param maxHostConnections The maximum number of connections to a host. * @since 2.0 */ public void setMaxConnectionsPerHost(final FileSystemOptions opts, final int maxHostConnections) { setParam(opts, HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, Integer.valueOf(maxHostConnections)); }
From source file:com.datos.vfs.provider.http.HttpFileSystemConfigBuilder.java
/** * Retrieve the maximum number of connections allowed per host. * @param opts The FileSystemOptions./*from w ww . j ava2 s . c o m*/ * @return The maximum number of connections allowed per host. * @since 2.0 */ public int getMaxConnectionsPerHost(final FileSystemOptions opts) { return getInteger(opts, HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, DEFAULT_MAX_HOST_CONNECTIONS); }
From source file:org.apache.abdera.protocol.client.AbderaClient.java
/** * Set the maximum number of connections allowed for a single host *///from ww w . jav a2 s .co m public AbderaClient setMaxConnectionsPerHost(int max) { Map<HostConfiguration, Integer> m = new HashMap<HostConfiguration, Integer>(); m.put(HostConfiguration.ANY_HOST_CONFIGURATION, max); client.getHttpConnectionManager().getParams().setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, m); return this; }
From source file:org.apache.abdera.protocol.client.AbderaClient.java
/** * Return the maximum number of connections allowed for a single host *///from w ww. j a v a2s. c om public int getMaxConnectionsPerHost() { Map<HostConfiguration, Integer> m = (Map<HostConfiguration, Integer>) client.getHttpConnectionManager() .getParams().getParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS); if (m == null) return MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS; Integer i = m.get(HostConfiguration.ANY_HOST_CONFIGURATION); return i != null ? i.intValue() : MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS; }
From source file:org.apache.ode.axis2.ODEServer.java
private void initHttpConnectionManager() throws ServletException { httpConnectionManager = new MultiThreadedHttpConnectionManager(); // settings may be overridden from ode-axis2.properties using the same properties as HttpClient // /!\ If the size of the conn pool is smaller than the size of the thread pool, the thread pool might get starved. int max_per_host = Integer.parseInt(_odeConfig.getProperty(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, "" + _odeConfig.getPoolMaxSize())); int max_total = Integer.parseInt(_odeConfig.getProperty(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, "" + _odeConfig.getPoolMaxSize())); if (__log.isDebugEnabled()) { __log.debug(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + "=" + max_per_host); __log.debug(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + "=" + max_total); }/*from w w w .j ava 2 s .c o m*/ if (max_per_host < 1 || max_total < 1) { String errmsg = HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + " and " + HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + " must be positive integers!"; __log.error(errmsg); throw new ServletException(errmsg); } httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(max_per_host); httpConnectionManager.getParams().setMaxTotalConnections(max_total); // Register the connection manager to a idle check thread idleConnectionTimeoutThread = new IdleConnectionTimeoutThread(); idleConnectionTimeoutThread.setName("Http_Idle_Connection_Timeout_Thread"); long idleConnectionTimeout = Long .parseLong(_odeConfig.getProperty("http.idle.connection.timeout", "30000")); long idleConnectionCheckInterval = Long .parseLong(_odeConfig.getProperty("http.idle.connection.check.interval", "30000")); if (__log.isDebugEnabled()) { __log.debug("http.idle.connection.timeout=" + idleConnectionTimeout); __log.debug("http.idle.connection.check.interval=" + idleConnectionCheckInterval); } idleConnectionTimeoutThread.setConnectionTimeout(idleConnectionTimeout); idleConnectionTimeoutThread.setTimeoutInterval(idleConnectionCheckInterval); idleConnectionTimeoutThread.addConnectionManager(httpConnectionManager); idleConnectionTimeoutThread.start(); }
From source file:org.kuali.rice.kew.config.ThinClientResourceLoader.java
protected void initializeHttpClientParams() { httpClientParams = new HttpClientParams(); configureDefaultHttpClientParams(httpClientParams); Properties configProps = ConfigContext.getCurrentContextConfig().getProperties(); for (Iterator iterator = configProps.keySet().iterator(); iterator.hasNext();) { String paramName = (String) iterator.next(); if (paramName.startsWith("http.")) { HttpClientHelper.setParameter(httpClientParams, paramName, (String) configProps.get(paramName)); }//from w w w .jav a 2 s . c o m } String maxConnectionsValue = configProps.getProperty(MAX_CONNECTIONS); if (!StringUtils.isEmpty(maxConnectionsValue)) { Integer maxConnections = new Integer(maxConnectionsValue); Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>(); maxHostConnectionsMap.put(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections); httpClientParams.setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, maxHostConnectionsMap); httpClientParams.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, maxConnections); } String connectionManagerTimeoutValue = configProps.getProperty(CONNECTION_MANAGER_TIMEOUT); if (!StringUtils.isEmpty(connectionManagerTimeoutValue)) { httpClientParams.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new Long(connectionManagerTimeoutValue)); } String connectionTimeoutValue = configProps.getProperty(CONNECTION_TIMEOUT); if (!StringUtils.isEmpty(connectionTimeoutValue)) { httpClientParams.setIntParameter(HttpConnectionManagerParams.CONNECTION_TIMEOUT, new Integer(connectionTimeoutValue)); } }
From source file:org.kuali.rice.kew.config.ThinClientResourceLoader.java
protected void configureDefaultHttpClientParams(HttpParams params) { params.setParameter(HttpClientParams.CONNECTION_MANAGER_CLASS, MultiThreadedHttpConnectionManager.class); params.setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109); params.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new Long(DEFAULT_CONNECTION_MANAGER_TIMEOUT)); Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>(); maxHostConnectionsMap.put(HostConfiguration.ANY_HOST_CONFIGURATION, new Integer(DEFAULT_MAX_CONNECTIONS)); params.setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, maxHostConnectionsMap); params.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, new Integer(DEFAULT_MAX_CONNECTIONS)); params.setIntParameter(HttpConnectionManagerParams.CONNECTION_TIMEOUT, new Integer(DEFAULT_CONNECTION_TIMEOUT)); boolean retrySocketException = new Boolean( ConfigContext.getCurrentContextConfig().getProperty(RETRY_SOCKET_EXCEPTION_PROPERTY)); if (retrySocketException) { LOG.info("Installing custom HTTP retry handler to retry requests in face of SocketExceptions"); params.setParameter(HttpMethodParams.RETRY_HANDLER, new CustomHttpMethodRetryHandler()); }//www. j a v a 2 s . c o m }
From source file:org.kuali.rice.ksb.messaging.serviceconnectors.HttpInvokerConnector.java
protected void configureDefaultHttpClientParams(HttpParams params) { params.setParameter(HttpClientParams.CONNECTION_MANAGER_CLASS, MultiThreadedHttpConnectionManager.class); params.setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109); params.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 10000); Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>(); maxHostConnectionsMap.put(HostConfiguration.ANY_HOST_CONFIGURATION, new Integer(20)); params.setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, maxHostConnectionsMap); params.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 20); params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000); params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 2 * 60 * 1000); boolean retrySocketException = new Boolean( ConfigContext.getCurrentContextConfig().getProperty(RETRY_SOCKET_EXCEPTION_PROPERTY)); if (retrySocketException) { LOG.info("Installing custom HTTP retry handler to retry requests in face of SocketExceptions"); params.setParameter(HttpMethodParams.RETRY_HANDLER, new CustomHttpMethodRetryHandler()); }/* w w w . j av a 2 s.c o m*/ }
From source file:org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl.java
private void initHttpConnectionManager() throws Exception { httpConnectionManager = new MultiThreadedHttpConnectionManager(); int maxConnectionsPerHost = bpelServerConfiguration.getMaxConnectionsPerHost(); int maxTotalConnections = bpelServerConfiguration.getMaxTotalConnections(); if (log.isDebugEnabled()) { log.debug(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + "=" + maxConnectionsPerHost); log.debug(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + "=" + maxTotalConnections); }/*from ww w. ja va 2 s. com*/ if (maxConnectionsPerHost < 1 || maxTotalConnections < 1) { String errmsg = HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + " and " + HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + " must be positive integers!"; log.error(errmsg); throw new Exception(errmsg); } httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionsPerHost); httpConnectionManager.getParams().setMaxTotalConnections(maxTotalConnections); // TODO: Modify this and move configuration to bps.xml // Register the connection manager to a idle check thread idleConnectionTimeoutThread = new IdleConnectionTimeoutThread(); idleConnectionTimeoutThread.setName("Http_Idle_Connection_Timeout_Thread"); long idleConnectionTimeout = Long .parseLong(odeConfigurationProperties.getProperty("http.idle.connection.timeout", "30000")); long idleConnectionCheckInterval = Long .parseLong(odeConfigurationProperties.getProperty("http.idle.connection.check.interval", "30000")); if (log.isDebugEnabled()) { log.debug("http.idle.connection.timeout=" + idleConnectionTimeout); log.debug("http.idle.connection.check.interval=" + idleConnectionCheckInterval); } idleConnectionTimeoutThread.setConnectionTimeout(idleConnectionTimeout); idleConnectionTimeoutThread.setTimeoutInterval(idleConnectionCheckInterval); idleConnectionTimeoutThread.addConnectionManager(httpConnectionManager); idleConnectionTimeoutThread.start(); }