Example usage for org.apache.http.impl.conn PoolingClientConnectionManager setMaxTotal

List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager setMaxTotal

Introduction

In this page you can find the example usage for org.apache.http.impl.conn PoolingClientConnectionManager setMaxTotal.

Prototype

public void setMaxTotal(final int max) 

Source Link

Usage

From source file:com.ah.be.common.PresenceUtil.java

public static HttpClient getHttpClientInstance(int maxConnections) {
    try {/*from  w w  w .ja  v  a  2 s .c o  m*/
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(null, new TrustManager[] { new ClientTrustManager() }, null);
        SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
        schemeRegistry.register(new Scheme("https", 443, ssf));
        PoolingClientConnectionManager connMgr = new PoolingClientConnectionManager(schemeRegistry);
        connMgr.setMaxTotal(maxConnections);
        connMgr.setDefaultMaxPerRoute(maxConnections);

        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, SOCKET_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
        HttpClient httpClient = new DefaultHttpClient(connMgr, params);
        return httpClient;
    } catch (Exception e) {
        log.error("getHttpClientInstance error.", e);
        return null;
    }
}

From source file:net.yacy.cora.federate.solr.instance.RemoteInstance.java

/**
 * Initialize the maximum connections for the given pool
 * //  w  ww .ja  v a2s.  c  o  m
 * @param pool
 *            a pooling connection manager. Must not be null.
 * @param maxConnections.
 *            The new maximum connections values. Must be greater than 0.
 * @throws IllegalArgumentException
 *             when pool is null or when maxConnections is lower than 1
 */
public static void initPoolMaxConnections(final org.apache.http.impl.conn.PoolingClientConnectionManager pool,
        int maxConnections) {
    if (pool == null) {
        throw new IllegalArgumentException("pool parameter must not be null");
    }
    if (maxConnections <= 0) {
        throw new IllegalArgumentException("maxConnections parameter must be greater than zero");
    }
    pool.setMaxTotal(maxConnections);

    /* max connections per host */
    pool.setDefaultMaxPerRoute((int) (2 * Memory.cores()));
}

From source file:com.microsoft.applicationinsights.internal.channel.common.ApacheSender42.java

public ApacheSender42() {
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
    cm.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);

    httpClient = new DefaultHttpClient(cm);

    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, REQUEST_TIMEOUT_IN_MILLIS);
    HttpConnectionParams.setSoTimeout(params, REQUEST_TIMEOUT_IN_MILLIS);

    InternalLogger.INSTANCE.info("Using Apache HttpClient 4.2");
}

From source file:at.ac.tuwien.big.testsuite.impl.util.HttpClientProducer.java

@Produces
@ApplicationScoped/* w  w  w.j  a  v a2s.co m*/
HttpClient produceHttpClient() {
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setMaxTotal(100);
    cm.setDefaultMaxPerRoute(20);
    DefaultHttpClient client = new DefaultHttpClient(cm);

    client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
        @Override
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            if (executionCount >= MAX_RETRY_COUNT) {
                // Do not retry if over max retry count
                return false;
            }
            if (exception instanceof InterruptedIOException) {
                // Timeout
                return true;
            }
            if (exception instanceof UnknownHostException) {
                // Unknown host
                return true;
            }
            if (exception instanceof ConnectException) {
                // Connection refused
                return true;
            }
            if (exception instanceof SSLException) {
                // SSL handshake exception
                return true;
            }
            HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
            boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
            if (idempotent) {
                // Retry if the request is considered idempotent 
                return true;
            }
            return false;
        }
    });

    return new DecompressingHttpClient(client);
}

From source file:org.sonatype.nexus.test.utils.hc4client.Hc4ClientHelper.java

@Override
public void start() throws Exception {
    super.start();

    HttpParams params = new SyncBasicHttpParams();
    params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024);
    params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, getConnectTimeout());
    params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, getReadTimeout());
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
    final PoolingClientConnectionManager connManager = new PoolingClientConnectionManager();
    connManager.setMaxTotal(getMaxTotalConnections());
    connManager.setDefaultMaxPerRoute(getMaxConnectionsPerHost());
    httpClient = new DefaultHttpClient(connManager, params);
    getLogger().info("Starting the HTTP client");
}

From source file:guru.nidi.languager.check.LinkChecker.java

public LinkChecker(File file, List<MessageLine> contents, Logger logger) {
    this.file = file;
    this.contents = contents;
    this.logger = logger;

    final PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setMaxTotal(20);
    this.client = new DefaultHttpClient(cm);
}

From source file:com.rackspacecloud.blueflood.http.HttpClientVendor.java

private ClientConnectionManager buildConnectionManager(int concurrency) {
    final PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setDefaultMaxPerRoute(concurrency);
    connectionManager.setMaxTotal(concurrency);
    return connectionManager;
}

From source file:uk.co.visalia.brightpearl.apiclient.http.httpclient4.HttpClient4ClientFactory.java

private void createClient() {
    BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeoutMs);
    httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeoutMs);
    HttpClientParams.setRedirecting(httpParams, allowRedirects);
    HttpClientParams.setConnectionManagerTimeout(httpParams, connectionManagerTimeoutMs);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(maxConnections);
    connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);

    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, httpParams);

    this.client = new HttpClient4Client(httpClient);
}

From source file:org.n52.oxf.util.web.PoolingConnectionManagerHttpClient.java

@Override
public ClientConnectionManager getConnectionManager() {
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    // Increase max total connection to 200
    cm.setMaxTotal(200);
    // Increase default max connection per route to 20
    cm.setDefaultMaxPerRoute(20);//from   www  .  j ava 2 s  .com
    // Increase max connections for localhost:80 to 50
    HttpHost localhost8080 = new HttpHost("localhost", 8080);
    cm.setMaxPerRoute(new HttpRoute(localhost8080), 50);
    HttpHost localhost = new HttpHost("localhost", 80);
    cm.setMaxPerRoute(new HttpRoute(localhost), 50);

    return cm;
}

From source file:uk.ac.ebi.intact.task.mitab.index.OntologyEnricherItemProcessor.java

private HttpClient createHttpClient() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    cm.setMaxTotal(maxTotalConnections);
    cm.setDefaultMaxPerRoute(defaultMaxConnectionsPerHost);

    HttpClient httpClient = new DefaultHttpClient(cm);

    return httpClient;
}