Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * ====================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ====================================================================
19 *
20 * This software consists of voluntary contributions made by many
21 * individuals on behalf of the Apache Software Foundation. For more
22 * information on the Apache Software Foundation, please see
23 * <http://www.apache.org/>.
24 *
25 */
27 package ch.boye.httpclientandroidlib.conn.params;
29 import ch.boye.httpclientandroidlib.annotation.Immutable;
31 import ch.boye.httpclientandroidlib.conn.routing.HttpRoute;
32 import ch.boye.httpclientandroidlib.impl.conn.tsccm.ThreadSafeClientConnManager;
33 import ch.boye.httpclientandroidlib.params.CoreConnectionPNames;
34 import ch.boye.httpclientandroidlib.params.HttpConnectionParams;
35 import ch.boye.httpclientandroidlib.params.HttpParams;
37 /**
38 * An adaptor for manipulating HTTP connection management
39 * parameters in {@link HttpParams}.
40 *
41 * @since 4.0
42 *
43 * @see ConnManagerPNames
44 * @deprecated replaced by methods in {@link HttpConnectionParams} and {@link ThreadSafeClientConnManager}.
45 * See individual method descriptions for details
46 */
47 @Deprecated
48 @Immutable
49 public final class ConnManagerParams implements ConnManagerPNames {
51 /** The default maximum number of connections allowed overall */
52 public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;
54 /**
55 * Returns the timeout in milliseconds used when retrieving a
56 * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the
57 * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}.
58 *
59 * @return timeout in milliseconds.
60 *
61 * @deprecated use {@link HttpConnectionParams#getConnectionTimeout(HttpParams)}
62 */
63 @Deprecated
64 public static long getTimeout(final HttpParams params) {
65 if (params == null) {
66 throw new IllegalArgumentException("HTTP parameters may not be null");
67 }
68 Long param = (Long) params.getParameter(TIMEOUT);
69 if (param != null) {
70 return param.longValue();
71 }
72 return params.getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
73 }
75 /**
76 * Sets the timeout in milliseconds used when retrieving a
77 * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the
78 * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}.
79 *
80 * @param timeout the timeout in milliseconds
81 *
82 * @deprecated use {@link HttpConnectionParams#setConnectionTimeout(HttpParams, int)}
83 */
84 @Deprecated
85 public static void setTimeout(final HttpParams params, long timeout) {
86 if (params == null) {
87 throw new IllegalArgumentException("HTTP parameters may not be null");
88 }
89 params.setLongParameter(TIMEOUT, timeout);
90 }
92 /** The default maximum number of connections allowed per host */
93 private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() {
95 public int getMaxForRoute(HttpRoute route) {
96 return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
97 }
99 };
101 /**
102 * Sets lookup interface for maximum number of connections allowed per route.
103 *
104 * @param params HTTP parameters
105 * @param connPerRoute lookup interface for maximum number of connections allowed
106 * per route
107 *
108 * @deprecated use {@link ThreadSafeClientConnManager#setMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute, int)}
109 */
110 @Deprecated
111 public static void setMaxConnectionsPerRoute(final HttpParams params,
112 final ConnPerRoute connPerRoute) {
113 if (params == null) {
114 throw new IllegalArgumentException
115 ("HTTP parameters must not be null.");
116 }
117 params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
118 }
120 /**
121 * Returns lookup interface for maximum number of connections allowed per route.
122 *
123 * @param params HTTP parameters
124 *
125 * @return lookup interface for maximum number of connections allowed per route.
126 *
127 * @deprecated use {@link ThreadSafeClientConnManager#getMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute)}
128 */
129 @Deprecated
130 public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
131 if (params == null) {
132 throw new IllegalArgumentException
133 ("HTTP parameters must not be null.");
134 }
135 ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE);
136 if (connPerRoute == null) {
137 connPerRoute = DEFAULT_CONN_PER_ROUTE;
138 }
139 return connPerRoute;
140 }
142 /**
143 * Sets the maximum number of connections allowed.
144 *
145 * @param params HTTP parameters
146 * @param maxTotalConnections The maximum number of connections allowed.
147 *
148 * @deprecated use {@link ThreadSafeClientConnManager#setMaxTotal(int)}
149 */
150 @Deprecated
151 public static void setMaxTotalConnections(
152 final HttpParams params,
153 int maxTotalConnections) {
154 if (params == null) {
155 throw new IllegalArgumentException
156 ("HTTP parameters must not be null.");
157 }
158 params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections);
159 }
161 /**
162 * Gets the maximum number of connections allowed.
163 *
164 * @param params HTTP parameters
165 *
166 * @return The maximum number of connections allowed.
167 *
168 * @deprecated use {@link ThreadSafeClientConnManager#getMaxTotal()}
169 */
170 @Deprecated
171 public static int getMaxTotalConnections(
172 final HttpParams params) {
173 if (params == null) {
174 throw new IllegalArgumentException
175 ("HTTP parameters must not be null.");
176 }
177 return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS);
178 }
180 }