public ConnPerRouteBean(int defaultMax) { super(); this.maxPerHostMap = new HashMap<HttpRoute, Integer>(); setDefaultMaxPerRoute(defaultMax); }
/** * Creates a new route-specific pool. * Called by {@link #getRoutePool} when necessary. * * @param route the route * * @return the new pool */ protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) { return new RouteSpecificPool(route, connPerRoute.getMaxForRoute(route)); }
/** * Adjust the connection timeout, i.e. the amount of time that may pass in order to establish a * connection with the server. Time unit is milliseconds. * * @param connectionTimeout * the timeout in milliseconds * @see CoreConnectionPNames#CONNECTION_TIMEOUT */ public void setConnectionTimeout(int connectionTimeout) { ConnManagerParams.setTimeout(httpClient.getParams(), connectionTimeout); }
public static ThreadSafeClientConnManager createThreadSafeClientConnManager( ClientConfiguration config, HttpParams httpClientParams) { ConnManagerParams.setMaxConnectionsPerRoute(httpClientParams, new ConnPerRouteBean(config.getMaxConnections())); ConnManagerParams.setMaxTotalConnections(httpClientParams, config.getMaxConnections()); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), DEFAULT_HTTP_PORT)); registry.register(new Scheme("https", sslSocketFactory, DEFAULT_HTTPS_PORT)); ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager( httpClientParams, registry); if (config.useReaper()) { IdleConnectionReaper.registerConnectionManager(connectionManager); } return connectionManager; } }
protected void setupHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean( DEFAULT_MAX_CONNECTIONS)); ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, DEFAULT_HTTP_USER_AGENT); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) { schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } else { // used to work around a bug in Android 1.6: // http://code.google.com/p/android/issues/detail?id=1946 // TODO: is there a less rigorous workaround for this? schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); } ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpClient = new DefaultHttpClient(cm, httpParams); }
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(25));
SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // https scheme schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
public void setMaximumConnections(int maxConnections) { ConnManagerParams.setMaxTotalConnections(httpClient.getParams(), maxConnections); }
ConnRouteParams.getForcedRoute(request.getParams()); if (route != null) return route; ConnRouteParams.getLocalAddress(request.getParams()); final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams());
/** * Creates a new connection pool, managed by route. */ public ConnPoolByRoute(final ClientConnectionOperator operator, final HttpParams params) { super(); if (operator == null) { throw new IllegalArgumentException("Connection operator may not be null"); } this.operator = operator; freeConnections = createFreeConnQueue(); waitingThreads = createWaitingThreadQueue(); routeToPool = createRouteToPoolMap(); maxTotalConnections = ConnManagerParams .getMaxTotalConnections(params); connPerRoute = ConnManagerParams .getMaxConnectionsPerRoute(params); }
ConnRouteParams.getForcedRoute(request.getParams()); if (route != null) return route; ConnRouteParams.getLocalAddress(request.getParams());
long timeout = ConnManagerParams.getTimeout(params);
ConnRouteParams.setDefaultProxy(httpClient.getParams(), proxyHost);
/** * @since 4.1 */ public int getMaxForRoute(final HttpRoute route) { return connPerRoute.getMaxForRoute(route); }
/** * @since 4.1 */ public void setMaxForRoute(final HttpRoute route, final int max) { connPerRoute.setMaxForRoute(route, max); }
ConnRouteParams.setLocalAddress(httpClientParams, config.getLocalAddress());
ConnManagerParams.setMaxTotalConnections(params, 1000); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1000));
ConnPerRoute connPerRoute = new ConnPerRouteBean(12); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); ConnManagerParams.setMaxTotalConnections(params, 20);
long timeout = ConnManagerParams.getTimeout(params);
params.setParameter(org.apache.http.conn.params.ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new org.apache.http.conn.params.ConnPerRouteBean(30)); params.setParameter(org.apache.http.params.CoreProtocolPNames.USE_EXPECT_CONTINUE, false); params.setParameter(org.apache.http.params.CoreProtocolPNames.USER_AGENT, "AnkiDroid-" + VersionUtils.getPkgVersionName());