HTTPCLIENT-618: class HostConfiguration is no more
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@558079 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5f99e69191
commit
d4862a917b
|
@ -1,5 +1,8 @@
|
|||
Changes since release 4.0 Alpha 1
|
||||
|
||||
* [HTTPCLIENT-618] eliminate class HostConfiguration
|
||||
Contributed by Roland Weber <rolandw at apache.org>
|
||||
|
||||
* [HTTPCLIENT-672] re-sync with API changes in core alpha6-SNAPSHOT
|
||||
Contributed by Roland Weber <rolandw at apache.org>
|
||||
|
||||
|
|
|
@ -1,195 +0,0 @@
|
|||
/*
|
||||
* $HeadURL$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.conn;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.util.LangUtils;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides configuration data for connecting to a host.
|
||||
* That is the host to connect to plus
|
||||
* a proxy to use or a local IP address to select
|
||||
* one of several network interfaces.
|
||||
* Instances of this class are immutable.
|
||||
* Instances of derived classes should be immutable, too.
|
||||
*
|
||||
* @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
|
||||
* @author <a href="mailto:becke@u.washington.edu">Michael Becke</a>
|
||||
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
|
||||
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
|
||||
* @author Laura Werner
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class HostConfiguration {
|
||||
|
||||
/**
|
||||
* Constant representing a configuration for <i>any</i> host.
|
||||
* That means to no host in particular. Use this constant in
|
||||
* cases where you'd otherwise pass <code>null</code> to
|
||||
* refer to a default value that applies to "any" host.
|
||||
*/
|
||||
public static final
|
||||
HostConfiguration ANY_HOST_CONFIGURATION = new HostConfiguration();
|
||||
|
||||
/** The host to connect to. */
|
||||
private final HttpHost targetHost;
|
||||
|
||||
/** The host name of the proxy server */
|
||||
private final HttpHost proxyHost;
|
||||
|
||||
/**
|
||||
* The local address to use when creating the socket.
|
||||
* <code>null</code> indicates that the default should be used.
|
||||
*/
|
||||
private final InetAddress localAddress;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new host configuration.
|
||||
*
|
||||
* @param host the target host to connect to
|
||||
* @param proxy the proxy host to use, or
|
||||
* <code>null</code> for a direct connection
|
||||
* @param laddr the local IP address to use, or
|
||||
* <code>null</code> for any
|
||||
*/
|
||||
public HostConfiguration(HttpHost host, HttpHost proxy,
|
||||
InetAddress laddr) {
|
||||
if (host == null) {
|
||||
throw new IllegalArgumentException("Target host may not be null.");
|
||||
}
|
||||
this.targetHost = host;
|
||||
this.proxyHost = proxy;
|
||||
this.localAddress = laddr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new "any" host configuration.
|
||||
* This is the only way to create a host configuration
|
||||
* without a target host. It is used exclusively to initialize
|
||||
* {@link #ANY_HOST_CONFIGURATION ANY_HOST_CONFIGURATION}.
|
||||
*/
|
||||
private HostConfiguration() {
|
||||
this.targetHost = null;
|
||||
this.proxyHost = null;
|
||||
this.localAddress = null;
|
||||
}
|
||||
|
||||
|
||||
// non-javadoc, see java.lang.Object#toString()
|
||||
public String toString() {
|
||||
|
||||
StringBuffer b = new StringBuffer(50);
|
||||
b.append("HostConfiguration[");
|
||||
|
||||
if (this.targetHost != null) {
|
||||
b.append("host=").append(this.targetHost);
|
||||
} else {
|
||||
b.append("host=*any*");
|
||||
}
|
||||
if (this.proxyHost != null) {
|
||||
b.append(", ").append("proxyHost=").append(this.proxyHost);
|
||||
}
|
||||
if (this.localAddress != null) {
|
||||
b.append(", ").append("localAddress=").append(this.localAddress);
|
||||
}
|
||||
b.append("]");
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the target host.
|
||||
*
|
||||
* @return the target host, or <code>null</code> if this is
|
||||
* {@link #ANY_HOST_CONFIGURATION ANY_HOST_CONFIGURATION}
|
||||
*/
|
||||
public HttpHost getHost() {
|
||||
return this.targetHost;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the proxy to use.
|
||||
*
|
||||
* @return the proxy host, or <code>null</code> if not set
|
||||
*/
|
||||
public HttpHost getProxyHost() {
|
||||
return this.proxyHost;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the local address to be used when creating connections.
|
||||
* If this is unset, the default address should be used.
|
||||
*
|
||||
* @return the local address to be used when creating Sockets,
|
||||
* or <code>null</code>
|
||||
*/
|
||||
public InetAddress getLocalAddress() {
|
||||
return this.localAddress;
|
||||
}
|
||||
|
||||
|
||||
// non-javadoc, see java.lang.Object#equals(java.lang.Object)
|
||||
public boolean equals(final Object o) {
|
||||
if (o instanceof HostConfiguration) {
|
||||
// shortcut if we're comparing with ourselves
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
HostConfiguration that = (HostConfiguration) o;
|
||||
return LangUtils.equals(this.targetHost, that.targetHost)
|
||||
&& LangUtils.equals(this.proxyHost, that.proxyHost)
|
||||
&& LangUtils.equals(this.localAddress, that.localAddress);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// non-javadoc, see java.lang.Object#hashCode()
|
||||
public int hashCode() {
|
||||
int hash = LangUtils.HASH_SEED;
|
||||
hash = LangUtils.hashCode(hash, this.targetHost);
|
||||
hash = LangUtils.hashCode(hash, this.proxyHost);
|
||||
hash = LangUtils.hashCode(hash, this.localAddress);
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
|
@ -368,24 +368,6 @@ public final class HttpRoute implements Cloneable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts to the {@link HostConfiguration traditional} interface.
|
||||
*
|
||||
* @return a host configuration matching this route as good as possible
|
||||
*
|
||||
* @deprecated No replacement.
|
||||
* This class will replace {@link HostConfiguration}
|
||||
* where routes need to be represented. No conversion necessary.
|
||||
*/
|
||||
public final HostConfiguration toHostConfig() {
|
||||
if ((this.proxyChain != null) && (this.proxyChain.length > 1)) {
|
||||
throw new IllegalStateException("Cannot convert proxy chain.");
|
||||
}
|
||||
return new HostConfiguration
|
||||
(this.targetHost, getProxyHost(), this.localAddress);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares this route to another.
|
||||
*
|
||||
|
|
|
@ -355,28 +355,6 @@ public final class RouteTracker implements Cloneable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtains the tracked route.
|
||||
* <br/><b>Note:</b>
|
||||
* Currently, {@link HostConfiguration HostConfiguration} is used to
|
||||
* represent the route. It does not cover all tracked attributes.
|
||||
* In particular, it can not represent intermediate steps in establishing
|
||||
* a route.
|
||||
*
|
||||
* @deprecated use {@link #toRoute toRoute} instead. Kept temporarily
|
||||
* until {@link HttpRoute} takes over from {@link HostConfiguration}.
|
||||
*
|
||||
* @return a representation of the route tracked so far
|
||||
*/
|
||||
public final HostConfiguration toHostConfig() {
|
||||
if ((this.proxyChain != null) && (this.proxyChain.length > 1)) {
|
||||
throw new IllegalStateException("Cannot convert proxy chain.");
|
||||
}
|
||||
return new HostConfiguration
|
||||
(this.targetHost, getProxyHost(), this.localAddress);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares this tracked route to another.
|
||||
*
|
||||
|
|
|
@ -33,7 +33,7 @@ package org.apache.http.conn.params;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.conn.HostConfiguration;
|
||||
import org.apache.http.conn.HttpRoute;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
/**
|
||||
|
@ -56,15 +56,19 @@ public final class HttpConnectionManagerParams {
|
|||
/** The default maximum number of connections allowed overall */
|
||||
public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;
|
||||
|
||||
/** A key to represent the default for route-specific settings. */
|
||||
private static final String ROUTE_DEFAULT = "*Route*Default*";
|
||||
|
||||
|
||||
/**
|
||||
* Defines the maximum number of connections allowed per host configuration.
|
||||
* These values only apply to the number of connections from a particular instance
|
||||
* of HttpConnectionManager.
|
||||
* <p>
|
||||
* This parameter expects a value of type {@link java.util.Map}. The value
|
||||
* should map instances of {@link HostConfiguration}
|
||||
* should map instances of {@link HttpRoute}
|
||||
* to {@link Integer integers}. The default value can be specified using
|
||||
* {@link HostConfiguration#ANY_HOST_CONFIGURATION}.
|
||||
* {@link HttpRoute#ANY_HOST_CONFIGURATION}.
|
||||
* </p>
|
||||
*/
|
||||
public static final String MAX_HOST_CONNECTIONS = "http.connection-manager.max-per-host";
|
||||
|
@ -77,44 +81,57 @@ public final class HttpConnectionManagerParams {
|
|||
* </p>
|
||||
*/
|
||||
public static final String MAX_TOTAL_CONNECTIONS = "http.connection-manager.max-total";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the default maximum number of connections allowed for a given
|
||||
* host config.
|
||||
* Sets the default maximum number of connections allowed for routes.
|
||||
*
|
||||
* @param maxHostConnections The default maximum.
|
||||
* @param max The default maximum.
|
||||
*
|
||||
* @see #MAX_HOST_CONNECTIONS
|
||||
*/
|
||||
public static void setDefaultMaxConnectionsPerHost(
|
||||
final HttpParams params,
|
||||
int maxHostConnections) {
|
||||
setMaxConnectionsPerHost(
|
||||
params,
|
||||
HostConfiguration.ANY_HOST_CONFIGURATION,
|
||||
maxHostConnections);
|
||||
public static void setDefaultMaxConnectionsPerHost(final HttpParams params,
|
||||
final int max) {
|
||||
setMaxPerHost(params, ROUTE_DEFAULT, max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of connections to be used for the given host config.
|
||||
* Sets the maximum number of connections to be used for a given route.
|
||||
*
|
||||
* @param hostConfiguration The host config to set the maximum for. Use
|
||||
* {@link HostConfiguration#ANY_HOST_CONFIGURATION} to configure the default value
|
||||
* per host.
|
||||
* @param maxHostConnections The maximum number of connections, <code>> 0</code>
|
||||
* @param route the route to set the maximum for
|
||||
* @param max the maximum number of connections,
|
||||
* must be greater than 0
|
||||
*
|
||||
* @see #MAX_HOST_CONNECTIONS
|
||||
*/
|
||||
public static void setMaxConnectionsPerHost(
|
||||
final HttpParams params,
|
||||
final HostConfiguration hostConfiguration,
|
||||
int maxHostConnections) {
|
||||
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
public static void setMaxConnectionsPerHost(final HttpParams params,
|
||||
final HttpRoute route,
|
||||
final int max) {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Route must not be null.");
|
||||
}
|
||||
if (maxHostConnections <= 0) {
|
||||
throw new IllegalArgumentException("maxHostConnections must be greater than 0");
|
||||
setMaxPerHost(params, route, max);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal setter for a max-per-host value.
|
||||
*
|
||||
* @param params the parameters in which to set a max-per-host value
|
||||
* @param key the key, either an {@link HttpRoute} or
|
||||
* {@link #ROUTE_DEFAULT}
|
||||
* @param max the value to set for that key
|
||||
*/
|
||||
private static void setMaxPerHost(HttpParams params,
|
||||
Object key, int max) {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException
|
||||
("HTTP parameters must not be null.");
|
||||
}
|
||||
if (max <= 0) {
|
||||
throw new IllegalArgumentException
|
||||
("The maximum must be greater than 0.");
|
||||
}
|
||||
|
||||
Map currentValues = (Map) params.getParameter(MAX_HOST_CONNECTIONS);
|
||||
|
@ -126,9 +143,10 @@ public final class HttpConnectionManagerParams {
|
|||
} else {
|
||||
newValues = new HashMap(currentValues);
|
||||
}
|
||||
newValues.put(hostConfiguration, new Integer(maxHostConnections));
|
||||
newValues.put(key, new Integer(max));
|
||||
params.setParameter(MAX_HOST_CONNECTIONS, newValues);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the default maximum number of connections allowed for a given
|
||||
|
@ -139,49 +157,67 @@ public final class HttpConnectionManagerParams {
|
|||
* @see #MAX_HOST_CONNECTIONS
|
||||
*/
|
||||
public static int getDefaultMaxConnectionsPerHost(
|
||||
final HttpParams params) {
|
||||
return getMaxConnectionsPerHost(
|
||||
params,
|
||||
HostConfiguration.ANY_HOST_CONFIGURATION);
|
||||
final HttpParams params) {
|
||||
return getMaxPerHost( params, ROUTE_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum number of connections to be used for a particular host config. If
|
||||
* the value has not been specified for the given host the default value will be
|
||||
* returned.
|
||||
* Gets the maximum number of connections allowed for a specific route.
|
||||
* If the value has not been specified for the given route, the default
|
||||
* value will be returned.
|
||||
*
|
||||
* @param hostConfiguration The host config.
|
||||
* @return The maximum number of connections to be used for the given host config.
|
||||
* @param route the route for which to get the maximum connections
|
||||
*
|
||||
* @return The maximum number of connections allowed for the given route.
|
||||
*
|
||||
* @see #MAX_HOST_CONNECTIONS
|
||||
*/
|
||||
public static int getMaxConnectionsPerHost(
|
||||
final HttpParams params,
|
||||
final HostConfiguration hostConfiguration) {
|
||||
public static int getMaxConnectionsPerHost(final HttpParams params,
|
||||
final HttpRoute route) {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Route must not be null.");
|
||||
}
|
||||
return getMaxPerHost(params, route);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal getter for a max-per-host value.
|
||||
*
|
||||
* @param params the parameters from which to get a max-per-host value
|
||||
* @param key the key, either an {@link HttpRoute} or
|
||||
* {@link #ROUTE_DEFAULT}
|
||||
*
|
||||
* @return the maximum for that key, or the default maximum
|
||||
*/
|
||||
private static int getMaxPerHost(final HttpParams params,
|
||||
final Object key) {
|
||||
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
throw new IllegalArgumentException
|
||||
("HTTP parameters must not be null.");
|
||||
}
|
||||
|
||||
// if neither a specific nor a default maximum is configured...
|
||||
int result = DEFAULT_MAX_HOST_CONNECTIONS;
|
||||
|
||||
Map m = (Map) params.getParameter(MAX_HOST_CONNECTIONS);
|
||||
if (m == null) {
|
||||
// MAX_HOST_CONNECTIONS have not been configured, using the default value
|
||||
return DEFAULT_MAX_HOST_CONNECTIONS;
|
||||
} else {
|
||||
Integer max = (Integer) m.get(hostConfiguration);
|
||||
if (max == null && hostConfiguration != HostConfiguration.ANY_HOST_CONFIGURATION) {
|
||||
// the value has not been configured specifically for this host config,
|
||||
// use the default value
|
||||
return getMaxConnectionsPerHost(params, HostConfiguration.ANY_HOST_CONFIGURATION);
|
||||
} else {
|
||||
return (
|
||||
max == null
|
||||
? DEFAULT_MAX_HOST_CONNECTIONS
|
||||
: max.intValue()
|
||||
);
|
||||
if (m != null) {
|
||||
Integer max = (Integer) m.get(key);
|
||||
if ((max == null) && (key != ROUTE_DEFAULT)) {
|
||||
// no specific maximum, get the configured default
|
||||
max = (Integer) m.get(ROUTE_DEFAULT);
|
||||
}
|
||||
if (max != null) {
|
||||
result = max.intValue();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the maximum number of connections allowed.
|
||||
*
|
||||
|
@ -193,7 +229,8 @@ public final class HttpConnectionManagerParams {
|
|||
final HttpParams params,
|
||||
int maxTotalConnections) {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
throw new IllegalArgumentException
|
||||
("HTTP parameters must not be null.");
|
||||
}
|
||||
params.setIntParameter(
|
||||
HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
|
||||
|
@ -210,7 +247,8 @@ public final class HttpConnectionManagerParams {
|
|||
public static int getMaxTotalConnections(
|
||||
final HttpParams params) {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
throw new IllegalArgumentException
|
||||
("HTTP parameters must not be null.");
|
||||
}
|
||||
return params.getIntParameter(
|
||||
HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.ClientConnectionOperator;
|
||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
import org.apache.http.conn.HostConfiguration;
|
||||
import org.apache.http.conn.HttpRoute;
|
||||
import org.apache.http.conn.HttpRoute;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
|
@ -68,7 +68,7 @@ import org.apache.http.params.HttpParams;
|
|||
*
|
||||
*
|
||||
* <!-- empty lines to avoid svn diff problems -->
|
||||
* @version $Revision$ $Date$
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
@ -185,8 +185,7 @@ public class ThreadSafeClientConnManager
|
|||
+ route + ", timeout = " + timeout);
|
||||
}
|
||||
|
||||
final TrackingPoolEntry entry =
|
||||
doGetConnection(route.toHostConfig(), timeout);
|
||||
final TrackingPoolEntry entry = doGetConnection(route, timeout);
|
||||
|
||||
return new HttpConnectionAdapter(entry);
|
||||
}
|
||||
|
@ -202,7 +201,7 @@ public class ThreadSafeClientConnManager
|
|||
*
|
||||
* @throws ConnectionPoolTimeoutException if the timeout expired
|
||||
*/
|
||||
private TrackingPoolEntry doGetConnection(HostConfiguration route,
|
||||
private TrackingPoolEntry doGetConnection(HttpRoute route,
|
||||
long timeout)
|
||||
throws ConnectionPoolTimeoutException {
|
||||
|
||||
|
@ -216,7 +215,7 @@ public class ThreadSafeClientConnManager
|
|||
synchronized (connectionPool) {
|
||||
|
||||
// we used to clone the hostconfig here, but it is now immutable:
|
||||
//route = new HostConfiguration(route);
|
||||
//route = new HttpRoute(route);
|
||||
HostConnectionPool hostPool = connectionPool.getHostPool(route);
|
||||
WaitingThread waitingThread = null;
|
||||
|
||||
|
@ -329,7 +328,7 @@ public class ThreadSafeClientConnManager
|
|||
*
|
||||
* @return the pool entry for the new connection
|
||||
*/
|
||||
private TrackingPoolEntry createPoolEntry(HostConfiguration route) {
|
||||
private TrackingPoolEntry createPoolEntry(HttpRoute route) {
|
||||
|
||||
OperatedClientConnection occ = connOperator.createConnection();
|
||||
return connectionPool.createEntry(route, occ);
|
||||
|
@ -491,7 +490,7 @@ public class ThreadSafeClientConnManager
|
|||
*/
|
||||
private static void storeReferenceToConnection(
|
||||
TrackingPoolEntry connection,
|
||||
HostConfiguration hostConfiguration,
|
||||
HttpRoute hostConfiguration,
|
||||
ConnectionPool connectionPool
|
||||
) {
|
||||
|
||||
|
@ -605,7 +604,7 @@ public class ThreadSafeClientConnManager
|
|||
* @param hostConfiguration The host configuration
|
||||
* @return The total number of pooled connections
|
||||
*/
|
||||
public int getConnectionsInPool(HostConfiguration hostConfiguration) {
|
||||
public int getConnectionsInPool(HttpRoute hostConfiguration) {
|
||||
synchronized (connectionPool) {
|
||||
HostConnectionPool hostPool = connectionPool.getHostPool(hostConfiguration);
|
||||
return hostPool.numConnections;
|
||||
|
@ -681,7 +680,7 @@ public class ThreadSafeClientConnManager
|
|||
private LinkedList waitingThreads = new LinkedList();
|
||||
|
||||
/**
|
||||
* Map where keys are {@link HostConfiguration}s and values are
|
||||
* Map where keys are {@link HttpRoute}s and values are
|
||||
* {@link HostConnectionPool}s
|
||||
*/
|
||||
private final Map mapHosts = new HashMap();
|
||||
|
@ -735,7 +734,7 @@ public class ThreadSafeClientConnManager
|
|||
* @return the new pool entry
|
||||
*/
|
||||
protected synchronized
|
||||
TrackingPoolEntry createEntry(HostConfiguration route,
|
||||
TrackingPoolEntry createEntry(HttpRoute route,
|
||||
OperatedClientConnection conn) {
|
||||
|
||||
HostConnectionPool hostPool = getHostPool(route);
|
||||
|
@ -762,7 +761,7 @@ public class ThreadSafeClientConnManager
|
|||
* @param config the host configuration of the connection that was lost
|
||||
*/
|
||||
public synchronized
|
||||
void handleLostConnection(HostConfiguration config) {
|
||||
void handleLostConnection(HttpRoute config) {
|
||||
|
||||
HostConnectionPool hostPool = getHostPool(config);
|
||||
hostPool.numConnections--;
|
||||
|
@ -780,7 +779,7 @@ public class ThreadSafeClientConnManager
|
|||
* @return a pool (list) of connections available for the given route
|
||||
*/
|
||||
public synchronized
|
||||
HostConnectionPool getHostPool(HostConfiguration route) {
|
||||
HostConnectionPool getHostPool(HttpRoute route) {
|
||||
|
||||
// Look for a list of connections for the given config
|
||||
HostConnectionPool listConnections =
|
||||
|
@ -802,7 +801,7 @@ public class ThreadSafeClientConnManager
|
|||
* @param hostConfiguration the configuraton for the connection pool
|
||||
* @return an available connection for the given config
|
||||
*/
|
||||
public synchronized TrackingPoolEntry getFreeConnection(HostConfiguration hostConfiguration) {
|
||||
public synchronized TrackingPoolEntry getFreeConnection(HttpRoute hostConfiguration) {
|
||||
|
||||
TrackingPoolEntry entry = null;
|
||||
|
||||
|
@ -865,7 +864,7 @@ public class ThreadSafeClientConnManager
|
|||
*/
|
||||
private synchronized void deleteConnection(TrackingPoolEntry entry) {
|
||||
|
||||
HostConfiguration route = entry.plannedRoute;
|
||||
HttpRoute route = entry.plannedRoute;
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Reclaiming connection, hostConfig=" + route);
|
||||
|
@ -906,7 +905,7 @@ public class ThreadSafeClientConnManager
|
|||
* @param configuration the host config to use for notifying
|
||||
* @see #notifyWaitingThread(HostConnectionPool)
|
||||
*/
|
||||
public synchronized void notifyWaitingThread(HostConfiguration configuration) {
|
||||
public synchronized void notifyWaitingThread(HttpRoute configuration) {
|
||||
notifyWaitingThread(getHostPool(configuration));
|
||||
}
|
||||
|
||||
|
@ -954,7 +953,7 @@ public class ThreadSafeClientConnManager
|
|||
*/
|
||||
private void freeConnection(TrackingPoolEntry entry) {
|
||||
|
||||
HostConfiguration route = entry.plannedRoute;
|
||||
HttpRoute route = entry.plannedRoute;
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Freeing connection, hostConfig=" + route);
|
||||
|
@ -1020,7 +1019,7 @@ public class ThreadSafeClientConnManager
|
|||
public ConnectionPool connectionPool;
|
||||
|
||||
/** The connection's host configuration */
|
||||
public HostConfiguration hostConfiguration;
|
||||
public HttpRoute hostConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1029,7 +1028,7 @@ public class ThreadSafeClientConnManager
|
|||
*/
|
||||
private static class HostConnectionPool {
|
||||
/** The hostConfig this pool is for */
|
||||
public HostConfiguration hostConfiguration;
|
||||
public HttpRoute hostConfiguration;
|
||||
|
||||
/** The list of free connections */
|
||||
public LinkedList freeConnections = new LinkedList();
|
||||
|
@ -1136,8 +1135,9 @@ public class ThreadSafeClientConnManager
|
|||
*/
|
||||
private class TrackingPoolEntry extends AbstractPoolEntry {
|
||||
|
||||
//@@@ move to base class
|
||||
/** The route for which this entry gets allocated. */
|
||||
private HostConfiguration plannedRoute;
|
||||
private HttpRoute plannedRoute;
|
||||
|
||||
/** The connection manager. */
|
||||
private ThreadSafeClientConnManager manager;
|
||||
|
|
|
@ -581,21 +581,4 @@ public class TestHttpRoute extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
// for completeness, although it's deprecated
|
||||
public void testHostConfig() {
|
||||
// these tests are sloppy, the method is scheduled for removal anyway
|
||||
HttpRoute route = new HttpRoute(TARGET1);
|
||||
assertNotNull("no host config", route.toHostConfig());
|
||||
|
||||
route = new HttpRoute(TARGET2, null, new HttpHost[]{ PROXY1, PROXY2 },
|
||||
false, false, false);
|
||||
try {
|
||||
route.toHostConfig();
|
||||
fail("proxy chain not detected");
|
||||
} catch (IllegalStateException isx) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // class TestHttpRoute
|
||||
|
|
|
@ -50,7 +50,7 @@ public class TestParams extends TestCase {
|
|||
public final static
|
||||
HttpHost TARGET1 = new HttpHost("target1.test.invalid");
|
||||
public final static
|
||||
HostConfiguration HOSTCFG1 = new HostConfiguration(TARGET1,null,null);
|
||||
HttpRoute ROUTE1 = new HttpRoute(TARGET1);
|
||||
|
||||
|
||||
public TestParams(String testName) {
|
||||
|
@ -82,7 +82,7 @@ public class TestParams extends TestCase {
|
|||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
setMaxConnectionsPerHost(null, HOSTCFG1, 3);
|
||||
setMaxConnectionsPerHost(null, ROUTE1, 3);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
|
@ -90,7 +90,7 @@ public class TestParams extends TestCase {
|
|||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
setMaxConnectionsPerHost(params, HOSTCFG1, 0);
|
||||
setMaxConnectionsPerHost(params, ROUTE1, 0);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
|
@ -108,7 +108,7 @@ public class TestParams extends TestCase {
|
|||
|
||||
try {
|
||||
HttpConnectionManagerParams.
|
||||
getMaxConnectionsPerHost(null, HOSTCFG1);
|
||||
getMaxConnectionsPerHost(null, ROUTE1);
|
||||
fail();
|
||||
} catch (IllegalArgumentException iax) {
|
||||
// expected
|
||||
|
@ -151,7 +151,7 @@ public class TestParams extends TestCase {
|
|||
getDefaultMaxConnectionsPerHost(params);
|
||||
|
||||
int fmcph = HttpConnectionManagerParams.
|
||||
getMaxConnectionsPerHost(params, HOSTCFG1);
|
||||
getMaxConnectionsPerHost(params, ROUTE1);
|
||||
|
||||
assertEquals(fdmcph, fmcph);
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class TestParams extends TestCase {
|
|||
|
||||
|
||||
int mcph = HttpConnectionManagerParams.
|
||||
getMaxConnectionsPerHost(params, HOSTCFG1);
|
||||
getMaxConnectionsPerHost(params, ROUTE1);
|
||||
assertEquals(ndmcph, mcph);
|
||||
}
|
||||
|
||||
|
|
|
@ -548,15 +548,6 @@ public class TestRouteTracker extends TestCase {
|
|||
rt = (RouteTracker) iter.next();
|
||||
final String rts = checkToString(rt);
|
||||
assertTrue("duplicate toString: " + rts, rtstrings.add(rts));
|
||||
|
||||
// it's scheduled for removal, but keep Clover happy...
|
||||
try {
|
||||
rt.toHostConfig();
|
||||
} catch (IllegalStateException isx) {
|
||||
if (rt.getHopCount() < 3)
|
||||
fail("could not get HostConfig for " + rt);
|
||||
// else expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ import junit.framework.TestSuite;
|
|||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
import org.apache.http.conn.HostConfiguration;
|
||||
import org.apache.http.conn.HttpRoute;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.conn.PlainSocketFactory;
|
||||
|
@ -236,13 +235,8 @@ public class TestTSCCMNoServer extends TestCase {
|
|||
HttpParams params = createDefaultParams();
|
||||
HttpConnectionManagerParams.setMaxTotalConnections(params, 100);
|
||||
HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost(params, 1);
|
||||
//@@@ HostConfiguration is deprecated
|
||||
//@@@ should it be mapped to HttpHost or HttpRoute here?
|
||||
//@@@ provide setter in TSCCM, it is implementation specific
|
||||
HttpConnectionManagerParams.setMaxConnectionsPerHost
|
||||
(params, route2.toHostConfig(), 2);
|
||||
HttpConnectionManagerParams.setMaxConnectionsPerHost
|
||||
(params, route3.toHostConfig(), 3);
|
||||
HttpConnectionManagerParams.setMaxConnectionsPerHost(params,route2, 2);
|
||||
HttpConnectionManagerParams.setMaxConnectionsPerHost(params,route3, 3);
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
||||
|
||||
|
@ -371,27 +365,26 @@ public class TestTSCCMNoServer extends TestCase {
|
|||
|
||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||
HttpRoute route = new HttpRoute(target, null, false);
|
||||
HostConfiguration hcfg = route.toHostConfig(); //@@@ deprecated
|
||||
|
||||
ManagedClientConnection conn = mgr.getConnection(route);
|
||||
|
||||
assertEquals("connectionsInPool",
|
||||
mgr.getConnectionsInPool(), 1);
|
||||
assertEquals("connectionsInPool(host)",
|
||||
mgr.getConnectionsInPool(hcfg), 1);
|
||||
mgr.getConnectionsInPool(route), 1);
|
||||
mgr.releaseConnection(conn);
|
||||
|
||||
assertEquals("connectionsInPool",
|
||||
mgr.getConnectionsInPool(), 1);
|
||||
assertEquals("connectionsInPool(host)",
|
||||
mgr.getConnectionsInPool(hcfg), 1);
|
||||
mgr.getConnectionsInPool(route), 1);
|
||||
|
||||
mgr.closeIdleConnections(0L); // implicitly deletes them, too
|
||||
|
||||
assertEquals("connectionsInPool",
|
||||
mgr.getConnectionsInPool(), 0);
|
||||
assertEquals("connectionsInPool(host)",
|
||||
mgr.getConnectionsInPool(hcfg), 0);
|
||||
mgr.getConnectionsInPool(route), 0);
|
||||
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue