• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnManagerParams.java $
3  * $Revision: 658785 $
4  * $Date: 2008-05-21 10:47:40 -0700 (Wed, 21 May 2008) $
5  *
6  * ====================================================================
7  *
8  *  Licensed to the Apache Software Foundation (ASF) under one or more
9  *  contributor license agreements.  See the NOTICE file distributed with
10  *  this work for additional information regarding copyright ownership.
11  *  The ASF licenses this file to You under the Apache License, Version 2.0
12  *  (the "License"); you may not use this file except in compliance with
13  *  the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  * ====================================================================
23  *
24  * This software consists of voluntary contributions made by many
25  * individuals on behalf of the Apache Software Foundation.  For more
26  * information on the Apache Software Foundation, please see
27  * <http://www.apache.org/>.
28  *
29  */
30 
31 package org.apache.http.conn.params;
32 
33 import org.apache.http.conn.routing.HttpRoute;
34 import org.apache.http.params.HttpParams;
35 
36 /**
37  * This class represents a collection of HTTP protocol parameters applicable
38  * to client-side
39  * {@link org.apache.http.conn.ClientConnectionManager connection managers}.
40  *
41  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
42  * @author Michael Becke
43  *
44  * @version $Revision: 658785 $
45  *
46  * @since 4.0
47  *
48  * @see ConnManagerPNames
49  *
50  * @deprecated Please use {@link java.net.URL#openConnection} instead.
51  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
52  *     for further details.
53  */
54 @Deprecated
55 public final class ConnManagerParams implements ConnManagerPNames {
56 
57     /** The default maximum number of connections allowed overall */
58     public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;
59 
60     /**
61      * Returns the timeout in milliseconds used when retrieving a
62      * {@link org.apache.http.conn.ManagedClientConnection} from the
63      * {@link org.apache.http.conn.ClientConnectionManager}.
64      *
65      * @return timeout in milliseconds.
66      */
getTimeout(final HttpParams params)67     public static long getTimeout(final HttpParams params) {
68         if (params == null) {
69             throw new IllegalArgumentException("HTTP parameters may not be null");
70         }
71         return params.getLongParameter(TIMEOUT, 0);
72     }
73 
74     /**
75      * Sets the timeout in milliseconds used when retrieving a
76      * {@link org.apache.http.conn.ManagedClientConnection} from the
77      * {@link org.apache.http.conn.ClientConnectionManager}.
78      *
79      * @param timeout the timeout in milliseconds
80      */
setTimeout(final HttpParams params, long timeout)81     public static void setTimeout(final HttpParams params, long timeout) {
82         if (params == null) {
83             throw new IllegalArgumentException("HTTP parameters may not be null");
84         }
85         params.setLongParameter(TIMEOUT, timeout);
86     }
87 
88     /** The default maximum number of connections allowed per host */
89     private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() {
90 
91         public int getMaxForRoute(HttpRoute route) {
92             return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
93         }
94 
95     };
96 
97     /**
98      * Sets lookup interface for maximum number of connections allowed per route.
99      *
100      * @param params HTTP parameters
101      * @param connPerRoute lookup interface for maximum number of connections allowed
102      *        per route
103      *
104      * @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE
105      */
setMaxConnectionsPerRoute(final HttpParams params, final ConnPerRoute connPerRoute)106     public static void setMaxConnectionsPerRoute(final HttpParams params,
107                                                 final ConnPerRoute connPerRoute) {
108         if (params == null) {
109             throw new IllegalArgumentException
110                 ("HTTP parameters must not be null.");
111         }
112         params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
113     }
114 
115     /**
116      * Returns lookup interface for maximum number of connections allowed per route.
117      *
118      * @param params HTTP parameters
119      *
120      * @return lookup interface for maximum number of connections allowed per route.
121      *
122      * @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE
123      */
getMaxConnectionsPerRoute(final HttpParams params)124     public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
125         if (params == null) {
126             throw new IllegalArgumentException
127                 ("HTTP parameters must not be null.");
128         }
129         ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE);
130         if (connPerRoute == null) {
131             connPerRoute = DEFAULT_CONN_PER_ROUTE;
132         }
133         return connPerRoute;
134     }
135 
136 
137     /**
138      * Sets the maximum number of connections allowed.
139      *
140      * @param params HTTP parameters
141      * @param maxTotalConnections The maximum number of connections allowed.
142      *
143      * @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS
144      */
setMaxTotalConnections( final HttpParams params, int maxTotalConnections)145     public static void setMaxTotalConnections(
146             final HttpParams params,
147             int maxTotalConnections) {
148         if (params == null) {
149             throw new IllegalArgumentException
150                 ("HTTP parameters must not be null.");
151         }
152         params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections);
153     }
154 
155     /**
156      * Gets the maximum number of connections allowed.
157      *
158      * @param params HTTP parameters
159      *
160      * @return The maximum number of connections allowed.
161      *
162      * @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS
163      */
getMaxTotalConnections( final HttpParams params)164     public static int getMaxTotalConnections(
165             final HttpParams params) {
166         if (params == null) {
167             throw new IllegalArgumentException
168                 ("HTTP parameters must not be null.");
169         }
170         return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS);
171     }
172 
173 
174 }
175