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

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

Introduction

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

Prototype

public void setDefaultMaxPerRoute(final int max) 

Source Link

Usage

From source file:org.bungeni.ext.integration.bungeniportal.BungeniAppConnector.java

/**
 * Thread safe client ,since we access the same client across threads
 * @return //w  w  w.j a v  a  2s  .com
 */
public DefaultHttpClient getThreadSafeClient() {
    PoolingClientConnectionManager cxMgr = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createDefault());
    cxMgr.setMaxTotal(100);
    cxMgr.setDefaultMaxPerRoute(20);

    DefaultHttpClient aClient = new DefaultHttpClient();
    HttpParams params = aClient.getParams();
    return new DefaultHttpClient(cxMgr, params);
}

From source file:com.flipkart.poseidon.handlers.http.impl.HttpConnectionPool.java

/** Constructor
 * @param host Host Name/*from  w ww  . jav a  2s . c  o  m*/
 * @param port Port Name
 * @param secure
 * @param connectionTimeout
 * @param operationTimeout
 * @param maxConnections
 * @param processQueueSize
 * @param timeToLiveInSecs
 */
protected HttpConnectionPool(final String name, String host, Integer port, Boolean secure,
        Integer connectionTimeout, Integer operationTimeout, Integer maxConnections, Integer processQueueSize,
        Integer timeToLiveInSecs) {
    this.name = name;
    this.host = host;
    this.port = port;
    this.secure = secure;
    this.headers = new HashMap<String, String>();
    this.processQueue = new Semaphore(processQueueSize + maxConnections);
    if (timeToLiveInSecs != null) {
        this.timeToLiveInSecs = timeToLiveInSecs;
    }
    this.requestGzipEnabled = false;
    this.responseGzipEnabled = false;

    // create scheme
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    if (this.secure) {
        schemeRegistry.register(new Scheme("https", port, SSLSocketFactory.getSocketFactory()));
    } else {
        schemeRegistry.register(new Scheme("http", port, PlainSocketFactory.getSocketFactory()));
    }

    // create connection manager
    PoolingClientConnectionManager cm;
    if (this.timeToLiveInSecs > 0) {
        cm = new PoolingClientConnectionManager(schemeRegistry, this.timeToLiveInSecs, TimeUnit.SECONDS);
    } else {
        cm = new PoolingClientConnectionManager(schemeRegistry);
    }

    // Max pool size
    cm.setMaxTotal(maxConnections);

    // Increase default max connection per route to 20
    cm.setDefaultMaxPerRoute(maxConnections);

    // Increase max connections for host:port
    HttpHost httpHost = new HttpHost(host, port);
    cm.setMaxPerRoute(new HttpRoute(httpHost), maxConnections);

    // set timeouts
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(httpParams, operationTimeout);

    // create client pool
    this.client = new DefaultHttpClient(cm, httpParams);

    // policies (cookie)
    this.client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);

    // adding gzip support for http client
    addGzipHeaderInRequestResponse();

}

From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql.java

/**
 * Returns an RDFService for a remote repository 
 * @param String - URI of the read SPARQL endpoint for the knowledge base
 * @param String - URI of the update SPARQL endpoint for the knowledge base
 * @param String - URI of the default write graph within the knowledge base.
 *                   this is the graph that will be written to when a graph
 *                   is not explicitly specified.
 * //from   w  w w  .j a  v  a 2 s  .c o  m
 * The default read graph is the union of all graphs in the
 * knowledge base
 */
public RDFServiceSparql(String readEndpointURI, String updateEndpointURI, String defaultWriteGraphURI) {
    this.readEndpointURI = readEndpointURI;
    this.updateEndpointURI = updateEndpointURI;

    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setDefaultMaxPerRoute(50);
    this.httpClient = new DefaultHttpClient(cm);

    testConnection();
}

From source file:com.centurylink.cloud.sdk.core.client.SdkClientBuilder.java

private ClientConnectionManager initClientConnectionManager(SchemeRegistry registry) {
    ClientConnectionManager cm;/*from  w  ww  . j a  v a  2  s . co  m*/
    if (connectionPoolSize > 0) {
        PoolingClientConnectionManager tcm = new PoolingClientConnectionManager(registry, connectionTTL,
                connectionTTLUnit);
        tcm.setMaxTotal(connectionPoolSize);
        if (maxPooledPerRoute == 0) {
            maxPooledPerRoute = connectionPoolSize;
        }
        tcm.setDefaultMaxPerRoute(maxPooledPerRoute);
        cm = tcm;

    } else {
        cm = new BasicClientConnectionManager(registry);
    }

    return cm;
}

From source file:com.impetus.client.couchdb.CouchDBClientFactory.java

@Override
protected Object createPoolOrConnection() {
    PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata()
            .getPersistenceUnitMetadata(getPersistenceUnit());

    Properties props = puMetadata.getProperties();
    String contactNode = null;//from  w  w w.  j a v a2  s  .c o  m
    String defaultPort = null;
    String keyspace = null;
    String poolSize = null;
    String userName = null;
    String password = null;
    String maxConnections = null;
    if (externalProperties != null) {
        contactNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES);
        defaultPort = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT);
        keyspace = (String) externalProperties.get(PersistenceProperties.KUNDERA_KEYSPACE);
        poolSize = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE);
        userName = (String) externalProperties.get(PersistenceProperties.KUNDERA_USERNAME);
        password = (String) externalProperties.get(PersistenceProperties.KUNDERA_PASSWORD);
        maxConnections = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_TOTAL);
    }
    if (contactNode == null) {
        contactNode = (String) props.get(PersistenceProperties.KUNDERA_NODES);
    }
    if (defaultPort == null) {
        defaultPort = (String) props.get(PersistenceProperties.KUNDERA_PORT);
    }
    if (keyspace == null) {
        keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE);
    }
    if (poolSize == null) {
        poolSize = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE);
    }
    if (userName == null) {
        userName = props.getProperty(PersistenceProperties.KUNDERA_USERNAME);
        password = props.getProperty(PersistenceProperties.KUNDERA_PASSWORD);
    }

    onValidation(contactNode, defaultPort);
    try {
        SchemeSocketFactory ssf = null;
        ssf = PlainSocketFactory.getSocketFactory();
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme(CouchDBConstants.PROTOCOL, Integer.parseInt(defaultPort), ssf));
        PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry);
        httpClient = new DefaultHttpClient(ccm);
        httpHost = new HttpHost(contactNode, Integer.parseInt(defaultPort), CouchDBConstants.PROTOCOL);
        httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
        // httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
        // props.getSocketTimeout());

        // httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
        // props.getConnectionTimeout());
        if (!StringUtils.isBlank(maxConnections)) {
            ccm.setMaxTotal(Integer.parseInt(maxConnections));
            ccm.setDefaultMaxPerRoute(Integer.parseInt(maxConnections));
        }
        // basic authentication
        if (userName != null && password != null) {
            ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(
                    new AuthScope(contactNode, Integer.parseInt(defaultPort)),
                    new UsernamePasswordCredentials(userName, password));
        }
        // request interceptor
        ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor() {
            public void process(final HttpRequest request, final HttpContext context) throws IOException {
                if (logger.isInfoEnabled()) {
                    RequestLine requestLine = request.getRequestLine();
                    logger.info(
                            ">> " + requestLine.getMethod() + " " + URI.create(requestLine.getUri()).getPath());
                }
            }
        });
        // response interceptor
        ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor() {
            public void process(final HttpResponse response, final HttpContext context) throws IOException {
                if (logger.isInfoEnabled())
                    logger.info("<< Status: " + response.getStatusLine().getStatusCode());
            }
        });
    } catch (Exception e) {
        logger.error("Error Creating HTTP client, caoused by {}. ", e);
        throw new IllegalStateException(e);
    }
    return httpClient;
}

From source file:com.amazonservices.mws.client.MwsConnection.java

/**
 * Get a connection manager to use for this connection.
 * <p>/* www  . j  a  v  a 2  s .c om*/
 * Called late in initialization.
 * <p>
 * Default implementation uses a shared PoolingClientConnectionManager.
 * 
 * @return The connection manager to use.
 */
private ClientConnectionManager getConnectionManager() {
    synchronized (this.getClass()) {
        if (sharedCM == null) {
            PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
            cm.setMaxTotal(maxConnections);
            cm.setDefaultMaxPerRoute(maxConnections);
            sharedCM = cm;
        }
        return sharedCM;
    }
}