HTTPCLIENT-1495: shut down standard connection managers only once
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1587883 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cd1f9fc9f7
commit
64fade92df
|
@ -32,6 +32,7 @@ import java.io.IOException;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -108,8 +109,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
@GuardedBy("this")
|
||||
private ConnectionConfig connConfig;
|
||||
|
||||
@GuardedBy("this")
|
||||
private volatile boolean shutdown;
|
||||
private final AtomicBoolean isShutdown;
|
||||
|
||||
private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
|
||||
return RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
|
@ -141,6 +141,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
this.expiry = Long.MAX_VALUE;
|
||||
this.socketConfig = SocketConfig.DEFAULT;
|
||||
this.connConfig = ConnectionConfig.DEFAULT;
|
||||
this.isShutdown = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
public BasicHttpClientConnectionManager(
|
||||
|
@ -256,7 +257,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
}
|
||||
|
||||
synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
|
||||
Asserts.check(!this.shutdown, "Connection manager has been shut down");
|
||||
Asserts.check(!this.isShutdown.get(), "Connection manager has been shut down");
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Get connection for route " + route);
|
||||
}
|
||||
|
@ -284,8 +285,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Releasing connection " + conn);
|
||||
}
|
||||
if (this.shutdown) {
|
||||
shutdownConnection();
|
||||
if (this.isShutdown.get()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -357,7 +357,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
|
||||
@Override
|
||||
public synchronized void closeExpiredConnections() {
|
||||
if (this.shutdown) {
|
||||
if (this.isShutdown.get()) {
|
||||
return;
|
||||
}
|
||||
if (!this.leased) {
|
||||
|
@ -368,7 +368,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
@Override
|
||||
public synchronized void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
Args.notNull(tunit, "Time unit");
|
||||
if (this.shutdown) {
|
||||
if (this.isShutdown.get()) {
|
||||
return;
|
||||
}
|
||||
if (!this.leased) {
|
||||
|
@ -385,11 +385,9 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
|
||||
@Override
|
||||
public synchronized void shutdown() {
|
||||
if (this.shutdown) {
|
||||
return;
|
||||
if (this.isShutdown.compareAndSet(false, true)) {
|
||||
shutdownConnection();
|
||||
}
|
||||
this.shutdown = true;
|
||||
shutdownConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -92,6 +93,7 @@ public class PoolingHttpClientConnectionManager
|
|||
private final ConfigData configData;
|
||||
private final CPool pool;
|
||||
private final HttpClientConnectionOperator connectionOperator;
|
||||
private final AtomicBoolean isShutDown;
|
||||
|
||||
private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
|
||||
return RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
|
@ -157,11 +159,12 @@ public class PoolingHttpClientConnectionManager
|
|||
final HttpClientConnectionOperator httpClientConnectionOperator,
|
||||
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
super();
|
||||
this.configData = new ConfigData();
|
||||
this.pool = new CPool(
|
||||
new InternalConnectionFactory(this.configData, connFactory), 2, 20, timeToLive, tunit);
|
||||
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "HttpClientConnectionOperator");
|
||||
super();
|
||||
this.configData = new ConfigData();
|
||||
this.pool = new CPool(new InternalConnectionFactory(
|
||||
this.configData, connFactory), 2, 20, timeToLive, tunit);
|
||||
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "HttpClientConnectionOperator");
|
||||
this.isShutDown = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,6 +180,7 @@ public class PoolingHttpClientConnectionManager
|
|||
this.pool = pool;
|
||||
this.connectionOperator = new DefaultHttpClientConnectionOperator(
|
||||
socketFactoryRegistry, schemePortResolver, dnsResolver);
|
||||
this.isShutDown = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -368,13 +372,15 @@ public class PoolingHttpClientConnectionManager
|
|||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
this.log.debug("Connection manager is shutting down");
|
||||
try {
|
||||
this.pool.shutdown();
|
||||
} catch (final IOException ex) {
|
||||
this.log.debug("I/O exception shutting down connection manager", ex);
|
||||
if (this.isShutDown.compareAndSet(false, true)) {
|
||||
this.log.debug("Connection manager is shutting down");
|
||||
try {
|
||||
this.pool.shutdown();
|
||||
} catch (final IOException 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
|
||||
|
|
Loading…
Reference in New Issue