"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java" between
httpcomponents-client-4.5.6-src.tar.gz and httpcomponents-client-4.5.7-src.tar.gz

About: HttpComponents is an Apache project responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols. Java sources.

PoolingHttpClientConnectionManager.java  (httpcomponents-client-4.5.6-src):PoolingHttpClientConnectionManager.java  (httpcomponents-client-4.5.7-src)
skipping to change at line 33 skipping to change at line 33
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
* *
*/ */
package org.apache.http.impl.conn; package org.apache.http.impl.conn;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpClientConnection; import org.apache.http.HttpClientConnection;
skipping to change at line 124 skipping to change at line 125
return RegistryBuilder.<ConnectionSocketFactory>create() return RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory( )) .register("http", PlainConnectionSocketFactory.getSocketFactory( ))
.register("https", SSLConnectionSocketFactory.getSocketFactory() ) .register("https", SSLConnectionSocketFactory.getSocketFactory() )
.build(); .build();
} }
public PoolingHttpClientConnectionManager() { public PoolingHttpClientConnectionManager() {
this(getDefaultRegistry()); this(getDefaultRegistry());
} }
public PoolingHttpClientConnectionManager(final long timeToLive, final TimeU public PoolingHttpClientConnectionManager(final long timeToLive, final TimeU
nit tunit) { nit timeUnit) {
this(getDefaultRegistry(), null, null ,null, timeToLive, tunit); this(getDefaultRegistry(), null, null ,null, timeToLive, timeUnit);
} }
public PoolingHttpClientConnectionManager( public PoolingHttpClientConnectionManager(
final Registry<ConnectionSocketFactory> socketFactoryRegistry) { final Registry<ConnectionSocketFactory> socketFactoryRegistry) {
this(socketFactoryRegistry, null, null); this(socketFactoryRegistry, null, null);
} }
public PoolingHttpClientConnectionManager( public PoolingHttpClientConnectionManager(
final Registry<ConnectionSocketFactory> socketFactoryRegistry, final Registry<ConnectionSocketFactory> socketFactoryRegistry,
final DnsResolver dnsResolver) { final DnsResolver dnsResolver) {
skipping to change at line 162 skipping to change at line 163
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
final DnsResolver dnsResolver) { final DnsResolver dnsResolver) {
this(socketFactoryRegistry, connFactory, null, dnsResolver, -1, TimeUnit .MILLISECONDS); this(socketFactoryRegistry, connFactory, null, dnsResolver, -1, TimeUnit .MILLISECONDS);
} }
public PoolingHttpClientConnectionManager( public PoolingHttpClientConnectionManager(
final Registry<ConnectionSocketFactory> socketFactoryRegistry, final Registry<ConnectionSocketFactory> socketFactoryRegistry,
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
final SchemePortResolver schemePortResolver, final SchemePortResolver schemePortResolver,
final DnsResolver dnsResolver, final DnsResolver dnsResolver,
final long timeToLive, final TimeUnit tunit) { final long timeToLive, final TimeUnit timeUnit) {
this( this(
new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schem ePortResolver, dnsResolver), new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schem ePortResolver, dnsResolver),
connFactory, connFactory,
timeToLive, tunit timeToLive, timeUnit
); );
} }
/** /**
* @since 4.4 * @since 4.4
*/ */
public PoolingHttpClientConnectionManager( public PoolingHttpClientConnectionManager(
final HttpClientConnectionOperator httpClientConnectionOperator, final HttpClientConnectionOperator httpClientConnectionOperator,
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> conn Factory, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> conn Factory,
final long timeToLive, final TimeUnit tunit) { final long timeToLive, final TimeUnit timeUnit) {
super(); super();
this.configData = new ConfigData(); this.configData = new ConfigData();
this.pool = new CPool(new InternalConnectionFactory( this.pool = new CPool(new InternalConnectionFactory(
this.configData, connFactory), 2, 20, timeToLive, tunit); this.configData, connFactory), 2, 20, timeToLive, timeUnit);
this.pool.setValidateAfterInactivity(2000); this.pool.setValidateAfterInactivity(2000);
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Ht tpClientConnectionOperator"); this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Ht tpClientConnectionOperator");
this.isShutDown = new AtomicBoolean(false); this.isShutDown = new AtomicBoolean(false);
} }
/** /**
* Visible for test. * Visible for test.
*/ */
PoolingHttpClientConnectionManager( PoolingHttpClientConnectionManager(
final CPool pool, final CPool pool,
skipping to change at line 278 skipping to change at line 279
return new ConnectionRequest() { return new ConnectionRequest() {
@Override @Override
public boolean cancel() { public boolean cancel() {
return future.cancel(true); return future.cancel(true);
} }
@Override @Override
public HttpClientConnection get( public HttpClientConnection get(
final long timeout, final long timeout,
final TimeUnit tunit) throws InterruptedException, Execution final TimeUnit timeUnit) throws InterruptedException, Execut
Exception, ConnectionPoolTimeoutException { ionException, ConnectionPoolTimeoutException {
final HttpClientConnection conn = leaseConnection(future, timeou final HttpClientConnection conn = leaseConnection(future, timeou
t, tunit); t, timeUnit);
if (conn.isOpen()) { if (conn.isOpen()) {
final HttpHost host; final HttpHost host;
if (route.getProxyHost() != null) { if (route.getProxyHost() != null) {
host = route.getProxyHost(); host = route.getProxyHost();
} else { } else {
host = route.getTargetHost(); host = route.getTargetHost();
} }
final SocketConfig socketConfig = resolveSocketConfig(host); final SocketConfig socketConfig = resolveSocketConfig(host);
conn.setSocketTimeout(socketConfig.getSoTimeout()); conn.setSocketTimeout(socketConfig.getSoTimeout());
} }
return conn; return conn;
} }
}; };
} }
protected HttpClientConnection leaseConnection( protected HttpClientConnection leaseConnection(
final Future<CPoolEntry> future, final Future<CPoolEntry> future,
final long timeout, final long timeout,
final TimeUnit tunit) throws InterruptedException, ExecutionExceptio n, ConnectionPoolTimeoutException { final TimeUnit timeUnit) throws InterruptedException, ExecutionExcep tion, ConnectionPoolTimeoutException {
final CPoolEntry entry; final CPoolEntry entry;
try { try {
entry = future.get(timeout, tunit); entry = future.get(timeout, timeUnit);
if (entry == null || future.isCancelled()) { if (entry == null || future.isCancelled()) {
throw new InterruptedException(); throw new ExecutionException(new CancellationException("Operatio n cancelled"));
} }
Asserts.check(entry.getConnection() != null, "Pool entry with no con nection"); Asserts.check(entry.getConnection() != null, "Pool entry with no con nection");
if (this.log.isDebugEnabled()) { if (this.log.isDebugEnabled()) {
this.log.debug("Connection leased: " + format(entry) + formatSta ts(entry.getRoute())); this.log.debug("Connection leased: " + format(entry) + formatSta ts(entry.getRoute()));
} }
return CPoolProxy.newProxy(entry); return CPoolProxy.newProxy(entry);
} catch (final TimeoutException ex) { } catch (final TimeoutException ex) {
throw new ConnectionPoolTimeoutException("Timeout waiting for connec tion from pool"); throw new ConnectionPoolTimeoutException("Timeout waiting for connec tion from pool");
} }
} }
@Override @Override
public void releaseConnection( public void releaseConnection(
final HttpClientConnection managedConn, final HttpClientConnection managedConn,
final Object state, final Object state,
final long keepalive, final TimeUnit tunit) { final long keepalive, final TimeUnit timeUnit) {
Args.notNull(managedConn, "Managed connection"); Args.notNull(managedConn, "Managed connection");
synchronized (managedConn) { synchronized (managedConn) {
final CPoolEntry entry = CPoolProxy.detach(managedConn); final CPoolEntry entry = CPoolProxy.detach(managedConn);
if (entry == null) { if (entry == null) {
return; return;
} }
final ManagedHttpClientConnection conn = entry.getConnection(); final ManagedHttpClientConnection conn = entry.getConnection();
try { try {
if (conn.isOpen()) { if (conn.isOpen()) {
final TimeUnit effectiveUnit = tunit != null ? tunit : TimeU nit.MILLISECONDS; final TimeUnit effectiveUnit = timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS;
entry.setState(state); entry.setState(state);
entry.updateExpiry(keepalive, effectiveUnit); entry.updateExpiry(keepalive, effectiveUnit);
if (this.log.isDebugEnabled()) { if (this.log.isDebugEnabled()) {
final String s; final String s;
if (keepalive > 0) { if (keepalive > 0) {
s = "for " + (double) effectiveUnit.toMillis(keepali ve) / 1000 + " seconds"; s = "for " + (double) effectiveUnit.toMillis(keepali ve) / 1000 + " seconds";
} else { } else {
s = "indefinitely"; s = "indefinitely";
} }
this.log.debug("Connection " + format(entry) + " can be kept alive " + s); this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
skipping to change at line 419 skipping to change at line 420
try { try {
this.pool.shutdown(); this.pool.shutdown();
} catch (final IOException ex) { } catch (final IOException ex) {
this.log.debug("I/O exception shutting down connection manager", ex); this.log.debug("I/O exception shutting down connection manager", ex);
} }
this.log.debug("Connection manager shut down"); this.log.debug("Connection manager shut down");
} }
} }
@Override @Override
public void closeIdleConnections(final long idleTimeout, final TimeUnit tuni t) { public void closeIdleConnections(final long idleTimeout, final TimeUnit time Unit) {
if (this.log.isDebugEnabled()) { if (this.log.isDebugEnabled()) {
this.log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit); this.log.debug("Closing connections idle longer than " + idleTimeout + " " + timeUnit);
} }
this.pool.closeIdle(idleTimeout, tunit); this.pool.closeIdle(idleTimeout, timeUnit);
} }
@Override @Override
public void closeExpiredConnections() { public void closeExpiredConnections() {
this.log.debug("Closing expired connections"); this.log.debug("Closing expired connections");
this.pool.closeExpired(); this.pool.closeExpired();
} }
protected void enumAvailable(final PoolEntryCallback<HttpRoute, ManagedHttpC lientConnection> callback) { protected void enumAvailable(final PoolEntryCallback<HttpRoute, ManagedHttpC lientConnection> callback) {
this.pool.enumAvailable(callback); this.pool.enumAvailable(callback);
 End of changes. 15 change blocks. 
19 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)