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

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

Introduction

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

Prototype

public void setMaxTotalConnections(int paramInt) 

Source Link

Usage

From source file:oauth.OAuthTokenValidaterStubFactory.java

/**
 * This created httpclient pool that can be used to connect to external entity. This connection can be configured
 * via broker.xml by setting up the required http connection parameters.
 *
 * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
 */// w  ww  .j  a va  2  s  . co  m
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(Integer
            .parseInt(tokenValidationProperties.getProperty(UIConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(
            Integer.parseInt(tokenValidationProperties.getProperty(UIConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:open.hyperion.nimblestorage.connection.NimbleStorageAPIFactory.java

/**
 * Initialize HTTP client//w  ww .  j  a v a2  s  . c  om
 */
public void init() {
    _log.info("NimbleStorageDriver:NimbleStorageAPIFactory init enter");
    _clientMap = new ConcurrentHashMap<String, NimbleStorageAPI>();

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setMaxTotalConnections(_maxConn);
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(_connTimeout);
    params.setSoTimeout(_socketConnTimeout);

    _connectionManager = new MultiThreadedHttpConnectionManager();
    _connectionManager.setParams(params);
    _connectionManager.closeIdleConnections(0); // close idle connections immediately

    HttpClient client = new HttpClient(_connectionManager);
    client.getParams().setConnectionManagerTimeout(_connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });

    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080));
}

From source file:open.hyperion.purestorage.connection.PureStorageAPIFactory.java

/**
 * Initialize HTTP client/*from w  ww .ja  v a2  s  .c om*/
 */
public void init() {
    _log.info("PureStorageDriver:PureStorageAPIFactory init enter");
    _clientMap = new ConcurrentHashMap<String, PureStorageAPI>();

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setMaxTotalConnections(_maxConn);
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(_connTimeout);
    params.setSoTimeout(_socketConnTimeout);

    _connectionManager = new MultiThreadedHttpConnectionManager();
    _connectionManager.setParams(params);
    _connectionManager.closeIdleConnections(0); // close idle connections immediately

    HttpClient client = new HttpClient(_connectionManager);
    client.getParams().setConnectionManagerTimeout(_connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });

    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080));
}

From source file:org.ala.harvester.BiocacheHarvester.java

public BiocacheHarvester() {
    int timeout = 3000; //msec

    hashTable = new Hashtable<String, String>();
    hashTable.put("accept", "application/json");

    mapper = new ObjectMapper();
    mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    HttpConnectionManagerParams params;
    MultiThreadedHttpConnectionManager m_connectionmgr = new MultiThreadedHttpConnectionManager();
    params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(timeout);
    params.setSoTimeout(timeout);/*from  w ww . j a  v a 2  s  .  c  o m*/
    params.setDefaultMaxConnectionsPerHost(100);
    params.setMaxTotalConnections(3000);
    m_connectionmgr.setParams(params);
    httpClient = new HttpClient(m_connectionmgr);

    // Default is to search all records. The query can be modified using the -query argument to the main method.
    biocacheSearchQuery = "*:*";
}

From source file:org.alfresco.httpclient.HttpClientFactory.java

protected HttpClient constructHttpClient() {
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);
    HttpClientParams params = httpClient.getParams();
    params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true);
    if (socketTimeout != null) {
        params.setSoTimeout(socketTimeout);
    }//from   ww w .j a  v a  2s. com
    HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();
    connectionManagerParams.setMaxTotalConnections(maxTotalConnections);
    connectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManagerParams.setConnectionTimeout(connectionTimeout);

    return httpClient;
}

From source file:org.alfresco.rest.api.tests.client.SharedHttpClientProvider.java

public SharedHttpClientProvider(String alfrescoUrl, int maxNumberOfConnections) {
    setAlfrescoUrl(alfrescoUrl);/*w  w w. j av a  2s.  co  m*/

    // Initialize manager
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxTotalConnections(maxNumberOfConnections);
    params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxNumberOfConnections);

    // Create the client
    client = new HttpClient(manager);
    client.getParams().setAuthenticationPreemptive(true);
}

From source file:org.apache.any23.http.DefaultHTTPClient.java

private void ensureClientInitialized() {
    if (configuration == null)
        throw new IllegalStateException("client must be initialized first.");
    if (client != null)
        return;// w w  w  . j a  v a 2 s  .co  m
    client = new HttpClient(manager);
    HttpConnectionManager connectionManager = client.getHttpConnectionManager();
    HttpConnectionManagerParams params = connectionManager.getParams();
    params.setConnectionTimeout(configuration.getDefaultTimeout());
    params.setSoTimeout(configuration.getDefaultTimeout());
    params.setMaxTotalConnections(configuration.getMaxConnections());

    HostConfiguration hostConf = client.getHostConfiguration();
    List<Header> headers = new ArrayList<Header>();
    headers.add(new Header("User-Agent", configuration.getUserAgent()));
    if (configuration.getAcceptHeader() != null) {
        headers.add(new Header("Accept", configuration.getAcceptHeader()));
    }
    headers.add(new Header("Accept-Language", "en-us,en-gb,en,*;q=0.3")); //TODO: this must become parametric.
    headers.add(new Header("Accept-Charset", "utf-8,iso-8859-1;q=0.7,*;q=0.5"));
    // headers.add(new Header("Accept-Encoding", "x-gzip, gzip"));
    hostConf.getParams().setParameter("http.default-headers", headers);
}

From source file:org.apache.hadoop.hbase.rest.client.Client.java

/**
 * Constructor//from ww w  .j a va 2 s  . c  o m
 * @param cluster the cluster definition
 */
public Client(Cluster cluster) {
    this.cluster = cluster;
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams managerParams = manager.getParams();
    managerParams.setConnectionTimeout(2000); // 2 s
    managerParams.setDefaultMaxConnectionsPerHost(10);
    managerParams.setMaxTotalConnections(100);
    extraHeaders = new ConcurrentHashMap<String, String>();
    this.httpClient = new HttpClient(manager);
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setVersion(HttpVersion.HTTP_1_1);
}

From source file:org.apache.hadoop.hbase.stargate.client.Client.java

/**
 * Constructor/*from w ww .  j a v  a2  s . c o m*/
 * @param cluster the cluster definition
 */
public Client(Cluster cluster) {
    this.cluster = cluster;
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams managerParams = manager.getParams();
    managerParams.setConnectionTimeout(2000); // 2 s
    managerParams.setDefaultMaxConnectionsPerHost(10);
    managerParams.setMaxTotalConnections(100);
    this.httpClient = new HttpClient(manager);
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setVersion(HttpVersion.HTTP_1_1);
}

From source file:org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.java

/**
 * Creates a new instance of this repository service.
 *
 * @param uri The server uri./*w ww  . jav  a2  s  .  c o m*/
 * @param idFactory The id factory.
 * @param nameFactory The name factory.
 * @param pathFactory The path factory.
 * @param qValueFactory The value factory.
 * @param itemInfoCacheSize The size of the item info cache.
 * @param maximumHttpConnections A int &gt;0 defining the maximum number of
 * connections per host to be configured on
 * {@link HttpConnectionManagerParams#setDefaultMaxConnectionsPerHost(int)}.
 * @throws RepositoryException If an error occurs.
 */
public RepositoryServiceImpl(String uri, IdFactory idFactory, NameFactory nameFactory, PathFactory pathFactory,
        QValueFactory qValueFactory, int itemInfoCacheSize, int maximumHttpConnections)
        throws RepositoryException {
    if (uri == null || "".equals(uri)) {
        throw new RepositoryException("Invalid repository uri '" + uri + "'.");
    }

    if (idFactory == null || qValueFactory == null) {
        throw new RepositoryException("IdFactory and QValueFactory may not be null.");
    }
    this.idFactory = idFactory;
    this.nameFactory = nameFactory;
    this.pathFactory = pathFactory;
    this.qValueFactory = qValueFactory;
    this.itemInfoCacheSize = itemInfoCacheSize;

    try {
        URI repositoryUri = computeRepositoryUri(uri);
        hostConfig = new HostConfiguration();
        hostConfig.setHost(repositoryUri);

        nsCache = new NamespaceCache();
        uriResolver = new URIResolverImpl(repositoryUri, this, DomUtil.createDocument());
        NamePathResolver resolver = new NamePathResolverImpl(nsCache);
        valueFactory = new ValueFactoryQImpl(qValueFactory, resolver);

    } catch (URIException e) {
        throw new RepositoryException(e);
    } catch (ParserConfigurationException e) {
        throw new RepositoryException(e);
    }

    connectionManager = new MultiThreadedHttpConnectionManager();
    if (maximumHttpConnections > 0) {
        HttpConnectionManagerParams connectionParams = connectionManager.getParams();
        connectionParams.setDefaultMaxConnectionsPerHost(maximumHttpConnections);
        connectionParams.setMaxTotalConnections(maximumHttpConnections);
    }

    // This configuration of the clients cache assumes that the level of
    // concurrency on this map will be equal to the default number of maximum
    // connections allowed on the httpClient level.
    // TODO: review again
    int concurrencyLevel = MAX_CONNECTIONS_DEFAULT;
    int initialCapacity = MAX_CONNECTIONS_DEFAULT;
    if (maximumHttpConnections > 0) {
        concurrencyLevel = maximumHttpConnections;
        initialCapacity = maximumHttpConnections;
    }
    clients = new ConcurrentHashMap<Object, HttpClient>(concurrencyLevel, .75f, initialCapacity);
}