1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with 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,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27 package org.apache.http.conn.params;
28
29 import org.apache.http.annotation.Immutable;
30 import org.apache.http.conn.routing.HttpRoute;
31 import org.apache.http.params.HttpConnectionParams;
32 import org.apache.http.params.HttpParams;
33 import org.apache.http.util.Args;
34
35 /**
36 * An adaptor for manipulating HTTP connection management
37 * parameters in {@link HttpParams}.
38 *
39 * @since 4.0
40 *
41 * @see ConnManagerPNames
42 *
43 * @deprecated (4.1) use configuration methods of the specific connection manager implementation.
44 */
45 @Deprecated
46 @Immutable
47 public final class ConnManagerParams implements ConnManagerPNames {
48
49 /** The default maximum number of connections allowed overall */
50 public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;
51
52 /**
53 * Returns the timeout in milliseconds used when retrieving a
54 * {@link org.apache.http.conn.ManagedClientConnection} from the
55 * {@link org.apache.http.conn.ClientConnectionManager}.
56 *
57 * @return timeout in milliseconds.
58 *
59 * @deprecated (4.1) use {@link HttpConnectionParams#getConnectionTimeout(HttpParams)}
60 */
61 @Deprecated
62 public static long getTimeout(final HttpParams params) {
63 Args.notNull(params, "HTTP parameters");
64 return params.getLongParameter(TIMEOUT, 0);
65 }
66
67 /**
68 * Sets the timeout in milliseconds used when retrieving a
69 * {@link org.apache.http.conn.ManagedClientConnection} from the
70 * {@link org.apache.http.conn.ClientConnectionManager}.
71 *
72 * @param timeout the timeout in milliseconds
73 *
74 * @deprecated (4.1) use {@link HttpConnectionParams#setConnectionTimeout(HttpParams, int)}
75 */
76 @Deprecated
77 public static void setTimeout(final HttpParams params, final long timeout) {
78 Args.notNull(params, "HTTP parameters");
79 params.setLongParameter(TIMEOUT, timeout);
80 }
81
82 /** The default maximum number of connections allowed per host */
83 private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() {
84
85 public int getMaxForRoute(final HttpRoute route) {
86 return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
87 }
88
89 };
90
91 /**
92 * Sets lookup interface for maximum number of connections allowed per route.
93 *
94 * @param params HTTP parameters
95 * @param connPerRoute lookup interface for maximum number of connections allowed
96 * per route
97 */
98 public static void setMaxConnectionsPerRoute(final HttpParams params,
99 final ConnPerRoute connPerRoute) {
100 Args.notNull(params, "HTTP parameters");
101 params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
102 }
103
104 /**
105 * Returns lookup interface for maximum number of connections allowed per route.
106 *
107 * @param params HTTP parameters
108 *
109 * @return lookup interface for maximum number of connections allowed per route.
110 */
111 public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
112 Args.notNull(params, "HTTP parameters");
113 ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE);
114 if (connPerRoute == null) {
115 connPerRoute = DEFAULT_CONN_PER_ROUTE;
116 }
117 return connPerRoute;
118 }
119
120 /**
121 * Sets the maximum number of connections allowed.
122 *
123 * @param params HTTP parameters
124 * @param maxTotalConnections The maximum number of connections allowed.
125 */
126 public static void setMaxTotalConnections(
127 final HttpParams params,
128 final int maxTotalConnections) {
129 Args.notNull(params, "HTTP parameters");
130 params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections);
131 }
132
133 /**
134 * Gets the maximum number of connections allowed.
135 *
136 * @param params HTTP parameters
137 *
138 * @return The maximum number of connections allowed.
139 */
140 public static int getMaxTotalConnections(
141 final HttpParams params) {
142 Args.notNull(params, "HTTP parameters");
143 return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS);
144 }
145
146 }