Example usage for org.apache.http.conn.params ConnPerRouteBean DEFAULT_MAX_CONNECTIONS_PER_ROUTE

List of usage examples for org.apache.http.conn.params ConnPerRouteBean DEFAULT_MAX_CONNECTIONS_PER_ROUTE

Introduction

In this page you can find the example usage for org.apache.http.conn.params ConnPerRouteBean DEFAULT_MAX_CONNECTIONS_PER_ROUTE.

Prototype

int DEFAULT_MAX_CONNECTIONS_PER_ROUTE

To view the source code for org.apache.http.conn.params ConnPerRouteBean DEFAULT_MAX_CONNECTIONS_PER_ROUTE.

Click Source Link

Document

The default maximum number of connections allowed per host

Usage

From source file:com.soundcloud.playerapi.ApiWrapper.java

/**
 * @return the default HttpParams//from ww  w. j av  a 2  s  .c  o  m
 * @see <a href="http://developer.android.com/reference/android/net/http/AndroidHttpClient.html#newInstance(java.lang.String, android.content.Context)">
 *      android.net.http.AndroidHttpClient#newInstance(String, Context)</a>
 */
protected HttpParams getParams() {
    final HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, BUFFER_SIZE);
    ConnManagerParams.setMaxTotalConnections(params, MAX_TOTAL_CONNECTIONS);

    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // fix contributed by Bjorn Roche XXX check if still needed
    params.setBooleanParameter("http.protocol.expect-continue", false);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRoute() {
        @Override
        public int getMaxForRoute(HttpRoute httpRoute) {
            if (env.isApiHost(httpRoute.getTargetHost())) {
                // there will be a lot of concurrent request to the API host
                return MAX_TOTAL_CONNECTIONS;
            } else {
                return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
            }
        }
    });
    // apply system proxy settings
    final String proxyHost = System.getProperty("http.proxyHost");
    final String proxyPort = System.getProperty("http.proxyPort");
    if (proxyHost != null) {
        int port = 80;
        try {
            port = Integer.parseInt(proxyPort);
        } catch (NumberFormatException ignored) {
        }
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port));
    }
    return params;
}