Example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams MAX_TOTAL_CONNECTIONS

List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams MAX_TOTAL_CONNECTIONS

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams MAX_TOTAL_CONNECTIONS.

Prototype

String MAX_TOTAL_CONNECTIONS

To view the source code for org.apache.commons.httpclient.params HttpConnectionManagerParams MAX_TOTAL_CONNECTIONS.

Click Source Link

Usage

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   w  ww .j  a va 2  s. c o 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.
 * @param opts The FileSystem options.//from w  w w . j a  va2 s  . c  o  m
 * @param maxTotalConnections The maximum number of connections.
 * @since 2.0
 */
public void setMaxTotalConnections(final FileSystemOptions opts, final int maxTotalConnections) {
    setParam(opts, HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, Integer.valueOf(maxTotalConnections));
}

From source file:com.datos.vfs.provider.http.HttpFileSystemConfigBuilder.java

/**
 * Retrieve the maximum number of connections allowed.
 * @param opts The FileSystemOptions.//from   w  w w . j a  va2  s .  c o m
 * @return The maximum number of connections allowed.
 * @since 2.0
 */
public int getMaxTotalConnections(final FileSystemOptions opts) {
    return getInteger(opts, HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_CONNECTIONS);
}

From source file:org.apache.abdera.protocol.client.AbderaClient.java

/**
 * Return the maximum number of connections allowed for the client
 *//*from  w  ww  .j ava2  s  .  c  o  m*/
public AbderaClient setMaxConnectionsTotal(int max) {
    client.getHttpConnectionManager().getParams()
            .setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, max);
    return this;
}

From source file:org.apache.abdera.protocol.client.AbderaClient.java

/**
 * Return the maximum number of connections allowed for the client
 *///from  w w w  .  j  a v  a  2s .  c o m
public int getMaxConnectionsTotal() {
    return client.getHttpConnectionManager().getParams().getIntParameter(
            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
            MultiThreadedHttpConnectionManager.DEFAULT_MAX_TOTAL_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);
    }//w  w  w.j av a2  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   www .j  av a 2  s  .co 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());
    }//from  ww  w  .  j  a v  a  2 s .c  om
}

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());
    }/*from w  w  w.  j a  va  2  s. co 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   www.  j a v  a2  s  . c om
    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();
}