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:org.apache.stratos.integration.common.rest.IntegrationMockClient.java

public IntegrationMockClient(String endpoint) {
    super(endpoint);
    this.endpoint = endpoint;
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    // Increase max total connection to 200
    cm.setMaxTotal(200);
    // Increase default max connection per route to 50
    cm.setDefaultMaxPerRoute(50);/*ww w  .j  a v a2 s . c o m*/

    httpClient = new DefaultHttpClient(cm);
    httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient);
}

From source file:org.apache.stratos.kubernetes.client.rest.RestClient.java

public RestClient() {
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    // Increase max total connection to 200
    cm.setMaxTotal(200);
    // Increase default max connection per route to 50
    cm.setDefaultMaxPerRoute(50);//from   ww  w  .j a v a  2  s .com

    httpClient = new DefaultHttpClient(cm);
}

From source file:com.lonepulse.zombielink.executor.ConfigurationService.java

/**
 * <p>The <i>out-of-the-box</i> configuration for an instance of {@link HttpClient} which will be used 
 * for executing all endpoint requests. Below is a detailed description of all configured properties.</p> 
 * <br>/*from w  w w  .  jav a 2s . c o  m*/
 * <ul>
 * <li>
 * <p><b>HttpClient</b></p>
 * <br>
 * <p>It registers two {@link Scheme}s:</p>
 * <br>
 * <ol>
 *    <li><b>HTTP</b> on port <b>80</b> using sockets from {@link PlainSocketFactory#getSocketFactory}</li>
 *    <li><b>HTTPS</b> on port <b>443</b> using sockets from {@link SSLSocketFactory#getSocketFactory}</li>
 * </ol>
 * 
 * <p>It uses a {@link PoolingClientConnectionManager} with the maximum number of client connections 
 * per route set to <b>4</b> and the total set to <b>128</b>.</p>
 * </li>
 * </ul>
 * @return the instance of {@link HttpClient} which will be used for request execution
 * <br><br>
 * @since 1.3.0
 */
@Override
public Configuration getDefault() {

    return new Configuration() {

        @Override
        public HttpClient httpClient() {

            try {

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

                PoolingClientConnectionManager pccm = new PoolingClientConnectionManager(schemeRegistry);
                pccm.setMaxTotal(200);
                pccm.setDefaultMaxPerRoute(20);

                return new DefaultHttpClient(pccm);
            } catch (Exception e) {

                throw new ConfigurationFailedException(e);
            }
        }
    };
}

From source file:com.impetus.kundera.ycsb.utils.CouchDBOperationUtils.java

public HttpClient initiateClient(String host, int port) {
    if (httpClient == null || httpHost == null) {
        SchemeSocketFactory ssf = null;//  w ww. j  av  a2  s .  c om
        ssf = PlainSocketFactory.getSocketFactory();
        SchemeRegistry schemeRegistry = new SchemeRegistry();

        schemeRegistry.register(new Scheme("http", port, ssf));
        PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry);

        ccm.setMaxTotal(100);
        //            ccm.setDefaultMaxPerRoute(50);

        httpClient = new DefaultHttpClient(ccm);
        httpHost = new HttpHost(host, port);

        try {
            // Http params
            httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

            // request interceptor
            ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor() {
                public void process(final HttpRequest request, final HttpContext context) throws IOException {

                }
            });
            // response interceptor
            ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor() {
                public void process(final HttpResponse response, final HttpContext context) throws IOException {

                }
            });
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    return httpClient;
}

From source file:de.drv.dsrv.spoc.web.service.impl.FachverfahrenRequestServiceImpl.java

/**
 * Konstruktor.//from  w  w  w.  j  a v  a  2s . c  o m
 * 
 * @param maxConnections
 *            die maximale Anzahl von gleichzeitigen HTTP-Verbindungen, die
 *            vom Service insgesamt zu Fachverfahren aufgebaut werden; wenn
 *            die Grenze erreicht wird, werden weitere Verbindungen
 *            geblockt, bis eine Connection frei wird
 * @param maxConnectionsPerRoute
 *            die maximale Anzahl von gleichzeitigen HTTP-Verbindungen, die
 *            vom Service zu einer bestimmten Route (entspricht einem
 *            Server) aufgebaut werden; wenn die Grenze erreicht wird,
 *            werden weitere Verbindungen geblockt, bis eine Connection frei
 *            wird
 * @param soapFaultString
 *            Text des SOAP-Fehlers
 * @param responseHandler
 *            Handler zur Verarbeitung der Antworten des Fachverfahrens
 * @param extraJaxbMarshaller
 *            JAXB-Marshaller
 * @param spocNutzdatenManager
 *            Manager zum ZUgriff auf die Nutzerdaten
 * 
 * @throws IllegalArgumentException
 *             wenn <code>maxConnections</code> oder
 *             <code>maxConnectionsPerRoute</code> kleiner als 0 sind
 */
public FachverfahrenRequestServiceImpl(final int maxConnections, final int maxConnectionsPerRoute,
        final String soapFaultString, final SpocResponseHandler responseHandler,
        final ExtraJaxbMarshaller extraJaxbMarshaller, final SpocNutzdatenManager spocNutzdatenManager) {
    this.soapFaultString = soapFaultString;
    final PoolingClientConnectionManager conman = new PoolingClientConnectionManager();
    conman.setMaxTotal(maxConnections);
    conman.setDefaultMaxPerRoute(maxConnectionsPerRoute);
    this.httpClient = new DefaultHttpClient(conman);
    this.httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8.name());
    this.responseHandler = responseHandler;
    this.extraJaxbMarshaller = extraJaxbMarshaller;
    this.spocNutzdatenManager = spocNutzdatenManager;
}

From source file:org.openrepose.core.services.httpclient.impl.ClientDecommissioner.java

public void addClientToBeDecommissioned(HttpClient client) {

    synchronized (listLock) {
        PoolingClientConnectionManager connMan = (PoolingClientConnectionManager) client.getConnectionManager();
        connMan.closeExpiredConnections();
        connMan.setMaxTotal(1);
        connMan.setDefaultMaxPerRoute(1);
        clientList.add(client);//from w ww .j av  a 2  s  .c  om
    }
}

From source file:com.lushapp.common.web.servlet.RemoteContentServlet.java

/**
 * HttpClient.//w ww .  j av a  2s .c  o  m
 */
@Override
public void init() throws ServletException {
    // Set connection pool
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setMaxTotal(CONNECTION_POOL_SIZE);
    httpClient = new DefaultHttpClient(cm);

    // set timeout
    HttpParams httpParams = httpClient.getParams();
    HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_SECONDS * 1000);
}

From source file:com.proofpoint.http.client.ApacheHttpClient.java

public ApacheHttpClient(HttpClientConfig config, Set<? extends HttpRequestFilter> requestFilters) {
    Preconditions.checkNotNull(config, "config is null");
    Preconditions.checkNotNull(requestFilters, "requestFilters is null");

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(config.getMaxConnections());
    connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsPerServer());

    BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT,
            Ints.checkedCast(config.getReadTimeout().toMillis()));
    httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
            Ints.checkedCast(config.getConnectTimeout().toMillis()));
    httpParams.setParameter(CoreConnectionPNames.SO_LINGER, 0); // do we need this?

    DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, httpParams);
    defaultHttpClient.setKeepAliveStrategy(new FixedIntervalKeepAliveStrategy(config.getKeepAliveInterval()));
    defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    this.httpClient = defaultHttpClient;

    this.requestFilters = ImmutableList.copyOf(requestFilters);
}

From source file:org.greencheek.spring.rest.SSLCachingHttpComponentsClientHttpRequestFactory.java

/**
 * Create a new instance of the HttpComponentsClientHttpRequestFactory with a default
 * {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
 *///  w ww  .j  a va  2 s  .c  o  m
public SSLCachingHttpComponentsClientHttpRequestFactory(boolean useSSLCaching) {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSystemSocketFactory()));

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);

    this.httpClient = new DefaultHttpClient(connectionManager);
    ((DefaultHttpClient) this.httpClient).removeRequestInterceptorByClass(RequestDefaultHeaders.class);

    setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);
    setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
    this.useSSLCaching = useSSLCaching;
    setTcpNoDelay(DEFAULT_TCP_NO_DELAY);
}

From source file:com.jillesvangurp.httpclientfuture.HttpClientWithFutureTest.java

@BeforeClass
public void beforeClass() {
    webServerExecutor = Executors.newSingleThreadExecutor();
    webServer = new WebServer();
    webServerExecutor.execute(webServer);
    clientThreadPool = Executors.newFixedThreadPool(threads);
    PoolingClientConnectionManager conman = new PoolingClientConnectionManager();
    conman.setDefaultMaxPerRoute(threads);
    conman.setMaxTotal(threads);
    DefaultHttpClient httpclient = new DefaultHttpClient(conman);
    client = new HttpClientWithFuture<Boolean>(httpclient, clientThreadPool, new ResponseHandler<Boolean>() {
        @Override/*w  ww  .j  a  v  a  2  s . co  m*/
        public Boolean handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            return response.getStatusLine().getStatusCode() == 200;
        }
    });
}