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

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

Introduction

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

Prototype

public void setMaxTotal(final int max) 

Source Link

Usage

From source file:com.arpnetworking.metrics.impl.ApacheHttpSink.java

ApacheHttpSink(final Builder builder, final Logger logger) {
    this(builder, new SingletonSupplier<>(() -> {
        final SingletonSupplier<PoolingHttpClientConnectionManager> clientManagerSupplier = new SingletonSupplier<>(
                () -> {/*from   ww w  .  j a  va2s .c om*/
                    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
                    connectionManager.setDefaultMaxPerRoute(builder._parallelism);
                    connectionManager.setMaxTotal(builder._parallelism);
                    return connectionManager;
                });

        return HttpClients.custom().setConnectionManager(clientManagerSupplier.get()).build();
    }), logger);
}

From source file:com.baidubce.http.BceHttpClient.java

/**
 * Create connection manager for http client.
 *
 * @return The connection manager for http client.
 *//*from  w  ww . ja va  2  s . c  o m*/
private HttpClientConnectionManager createHttpClientConnectionManager() {
    ConnectionSocketFactory socketFactory = PlainConnectionSocketFactory.getSocketFactory();
    LayeredConnectionSocketFactory sslSocketFactory;
    try {
        sslSocketFactory = new SSLConnectionSocketFactory(SSLContext.getDefault(),
                SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER);
    } catch (NoSuchAlgorithmException e) {
        throw new BceClientException("Fail to create SSLConnectionSocketFactory", e);
    }
    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register(Protocol.HTTP.toString(), socketFactory)
            .register(Protocol.HTTPS.toString(), sslSocketFactory).build();
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
    connectionManager.setDefaultMaxPerRoute(this.config.getMaxConnections());
    connectionManager.setDefaultSocketConfig(SocketConfig.custom()
            .setSoTimeout(this.config.getSocketTimeoutInMillis()).setTcpNoDelay(true).build());
    connectionManager.setMaxTotal(this.config.getMaxConnections());
    return connectionManager;
}

From source file:org.apache.zeppelin.sap.universe.UniverseClient.java

public UniverseClient(String user, String password, String apiUrl, String authType, int queryTimeout) {
    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(queryTimeout)
            .setSocketTimeout(queryTimeout).build();
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(100);
    cm.setDefaultMaxPerRoute(100);//  w  w  w.j ava  2s.  c o m
    cm.closeIdleConnections(10, TimeUnit.MINUTES);
    httpClient = HttpClientBuilder.create().setConnectionManager(cm).setDefaultRequestConfig(requestConfig)
            .build();

    this.user = user;
    this.password = password;
    this.authType = authType;
    if (StringUtils.isNotBlank(apiUrl)) {
        this.apiUrl = apiUrl.replaceAll("/$", "");
    }
}

From source file:com.liferay.jsonwebserviceclient.JSONWebServiceClientImpl.java

protected PoolingHttpClientConnectionManager getPoolingHttpClientConnectionManager() {

    PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = null;

    if (_keyStore != null) {
        poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(getSocketFactoryRegistry(),
                null, null, null, 60000, TimeUnit.MILLISECONDS);
    } else {/*from  w ww .ja  v  a 2 s.  c o  m*/
        poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(60000,
                TimeUnit.MILLISECONDS);
    }

    poolingHttpClientConnectionManager.setMaxTotal(20);

    return poolingHttpClientConnectionManager;
}

From source file:com.joyent.manta.http.MantaConnectionFactory.java

/**
 * Configures a connection manager with all of the setting needed to connect
 * to Manta.//from www.  j a va 2s  .co m
 *
 * @param metricConfig potentially-null configuration for tracking client metrics
 * @return fully configured connection manager
 */
protected HttpClientConnectionManager buildConnectionManager(
        final MantaClientMetricConfiguration metricConfig) {
    final int maxConns = ObjectUtils.firstNonNull(config.getMaximumConnections(),
            DefaultsConfigContext.DEFAULT_MAX_CONNS);

    final ConnectionSocketFactory sslConnectionSocketFactory = new MantaSSLConnectionSocketFactory(this.config);

    final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();

    final Registry<ConnectionSocketFactory> socketFactoryRegistry = registryBuilder
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", sslConnectionSocketFactory).build();

    final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = buildHttpConnectionFactory();

    final PoolingHttpClientConnectionManager connManager;
    if (metricConfig != null) {
        connManager = new InstrumentedPoolingHttpClientConnectionManager(metricConfig.getRegistry(),
                socketFactoryRegistry, connFactory, null, DNS_RESOLVER, -1, TimeUnit.MILLISECONDS);
    } else {
        connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, connFactory, DNS_RESOLVER);
    }

    connManager.setDefaultMaxPerRoute(maxConns);
    connManager.setMaxTotal(maxConns);
    connManager.setDefaultSocketConfig(buildSocketConfig());
    connManager.setDefaultConnectionConfig(buildConnectionConfig());

    return connManager;
}

From source file:org.iipg.hurricane.jmx.client.JMXClientBuilder.java

private PoolingHttpClientConnectionManager createPoolingConnectionManager() {
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(
            getSocketFactoryRegistry(), getConnectionFactory());
    connManager.setDefaultSocketConfig(createSocketConfig());
    connManager.setDefaultConnectionConfig(createConnectionConfig());
    if (maxTotalConnections != 0) {
        connManager.setMaxTotal(maxTotalConnections);
    }// w w w . j  a va 2 s  . c  om
    return connManager;
}

From source file:eu.europa.esig.dss.client.http.commons.CommonsDataLoader.java

private HttpClientConnectionManager getConnectionManager() throws DSSException {

    RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistryBuilder = RegistryBuilder.create();
    socketFactoryRegistryBuilder = setConnectionManagerSchemeHttp(socketFactoryRegistryBuilder);
    socketFactoryRegistryBuilder = setConnectionManagerSchemeHttps(socketFactoryRegistryBuilder);

    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(
            socketFactoryRegistryBuilder.build());

    connectionManager.setMaxTotal(getConnectionsMaxTotal());
    connectionManager.setDefaultMaxPerRoute(getConnectionsMaxPerRoute());

    LOG.debug("PoolingHttpClientConnectionManager: max total: " + connectionManager.getMaxTotal());
    LOG.debug(
            "PoolingHttpClientConnectionManager: max per route: " + connectionManager.getDefaultMaxPerRoute());

    return connectionManager;
}

From source file:microsoft.exchange.webservices.data.core.ExchangeServiceBase.java

private void initializeHttpPoolingClient() {
    Registry<ConnectionSocketFactory> registry = createConnectionSocketFactoryRegistry();
    PoolingHttpClientConnectionManager httpConnectionManager = new PoolingHttpClientConnectionManager(registry);
    httpConnectionManager.setMaxTotal(maximumPoolingConnections);
    httpConnectionManager.setDefaultMaxPerRoute(maximumPoolingConnections);
    AuthenticationStrategy authStrategy = new CookieProcessingTargetAuthenticationStrategy();

    httpPoolingClient = HttpClients.custom().setConnectionManager(httpConnectionManager)
            .setTargetAuthenticationStrategy(authStrategy).build();
}

From source file:org.kuali.rice.ksb.messaging.serviceconnectors.DefaultHttpClientConfigurer.java

/**
 * Builds the HttpClientConnectionManager.
 *
 * <p>Note that this calls {@link #buildSslConnectionSocketFactory()} and registers the resulting {@link SSLConnectionSocketFactory}
 * (if non-null) with its socket factory registry.</p>
 *
 * @return the HttpClientConnectionManager
 *//*w  w  w.j  a  v  a  2s .  c o m*/
protected HttpClientConnectionManager buildConnectionManager() {
    PoolingHttpClientConnectionManager poolingConnectionManager = null;

    SSLConnectionSocketFactory sslConnectionSocketFactory = buildSslConnectionSocketFactory();
    if (sslConnectionSocketFactory != null) {
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                .<ConnectionSocketFactory>create().register("https", sslConnectionSocketFactory)
                .register("http", new PlainConnectionSocketFactory()).build();
        poolingConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    } else {
        poolingConnectionManager = new PoolingHttpClientConnectionManager();
    }

    // Configure the connection manager
    poolingConnectionManager
            .setMaxTotal(MAX_TOTAL_CONNECTIONS.getValueOrDefault(DEFAULT_MAX_TOTAL_CONNECTIONS));

    // By default we'll set the max connections per route (essentially that means per host for us) to the max total
    poolingConnectionManager
            .setDefaultMaxPerRoute(MAX_TOTAL_CONNECTIONS.getValueOrDefault(DEFAULT_MAX_TOTAL_CONNECTIONS));

    SocketConfig.Builder socketConfigBuilder = SocketConfig.custom();
    socketConfigBuilder.setSoTimeout(SO_TIMEOUT.getValueOrDefault(DEFAULT_SOCKET_TIMEOUT));

    Integer soLinger = SO_LINGER.getValue();
    if (soLinger != null) {
        socketConfigBuilder.setSoLinger(soLinger);
    }

    Boolean isTcpNoDelay = TCP_NODELAY.getValue();
    if (isTcpNoDelay != null) {
        socketConfigBuilder.setTcpNoDelay(isTcpNoDelay);
    }

    poolingConnectionManager.setDefaultSocketConfig(socketConfigBuilder.build());

    ConnectionConfig.Builder connectionConfigBuilder = ConnectionConfig.custom();

    Integer sendBuffer = SO_SNDBUF.getValue();
    Integer receiveBuffer = SO_RCVBUF.getValue();

    // if either send or recieve buffer size is set, we'll set the buffer size to whichever is greater
    if (sendBuffer != null || receiveBuffer != null) {
        Integer bufferSize = -1;
        if (sendBuffer != null) {
            bufferSize = sendBuffer;
        }

        if (receiveBuffer != null && receiveBuffer > bufferSize) {
            bufferSize = receiveBuffer;
        }

        connectionConfigBuilder.setBufferSize(bufferSize);
    }

    String contentCharset = HTTP_CONTENT_CHARSET.getValue();
    if (contentCharset != null) {
        connectionConfigBuilder.setCharset(Charset.forName(contentCharset));
    }

    poolingConnectionManager.setDefaultConnectionConfig(connectionConfigBuilder.build());

    return poolingConnectionManager;
}