deleted MTHCM and related classes, fixed bug in TSCCM
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@509672 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
924f8ddf3a
commit
a21767dc9e
|
@ -1,103 +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;
|
||||
|
||||
/**
|
||||
* "Old" connection manager interface, as ported from HttpClient 3.x.
|
||||
* @deprecated kept temporarily for reference. To be replaced by
|
||||
* {@link ClientConnectionManager}.
|
||||
*
|
||||
* @author Michael Becke
|
||||
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
|
||||
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface HttpConnectionManager {
|
||||
|
||||
/**
|
||||
* Gets an HttpConnection for a given host configuration. If a connection is
|
||||
* not available this method will block until one is.
|
||||
*
|
||||
* The connection manager should be registered with any HttpConnection that
|
||||
* is created.
|
||||
*
|
||||
* @param hostConfiguration the host configuration to use to configure the
|
||||
* connection
|
||||
*
|
||||
* @return an HttpConnection for the given configuration
|
||||
*/
|
||||
HttpHostConnection getConnection(HostConfiguration hostConfiguration);
|
||||
|
||||
/**
|
||||
* Gets an HttpConnection for a given host configuration. If a connection is
|
||||
* not available, this method will block for at most the specified number of
|
||||
* milliseconds or until a connection becomes available.
|
||||
*
|
||||
* The connection manager should be registered with any HttpConnection that
|
||||
* is created.
|
||||
*
|
||||
* @param hostConfiguration the host configuration to use to configure the
|
||||
* connection
|
||||
* @param timeout - the time (in milliseconds) to wait for a connection to
|
||||
* become available, 0 to specify an infinite timeout
|
||||
*
|
||||
* @return an HttpConnection for the given configuraiton
|
||||
*
|
||||
* @throws ConnectionPoolTimeoutException if no connection becomes available before the
|
||||
* timeout expires
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
HttpHostConnection getConnection(HostConfiguration hostConfiguration, long timeout)
|
||||
throws ConnectionPoolTimeoutException;
|
||||
|
||||
/**
|
||||
* Releases the given HttpConnection for use by other requests.
|
||||
*
|
||||
* @param conn - The HttpHostConnection to make available.
|
||||
*/
|
||||
void releaseConnection(HttpHostConnection conn);
|
||||
|
||||
/**
|
||||
* Closes connections that have been idle for at least the given amount of time. Only
|
||||
* connections that are currently owned, not checked out, are subject to idle timeouts.
|
||||
*
|
||||
* @param idleTimeout the minimum idle time, in milliseconds, for connections to be closed
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
void closeIdleConnections(long idleTimeout);
|
||||
|
||||
void shutdown();
|
||||
|
||||
}
|
|
@ -1,70 +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.io.IOException;
|
||||
import java.net.SocketException;
|
||||
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.HttpInetConnection;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
/**
|
||||
* "Old" connection interface, as ported from HttpClient 3.x.
|
||||
* @deprecated kept temporarily for reference. To be replaced by
|
||||
* {@link OperatedClientConnection} and
|
||||
* {@link ManagedClientConnection}.
|
||||
*/
|
||||
public interface HttpHostConnection extends HttpClientConnection, HttpInetConnection {
|
||||
|
||||
void setHttpConnectionManager(HttpConnectionManager manager);
|
||||
|
||||
HostConfiguration getHostConfiguration();
|
||||
|
||||
void open(HttpParams params) throws IOException;
|
||||
|
||||
void tunnelCreated(HttpParams params) throws IOException;
|
||||
|
||||
void setSocketTimeout(int timeout) throws SocketException;
|
||||
|
||||
HttpResponse getLastResponse();
|
||||
|
||||
void setLastResponse(HttpResponse response);
|
||||
|
||||
void setLocked(boolean locked);
|
||||
|
||||
boolean isLocked();
|
||||
|
||||
void releaseConnection();
|
||||
|
||||
}
|
|
@ -1,282 +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.impl.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.conn.HostConfiguration;
|
||||
import org.apache.http.conn.HttpConnectionManager;
|
||||
import org.apache.http.conn.HttpHostConnection;
|
||||
import org.apache.http.conn.Scheme;
|
||||
import org.apache.http.conn.SchemeRegistry;
|
||||
import org.apache.http.conn.SecureSocketFactory;
|
||||
import org.apache.http.conn.SocketFactory;
|
||||
import org.apache.http.impl.SocketHttpClientConnection;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
/**
|
||||
* Default {@link HttpHostConnection} implementation.
|
||||
*
|
||||
* @deprecated kept temporarily for reference. To be replaced by
|
||||
* {@link DefaultClientConnection} and
|
||||
* {@link AbstractClientConnectionAdapter}.
|
||||
*
|
||||
* @author Rod Waldhoff
|
||||
* @author Sean C. Sullivan
|
||||
* @author Ortwin Glueck
|
||||
* @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
|
||||
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
|
||||
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
|
||||
* @author Michael Becke
|
||||
* @author Eric E Johnson
|
||||
* @author Laura Werner
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class DefaultHttpHostConnection
|
||||
extends SocketHttpClientConnection implements HttpHostConnection {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(DefaultHttpHostConnection.class);
|
||||
|
||||
/** the connection manager that created this connection or null */
|
||||
private HttpConnectionManager manager;
|
||||
|
||||
private HostConfiguration hostconf;
|
||||
|
||||
/** flag to indicate if this connection can be released, if locked the connection cannot be
|
||||
* released */
|
||||
private boolean locked = false;
|
||||
|
||||
/** Whether the connection is open via a secure tunnel or not */
|
||||
private boolean tunnelEstablished = false;
|
||||
|
||||
private HttpResponse lastResponse;
|
||||
|
||||
public DefaultHttpHostConnection() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setHttpConnectionManager(final HttpConnectionManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public void setHostConfiguration(final HostConfiguration hostconf) {
|
||||
assertNotOpen();
|
||||
this.hostconf = hostconf;
|
||||
}
|
||||
|
||||
public HostConfiguration getHostConfiguration() {
|
||||
return this.hostconf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes a connection to the specified host and port
|
||||
* (via a proxy if specified).
|
||||
* The underlying socket is created from the {@link SocketFactory}.
|
||||
*
|
||||
* @throws IOException if an attempt to establish the connection results in an
|
||||
* I/O error.
|
||||
*/
|
||||
public void open(final HttpParams params)
|
||||
throws IllegalStateException, IOException {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
}
|
||||
assertNotOpen();
|
||||
if (this.hostconf == null) {
|
||||
throw new IllegalArgumentException("Host configuration is null");
|
||||
}
|
||||
|
||||
HttpHost host = this.hostconf.getHost();
|
||||
if (host == null) {
|
||||
throw new IllegalStateException("Target http host is null");
|
||||
}
|
||||
HttpHost proxyHost = this.hostconf.getProxyHost();
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
if (proxyHost == null) {
|
||||
LOG.debug("Open connection to " + host);
|
||||
} else {
|
||||
LOG.debug("Open connection to " + host + " via proxy " + proxyHost);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the type of the connection
|
||||
Scheme scheme = SchemeRegistry.DEFAULT.getScheme(host.getSchemeName());
|
||||
SocketFactory socketFactory = scheme.getSocketFactory();
|
||||
boolean secure = (socketFactory instanceof SecureSocketFactory);
|
||||
boolean proxied = (proxyHost != null);
|
||||
|
||||
// Determine the target host
|
||||
HttpHost target = null;
|
||||
if (proxyHost != null) {
|
||||
target = proxyHost;
|
||||
} else {
|
||||
target = host;
|
||||
}
|
||||
|
||||
// Create the socket
|
||||
String hostname = target.getHostName();
|
||||
int port = target.getPort();
|
||||
if (port < 0) {
|
||||
port = scheme.getDefaultPort();
|
||||
}
|
||||
if (secure && proxied) {
|
||||
scheme = SchemeRegistry.DEFAULT.getScheme("http");
|
||||
socketFactory = scheme.getSocketFactory();
|
||||
} else {
|
||||
scheme = SchemeRegistry.DEFAULT.getScheme(target.getSchemeName());
|
||||
}
|
||||
socketFactory = scheme.getSocketFactory();
|
||||
Socket socket = socketFactory.connectSocket(
|
||||
null, hostname, port,
|
||||
this.hostconf.getLocalAddress(), 0, params);
|
||||
|
||||
// Bind connection to the socket
|
||||
bind(socket, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the proxy to establish a secure tunnel to the host. The socket will
|
||||
* be switched to the secure socket. Subsequent communication is done via the secure
|
||||
* socket. The method can only be called once on a proxied secure connection.
|
||||
*
|
||||
* @throws IllegalStateException if connection is not secure and proxied or
|
||||
* if the socket is already secure.
|
||||
* @throws IOException if an attempt to establish the secure tunnel results in an
|
||||
* I/O error.
|
||||
*/
|
||||
public void tunnelCreated(final HttpParams params)
|
||||
throws IllegalStateException, IOException {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
}
|
||||
assertOpen();
|
||||
if (this.tunnelEstablished) {
|
||||
throw new IllegalStateException("Tunnel already established");
|
||||
}
|
||||
HttpHost host = this.hostconf.getHost();
|
||||
if (host == null) {
|
||||
throw new IllegalStateException("Target http host is null");
|
||||
}
|
||||
HttpHost proxyHost = this.hostconf.getProxyHost();
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Secure tunnel to " + host);
|
||||
}
|
||||
|
||||
Scheme scheme = SchemeRegistry.DEFAULT.getScheme(host.getSchemeName());
|
||||
SocketFactory socketFactory = scheme.getSocketFactory();
|
||||
boolean secure = (socketFactory instanceof SecureSocketFactory);
|
||||
boolean proxied = (proxyHost != null);
|
||||
|
||||
if (!secure || !proxied) {
|
||||
throw new IllegalStateException(
|
||||
"Connection must be secure "
|
||||
+ "and proxied to use this feature");
|
||||
}
|
||||
|
||||
String hostname = host.getHostName();
|
||||
int port = host.getPort();
|
||||
if (port < 0) {
|
||||
port = scheme.getDefaultPort();
|
||||
}
|
||||
SecureSocketFactory securesocketFactory = (SecureSocketFactory) socketFactory;
|
||||
|
||||
Socket tunnel = securesocketFactory.createSocket(
|
||||
this.socket, hostname, port, true);
|
||||
bind(tunnel, params);
|
||||
this.tunnelEstablished = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the httpConnectionManager.
|
||||
* @return HttpConnectionManager
|
||||
*/
|
||||
public HttpConnectionManager getHttpConnectionManager() {
|
||||
return this.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the connection. If the connection is locked or does not have a connection
|
||||
* manager associated with it, this method has no effect. Note that it is completely safe
|
||||
* to call this method multiple times.
|
||||
*/
|
||||
public void releaseConnection() {
|
||||
if (locked) {
|
||||
LOG.debug("Connection is locked. Call to releaseConnection() ignored.");
|
||||
} else if (this.manager != null) {
|
||||
LOG.debug("Releasing connection back to connection manager.");
|
||||
this.manager.releaseConnection(this);
|
||||
} else {
|
||||
LOG.warn("HttpConnectionManager is null. Connection cannot be released.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the connection is locked. Locked connections cannot be released.
|
||||
* An attempt to release a locked connection will have no effect.
|
||||
*
|
||||
* @return <tt>true</tt> if the connection is locked, <tt>false</tt> otherwise.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks or unlocks the connection. Locked connections cannot be released.
|
||||
* An attempt to release a locked connection will have no effect.
|
||||
*
|
||||
* @param locked <tt>true</tt> to lock the connection, <tt>false</tt> to unlock
|
||||
* the connection.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public HttpResponse getLastResponse() {
|
||||
return this.lastResponse;
|
||||
}
|
||||
|
||||
public void setLastResponse(final HttpResponse lastResponse) {
|
||||
this.lastResponse = lastResponse;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,234 +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.impl.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.conn.HostConfiguration;
|
||||
import org.apache.http.conn.HttpConnectionManager;
|
||||
import org.apache.http.conn.HttpHostConnection;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
/**
|
||||
* A connection manager that provides access to a single HttpConnection. This
|
||||
* manager makes no attempt to provide exclusive access to the contained
|
||||
* HttpConnection.
|
||||
* @deprecated To be adapted to the new connection handler interface.
|
||||
*
|
||||
* @author <a href="mailto:becke@u.washington.edu">Michael Becke</a>
|
||||
* @author Eric Johnson
|
||||
* @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 2.0
|
||||
*/
|
||||
public class SimpleHttpConnectionManager implements HttpConnectionManager {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(SimpleHttpConnectionManager.class);
|
||||
|
||||
private static final String MISUSE_MESSAGE =
|
||||
"SimpleHttpConnectionManager being used incorrectly. Be sure that"
|
||||
+ " HttpMethod.releaseConnection() is always called and that only one thread"
|
||||
+ " and/or method is using this connection manager at a time.";
|
||||
|
||||
/**
|
||||
* Since the same connection is about to be reused, make sure the
|
||||
* previous request was completely processed, and if not
|
||||
* consume it now.
|
||||
* @param conn The connection
|
||||
*/
|
||||
protected static void finishLastResponse(HttpHostConnection conn) {
|
||||
HttpResponse lastResponse = conn.getLastResponse();
|
||||
if (lastResponse != null) {
|
||||
conn.setLastResponse(null);
|
||||
HttpEntity entity = lastResponse.getEntity();
|
||||
if (entity != null) {
|
||||
try {
|
||||
entity.consumeContent();
|
||||
} catch (IOException ex) {
|
||||
LOG.debug("I/O error consuming response content", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The http connection */
|
||||
protected DefaultHttpHostConnection httpConnection;
|
||||
|
||||
/**
|
||||
* Collection of parameters associated with this connection manager.
|
||||
*/
|
||||
private HttpParams params = new BasicHttpParams();
|
||||
|
||||
/**
|
||||
* The time the connection was made idle.
|
||||
*/
|
||||
private long idleStartTime = Long.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Used to test if {@link #httpConnection} is currently in use
|
||||
* (i.e. checked out). This is only used as a sanity check to help
|
||||
* debug cases where this connection manager is being used incorrectly.
|
||||
* It will not be used to enforce thread safety.
|
||||
*/
|
||||
private volatile boolean inUse = false;
|
||||
|
||||
private boolean alwaysClose = false;
|
||||
|
||||
/**
|
||||
* The connection manager created with this constructor will try to keep the
|
||||
* connection open (alive) between consecutive requests if the alwaysClose
|
||||
* parameter is set to <tt>false</tt>. Otherwise the connection manager will
|
||||
* always close connections upon release.
|
||||
*
|
||||
* @param alwaysClose if set <tt>true</tt>, the connection manager will always
|
||||
* close connections upon release.
|
||||
*/
|
||||
public SimpleHttpConnectionManager(boolean alwaysClose) {
|
||||
super();
|
||||
this.alwaysClose = alwaysClose;
|
||||
}
|
||||
|
||||
/**
|
||||
* The connection manager created with this constructor will always try to keep
|
||||
* the connection open (alive) between consecutive requests.
|
||||
*/
|
||||
public SimpleHttpConnectionManager() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpConnectionManager#getConnection(HostConfiguration)
|
||||
*/
|
||||
public HttpHostConnection getConnection(HostConfiguration hostConfiguration) {
|
||||
return getConnection(hostConfiguration, 0);
|
||||
}
|
||||
|
||||
private void closeConnection() {
|
||||
try {
|
||||
this.httpConnection.close();
|
||||
} catch (IOException ex) {
|
||||
LOG.debug("I/O error closing connection", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method always returns the same connection object. If the connection is already
|
||||
* open, it will be closed and the new host configuration will be applied.
|
||||
*
|
||||
* @param hostConfiguration The host configuration specifying the connection
|
||||
* details.
|
||||
* @param timeout this parameter has no effect. The connection is always returned
|
||||
* immediately.
|
||||
* @since 3.0
|
||||
*/
|
||||
public HttpHostConnection getConnection(
|
||||
HostConfiguration hostConfiguration, long timeout) {
|
||||
|
||||
if (httpConnection == null) {
|
||||
httpConnection = new DefaultHttpHostConnection();
|
||||
httpConnection.setHttpConnectionManager(this);
|
||||
} else {
|
||||
// make sure the host and proxy are correct for this connection
|
||||
// close it and set the values if they are not
|
||||
if (!hostConfiguration.equals(httpConnection)) {
|
||||
if (httpConnection.isOpen()) {
|
||||
closeConnection();
|
||||
}
|
||||
httpConnection.setHostConfiguration(hostConfiguration);
|
||||
} else {
|
||||
finishLastResponse(httpConnection);
|
||||
}
|
||||
}
|
||||
|
||||
// remove the connection from the timeout handler
|
||||
idleStartTime = Long.MAX_VALUE;
|
||||
|
||||
if (inUse) LOG.warn(MISUSE_MESSAGE);
|
||||
inUse = true;
|
||||
|
||||
return httpConnection;
|
||||
}
|
||||
|
||||
// non-javadoc, see interface HttpConnectionManager
|
||||
public void releaseConnection(HttpHostConnection conn) {
|
||||
if (conn != httpConnection) {
|
||||
throw new IllegalStateException("Unexpected release of an unknown connection.");
|
||||
}
|
||||
if (this.alwaysClose) {
|
||||
closeConnection();
|
||||
} else {
|
||||
// make sure the connection is reuseable
|
||||
finishLastResponse(httpConnection);
|
||||
}
|
||||
|
||||
inUse = false;
|
||||
|
||||
// track the time the connection was made idle
|
||||
idleStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public HttpParams getParams() {
|
||||
return this.params;
|
||||
}
|
||||
|
||||
public void setParams(final HttpParams params) {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("Parameters may not be null");
|
||||
}
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.0
|
||||
*/
|
||||
public void closeIdleConnections(long idleTimeout) {
|
||||
long maxIdleTime = System.currentTimeMillis() - idleTimeout;
|
||||
if (idleStartTime <= maxIdleTime) {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* since 3.1
|
||||
*/
|
||||
public void shutdown() {
|
||||
closeConnection();
|
||||
}
|
||||
|
||||
}
|
|
@ -424,10 +424,10 @@ public class ThreadSafeClientConnManager
|
|||
synchronized (ALL_CONNECTION_MANAGERS) {
|
||||
// Don't use an iterator here. Iterators on WeakHashMap can
|
||||
// get ConcurrentModificationException on garbage collection.
|
||||
MultiThreadedHttpConnectionManager[]
|
||||
connManagers = (MultiThreadedHttpConnectionManager[])
|
||||
ThreadSafeClientConnManager[]
|
||||
connManagers = (ThreadSafeClientConnManager[])
|
||||
ALL_CONNECTION_MANAGERS.keySet().toArray(
|
||||
new MultiThreadedHttpConnectionManager
|
||||
new ThreadSafeClientConnManager
|
||||
[ALL_CONNECTION_MANAGERS.size()]
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue