Skip to content
Permalink
Browse files
Fixed context logging in BasicHttpClientConnectionManager
  • Loading branch information
ok2c committed Mar 15, 2021
1 parent 2404540 commit 5875ca1c37e2cf9e1d283158e7ecc3b0d03afe70
Showing 1 changed file with 11 additions and 10 deletions.
@@ -93,8 +93,11 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan

private static final Logger LOG = LoggerFactory.getLogger(BasicHttpClientConnectionManager.class);

private static final AtomicLong COUNT = new AtomicLong(0);

private final HttpClientConnectionOperator connectionOperator;
private final HttpConnectionFactory<ManagedHttpClientConnection> connFactory;
private final String id;

private ManagedHttpClientConnection conn;
private HttpRoute route;
@@ -131,6 +134,7 @@ public BasicHttpClientConnectionManager(
super();
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator");
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
this.id = String.format("ep-%010d", COUNT.getAndIncrement());
this.expiry = Long.MAX_VALUE;
this.socketConfig = SocketConfig.DEFAULT;
this.closed = new AtomicBoolean(false);
@@ -207,7 +211,9 @@ public boolean cancel() {

private synchronized void closeConnection(final CloseMode closeMode) {
if (this.conn != null) {
LOG.debug("Closing connection {}", closeMode);
if (LOG.isDebugEnabled()) {
LOG.debug("{} Closing connection {}", id, closeMode);
}
this.conn.close(closeMode);
this.conn = null;
}
@@ -216,7 +222,7 @@ private synchronized void closeConnection(final CloseMode closeMode) {
private void checkExpiry() {
if (this.conn != null && System.currentTimeMillis() >= this.expiry) {
if (LOG.isDebugEnabled()) {
LOG.debug("Connection expired @ {}", new Date(this.expiry));
LOG.debug("{} Connection expired @ {}", id, new Date(this.expiry));
}
closeConnection(CloseMode.GRACEFUL);
}
@@ -225,7 +231,7 @@ private void checkExpiry() {
synchronized ManagedHttpClientConnection getConnection(final HttpRoute route, final Object state) throws IOException {
Asserts.check(!this.closed.get(), "Connection manager has been shut down");
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");
if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
@@ -254,9 +260,8 @@ private InternalConnectionEndpoint cast(final ConnectionEndpoint endpoint) {
public synchronized void release(final ConnectionEndpoint endpoint, final Object state, final TimeValue keepAlive) {
Args.notNull(endpoint, "Managed endpoint");
final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
final String id = internalEndpoint.id;
final ManagedHttpClientConnection conn = internalEndpoint.detach();
if (conn != null && LOG.isDebugEnabled()) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} Releasing connection {}", id, conn);
}
if (this.closed.get()) {
@@ -360,18 +365,14 @@ public synchronized void closeIdle(final TimeValue idleTime) {
}
}

private static final AtomicLong COUNT = new AtomicLong(0);

class InternalConnectionEndpoint extends ConnectionEndpoint {

private final HttpRoute route;
private final AtomicReference<ManagedHttpClientConnection> connRef;
private final String id;

public InternalConnectionEndpoint(final HttpRoute route, final ManagedHttpClientConnection conn) {
this.route = route;
this.connRef = new AtomicReference<>(conn);
this.id = String.format("ep-%010d", COUNT.getAndIncrement());
}

HttpRoute getRoute() {
@@ -432,7 +433,7 @@ public ClassicHttpResponse execute(
Args.notNull(request, "HTTP request");
Args.notNull(requestExecutor, "Request executor");
if (LOG.isDebugEnabled()) {
LOG.debug("{} executing exchange {}", id, exchangeId);
LOG.debug("{} Executing exchange {}", id, exchangeId);
}
return requestExecutor.execute(request, getValidatedConnection(), context);
}

0 comments on commit 5875ca1

Please sign in to comment.