1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/conn/params/ConnManagerParams.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,180 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * 1.7 + * Licensed to the Apache Software Foundation (ASF) under one or more 1.8 + * contributor license agreements. See the NOTICE file distributed with 1.9 + * this work for additional information regarding copyright ownership. 1.10 + * The ASF licenses this file to You under the Apache License, Version 2.0 1.11 + * (the "License"); you may not use this file except in compliance with 1.12 + * the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, software 1.17 + * distributed under the License is distributed on an "AS IS" BASIS, 1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.19 + * See the License for the specific language governing permissions and 1.20 + * limitations under the License. 1.21 + * ==================================================================== 1.22 + * 1.23 + * This software consists of voluntary contributions made by many 1.24 + * individuals on behalf of the Apache Software Foundation. For more 1.25 + * information on the Apache Software Foundation, please see 1.26 + * <http://www.apache.org/>. 1.27 + * 1.28 + */ 1.29 + 1.30 +package ch.boye.httpclientandroidlib.conn.params; 1.31 + 1.32 +import ch.boye.httpclientandroidlib.annotation.Immutable; 1.33 + 1.34 +import ch.boye.httpclientandroidlib.conn.routing.HttpRoute; 1.35 +import ch.boye.httpclientandroidlib.impl.conn.tsccm.ThreadSafeClientConnManager; 1.36 +import ch.boye.httpclientandroidlib.params.CoreConnectionPNames; 1.37 +import ch.boye.httpclientandroidlib.params.HttpConnectionParams; 1.38 +import ch.boye.httpclientandroidlib.params.HttpParams; 1.39 + 1.40 +/** 1.41 + * An adaptor for manipulating HTTP connection management 1.42 + * parameters in {@link HttpParams}. 1.43 + * 1.44 + * @since 4.0 1.45 + * 1.46 + * @see ConnManagerPNames 1.47 + * @deprecated replaced by methods in {@link HttpConnectionParams} and {@link ThreadSafeClientConnManager}. 1.48 + * See individual method descriptions for details 1.49 + */ 1.50 +@Deprecated 1.51 +@Immutable 1.52 +public final class ConnManagerParams implements ConnManagerPNames { 1.53 + 1.54 + /** The default maximum number of connections allowed overall */ 1.55 + public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20; 1.56 + 1.57 + /** 1.58 + * Returns the timeout in milliseconds used when retrieving a 1.59 + * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the 1.60 + * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}. 1.61 + * 1.62 + * @return timeout in milliseconds. 1.63 + * 1.64 + * @deprecated use {@link HttpConnectionParams#getConnectionTimeout(HttpParams)} 1.65 + */ 1.66 + @Deprecated 1.67 + public static long getTimeout(final HttpParams params) { 1.68 + if (params == null) { 1.69 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.70 + } 1.71 + Long param = (Long) params.getParameter(TIMEOUT); 1.72 + if (param != null) { 1.73 + return param.longValue(); 1.74 + } 1.75 + return params.getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 0); 1.76 + } 1.77 + 1.78 + /** 1.79 + * Sets the timeout in milliseconds used when retrieving a 1.80 + * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the 1.81 + * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}. 1.82 + * 1.83 + * @param timeout the timeout in milliseconds 1.84 + * 1.85 + * @deprecated use {@link HttpConnectionParams#setConnectionTimeout(HttpParams, int)} 1.86 + */ 1.87 + @Deprecated 1.88 + public static void setTimeout(final HttpParams params, long timeout) { 1.89 + if (params == null) { 1.90 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.91 + } 1.92 + params.setLongParameter(TIMEOUT, timeout); 1.93 + } 1.94 + 1.95 + /** The default maximum number of connections allowed per host */ 1.96 + private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() { 1.97 + 1.98 + public int getMaxForRoute(HttpRoute route) { 1.99 + return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE; 1.100 + } 1.101 + 1.102 + }; 1.103 + 1.104 + /** 1.105 + * Sets lookup interface for maximum number of connections allowed per route. 1.106 + * 1.107 + * @param params HTTP parameters 1.108 + * @param connPerRoute lookup interface for maximum number of connections allowed 1.109 + * per route 1.110 + * 1.111 + * @deprecated use {@link ThreadSafeClientConnManager#setMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute, int)} 1.112 + */ 1.113 + @Deprecated 1.114 + public static void setMaxConnectionsPerRoute(final HttpParams params, 1.115 + final ConnPerRoute connPerRoute) { 1.116 + if (params == null) { 1.117 + throw new IllegalArgumentException 1.118 + ("HTTP parameters must not be null."); 1.119 + } 1.120 + params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute); 1.121 + } 1.122 + 1.123 + /** 1.124 + * Returns lookup interface for maximum number of connections allowed per route. 1.125 + * 1.126 + * @param params HTTP parameters 1.127 + * 1.128 + * @return lookup interface for maximum number of connections allowed per route. 1.129 + * 1.130 + * @deprecated use {@link ThreadSafeClientConnManager#getMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute)} 1.131 + */ 1.132 + @Deprecated 1.133 + public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) { 1.134 + if (params == null) { 1.135 + throw new IllegalArgumentException 1.136 + ("HTTP parameters must not be null."); 1.137 + } 1.138 + ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE); 1.139 + if (connPerRoute == null) { 1.140 + connPerRoute = DEFAULT_CONN_PER_ROUTE; 1.141 + } 1.142 + return connPerRoute; 1.143 + } 1.144 + 1.145 + /** 1.146 + * Sets the maximum number of connections allowed. 1.147 + * 1.148 + * @param params HTTP parameters 1.149 + * @param maxTotalConnections The maximum number of connections allowed. 1.150 + * 1.151 + * @deprecated use {@link ThreadSafeClientConnManager#setMaxTotal(int)} 1.152 + */ 1.153 + @Deprecated 1.154 + public static void setMaxTotalConnections( 1.155 + final HttpParams params, 1.156 + int maxTotalConnections) { 1.157 + if (params == null) { 1.158 + throw new IllegalArgumentException 1.159 + ("HTTP parameters must not be null."); 1.160 + } 1.161 + params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections); 1.162 + } 1.163 + 1.164 + /** 1.165 + * Gets the maximum number of connections allowed. 1.166 + * 1.167 + * @param params HTTP parameters 1.168 + * 1.169 + * @return The maximum number of connections allowed. 1.170 + * 1.171 + * @deprecated use {@link ThreadSafeClientConnManager#getMaxTotal()} 1.172 + */ 1.173 + @Deprecated 1.174 + public static int getMaxTotalConnections( 1.175 + final HttpParams params) { 1.176 + if (params == null) { 1.177 + throw new IllegalArgumentException 1.178 + ("HTTP parameters must not be null."); 1.179 + } 1.180 + return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS); 1.181 + } 1.182 + 1.183 +}