Fixed context logging in BasicHttpClientConnectionManager
This commit is contained in:
parent
2404540f1f
commit
5875ca1c37
|
@ -93,8 +93,11 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BasicHttpClientConnectionManager.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BasicHttpClientConnectionManager.class);
|
||||||
|
|
||||||
|
private static final AtomicLong COUNT = new AtomicLong(0);
|
||||||
|
|
||||||
private final HttpClientConnectionOperator connectionOperator;
|
private final HttpClientConnectionOperator connectionOperator;
|
||||||
private final HttpConnectionFactory<ManagedHttpClientConnection> connFactory;
|
private final HttpConnectionFactory<ManagedHttpClientConnection> connFactory;
|
||||||
|
private final String id;
|
||||||
|
|
||||||
private ManagedHttpClientConnection conn;
|
private ManagedHttpClientConnection conn;
|
||||||
private HttpRoute route;
|
private HttpRoute route;
|
||||||
|
@ -131,6 +134,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
super();
|
super();
|
||||||
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator");
|
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator");
|
||||||
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
|
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
|
||||||
|
this.id = String.format("ep-%010d", COUNT.getAndIncrement());
|
||||||
this.expiry = Long.MAX_VALUE;
|
this.expiry = Long.MAX_VALUE;
|
||||||
this.socketConfig = SocketConfig.DEFAULT;
|
this.socketConfig = SocketConfig.DEFAULT;
|
||||||
this.closed = new AtomicBoolean(false);
|
this.closed = new AtomicBoolean(false);
|
||||||
|
@ -207,7 +211,9 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
|
|
||||||
private synchronized void closeConnection(final CloseMode closeMode) {
|
private synchronized void closeConnection(final CloseMode closeMode) {
|
||||||
if (this.conn != null) {
|
if (this.conn != null) {
|
||||||
LOG.debug("Closing connection {}", closeMode);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("{} Closing connection {}", id, closeMode);
|
||||||
|
}
|
||||||
this.conn.close(closeMode);
|
this.conn.close(closeMode);
|
||||||
this.conn = null;
|
this.conn = null;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +222,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
private void checkExpiry() {
|
private void checkExpiry() {
|
||||||
if (this.conn != null && System.currentTimeMillis() >= this.expiry) {
|
if (this.conn != null && System.currentTimeMillis() >= this.expiry) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Connection expired @ {}", new Date(this.expiry));
|
LOG.debug("{} Connection expired @ {}", id, new Date(this.expiry));
|
||||||
}
|
}
|
||||||
closeConnection(CloseMode.GRACEFUL);
|
closeConnection(CloseMode.GRACEFUL);
|
||||||
}
|
}
|
||||||
|
@ -225,7 +231,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
synchronized ManagedHttpClientConnection getConnection(final HttpRoute route, final Object state) throws IOException {
|
synchronized ManagedHttpClientConnection getConnection(final HttpRoute route, final Object state) throws IOException {
|
||||||
Asserts.check(!this.closed.get(), "Connection manager has been shut down");
|
Asserts.check(!this.closed.get(), "Connection manager has been shut down");
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Get connection for route {}", route);
|
LOG.debug("{} Get connection for route {}", id, route);
|
||||||
}
|
}
|
||||||
Asserts.check(!this.leased, "Connection is still allocated");
|
Asserts.check(!this.leased, "Connection is still allocated");
|
||||||
if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
|
if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
|
||||||
|
@ -254,9 +260,8 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
public synchronized void release(final ConnectionEndpoint endpoint, final Object state, final TimeValue keepAlive) {
|
public synchronized void release(final ConnectionEndpoint endpoint, final Object state, final TimeValue keepAlive) {
|
||||||
Args.notNull(endpoint, "Managed endpoint");
|
Args.notNull(endpoint, "Managed endpoint");
|
||||||
final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
|
final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
|
||||||
final String id = internalEndpoint.id;
|
|
||||||
final ManagedHttpClientConnection conn = internalEndpoint.detach();
|
final ManagedHttpClientConnection conn = internalEndpoint.detach();
|
||||||
if (conn != null && LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("{} Releasing connection {}", id, conn);
|
LOG.debug("{} Releasing connection {}", id, conn);
|
||||||
}
|
}
|
||||||
if (this.closed.get()) {
|
if (this.closed.get()) {
|
||||||
|
@ -360,18 +365,14 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final AtomicLong COUNT = new AtomicLong(0);
|
|
||||||
|
|
||||||
class InternalConnectionEndpoint extends ConnectionEndpoint {
|
class InternalConnectionEndpoint extends ConnectionEndpoint {
|
||||||
|
|
||||||
private final HttpRoute route;
|
private final HttpRoute route;
|
||||||
private final AtomicReference<ManagedHttpClientConnection> connRef;
|
private final AtomicReference<ManagedHttpClientConnection> connRef;
|
||||||
private final String id;
|
|
||||||
|
|
||||||
public InternalConnectionEndpoint(final HttpRoute route, final ManagedHttpClientConnection conn) {
|
public InternalConnectionEndpoint(final HttpRoute route, final ManagedHttpClientConnection conn) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
this.connRef = new AtomicReference<>(conn);
|
this.connRef = new AtomicReference<>(conn);
|
||||||
this.id = String.format("ep-%010d", COUNT.getAndIncrement());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRoute getRoute() {
|
HttpRoute getRoute() {
|
||||||
|
@ -432,7 +433,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
||||||
Args.notNull(request, "HTTP request");
|
Args.notNull(request, "HTTP request");
|
||||||
Args.notNull(requestExecutor, "Request executor");
|
Args.notNull(requestExecutor, "Request executor");
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("{} executing exchange {}", id, exchangeId);
|
LOG.debug("{} Executing exchange {}", id, exchangeId);
|
||||||
}
|
}
|
||||||
return requestExecutor.execute(request, getValidatedConnection(), context);
|
return requestExecutor.execute(request, getValidatedConnection(), context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue