2
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java,v 1.9 2004/09/13 16:25:20 olegk Exp $
4
* $Date: 2005-12-05 15:18:10 -0500 (Mon, 05 Dec 2005) $
6
* ====================================================================
8
* Copyright 1999-2004 The Apache Software Foundation
10
* Licensed under the Apache License, Version 2.0 (the "License");
11
* you may not use this file except in compliance with the License.
12
* You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing, software
17
* distributed under the License is distributed on an "AS IS" BASIS,
18
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
* See the License for the specific language governing permissions and
20
* limitations under the License.
21
* ====================================================================
23
* This software consists of voluntary contributions made by many
24
* individuals on behalf of the Apache Software Foundation. For more
25
* information on the Apache Software Foundation, please see
26
* <http://www.apache.org/>.
30
package org.apache.commons.httpclient.params;
32
import java.util.HashMap;
35
import org.apache.commons.httpclient.HostConfiguration;
36
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
39
* This class represents a collection of HTTP protocol parameters applicable to
40
* {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection managers}.
41
* Protocol parameters may be linked together to form a hierarchy. If a particular
42
* parameter value has not been explicitly defined in the collection itself, its
43
* value will be drawn from the parent collection of parameters.
45
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
46
* @author Michael Becke
48
* @version $Revision: 354155 $
52
public class HttpConnectionManagerParams extends HttpConnectionParams {
55
* Defines the maximum number of connections allowed per host configuration.
56
* These values only apply to the number of connections from a particular instance
57
* of HttpConnectionManager.
59
* This parameter expects a value of type {@link java.util.Map}. The value
60
* should map instances of {@link org.apache.commons.httpclient.HostConfiguration}
61
* to {@link Integer integers}. The default value can be specified using
62
* {@link org.apache.commons.httpclient.HostConfiguration#ANY_HOST_CONFIGURATION}.
65
public static final String MAX_HOST_CONNECTIONS = "http.connection-manager.max-per-host";
68
* Defines the maximum number of connections allowed overall. This value only applies
69
* to the number of connections from a particular instance of HttpConnectionManager.
71
* This parameter expects a value of type {@link Integer}.
74
public static final String MAX_TOTAL_CONNECTIONS = "http.connection-manager.max-total";
77
* Sets the default maximum number of connections allowed for a given
80
* @param maxHostConnections The default maximum.
82
* @see #MAX_HOST_CONNECTIONS
84
public void setDefaultMaxConnectionsPerHost(int maxHostConnections) {
85
setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxHostConnections);
89
* Sets the maximum number of connections to be used for the given host config.
91
* @param hostConfiguration The host config to set the maximum for. Use
92
* {@link HostConfiguration#ANY_HOST_CONFIGURATION} to configure the default value
94
* @param maxHostConnections The maximum number of connections, <code>> 0</code>
96
* @see #MAX_HOST_CONNECTIONS
98
public void setMaxConnectionsPerHost(
99
HostConfiguration hostConfiguration,
100
int maxHostConnections) {
102
if (maxHostConnections <= 0) {
103
throw new IllegalArgumentException("maxHostConnections must be greater than 0");
106
Map currentValues = (Map) getParameter(MAX_HOST_CONNECTIONS);
107
// param values are meant to be immutable so we'll make a copy
109
Map newValues = null;
110
if (currentValues == null) {
111
newValues = new HashMap();
113
newValues = new HashMap(currentValues);
115
newValues.put(hostConfiguration, new Integer(maxHostConnections));
116
setParameter(MAX_HOST_CONNECTIONS, newValues);
120
* Gets the default maximum number of connections allowed for a given
123
* @return The default maximum.
125
* @see #MAX_HOST_CONNECTIONS
127
public int getDefaultMaxConnectionsPerHost() {
128
return getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION);
132
* Gets the maximum number of connections to be used for a particular host config. If
133
* the value has not been specified for the given host the default value will be
136
* @param hostConfiguration The host config.
137
* @return The maximum number of connections to be used for the given host config.
139
* @see #MAX_HOST_CONNECTIONS
141
public int getMaxConnectionsPerHost(HostConfiguration hostConfiguration) {
143
Map m = (Map) getParameter(MAX_HOST_CONNECTIONS);
145
// MAX_HOST_CONNECTIONS have not been configured, using the default value
146
return MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS;
148
Integer max = (Integer) m.get(hostConfiguration);
149
if (max == null && hostConfiguration != HostConfiguration.ANY_HOST_CONFIGURATION) {
150
// the value has not been configured specifically for this host config,
151
// use the default value
152
return getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION);
156
? MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS
164
* Sets the maximum number of connections allowed.
166
* @param maxTotalConnections The maximum number of connections allowed.
168
* @see #MAX_TOTAL_CONNECTIONS
170
public void setMaxTotalConnections(int maxTotalConnections) {
172
HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
173
maxTotalConnections);
177
* Gets the maximum number of connections allowed.
179
* @return The maximum number of connections allowed.
181
* @see #MAX_TOTAL_CONNECTIONS
183
public int getMaxTotalConnections() {
184
return getIntParameter(
185
HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
186
MultiThreadedHttpConnectionManager.DEFAULT_MAX_TOTAL_CONNECTIONS);