From dcc09e92e0453efae2a3f1c2e22809c24052958a Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Fri, 1 Sep 2017 20:11:04 +0200 Subject: [PATCH] Logging improvements --- .../hc/client5/http/impl/ConnPoolSupport.java | 2 ++ .../hc/client5/http/impl/{logging => }/Wire.java | 8 +++++--- .../async/HttpAsyncClientEventHandlerFactory.java | 2 -- .../http/impl/async/InternalHttpAsyncClient.java | 2 +- .../impl/{logging => async}/LogAppendable.java | 2 +- .../impl/{logging => async}/LoggingIOSession.java | 5 +++-- .../io/DefaultManagedHttpClientConnection.java | 1 - .../impl/{logging => io}/LoggingInputStream.java | 4 +++- .../impl/{logging => io}/LoggingOutputStream.java | 4 +++- .../impl/{logging => io}/LoggingSocketHolder.java | 5 +++-- .../io/PoolingHttpClientConnectionManager.java | 13 +++++-------- .../PoolingHttpClientConnectionManagerBuilder.java | 12 ------------ .../nio/PoolingAsyncClientConnectionManager.java | 8 +++----- ...PoolingAsyncClientConnectionManagerBuilder.java | 14 +------------- 14 files changed, 30 insertions(+), 52 deletions(-) rename httpclient5/src/main/java/org/apache/hc/client5/http/impl/{logging => }/Wire.java (97%) rename httpclient5/src/main/java/org/apache/hc/client5/http/impl/{logging => async}/LogAppendable.java (98%) rename httpclient5/src/main/java/org/apache/hc/client5/http/impl/{logging => async}/LoggingIOSession.java (98%) rename httpclient5/src/main/java/org/apache/hc/client5/http/impl/{logging => io}/LoggingInputStream.java (97%) rename httpclient5/src/main/java/org/apache/hc/client5/http/impl/{logging => io}/LoggingOutputStream.java (97%) rename httpclient5/src/main/java/org/apache/hc/client5/http/impl/{logging => io}/LoggingSocketHolder.java (93%) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java index e6650a439..3de413c4d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java @@ -27,10 +27,12 @@ package org.apache.hc.client5.http.impl; import org.apache.hc.client5.http.HttpRoute; +import org.apache.hc.core5.annotation.Internal; import org.apache.hc.core5.pool.ConnPoolControl; import org.apache.hc.core5.pool.PoolStats; import org.apache.hc.core5.util.Identifiable; +@Internal public final class ConnPoolSupport { public static String getId(final Object object) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java similarity index 97% rename from httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java index 8bd9e4fe0..fd48ebd1f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java @@ -25,14 +25,16 @@ * */ -package org.apache.hc.client5.http.impl.logging; +package org.apache.hc.client5.http.impl; import java.nio.ByteBuffer; +import org.apache.hc.core5.annotation.Internal; import org.apache.hc.core5.util.Args; import org.apache.logging.log4j.Logger; -class Wire { +@Internal +public class Wire { private static final int MAX_STRING_BUILDER_SIZE = 2048; @@ -73,7 +75,7 @@ class Wire { private final Logger log; private final String id; - Wire(final Logger log, final String id) { + public Wire(final Logger log, final String id) { super(); this.log = log; this.id = id; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java index 1419b4427..95d9267ce 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java @@ -32,8 +32,6 @@ import java.util.Iterator; import java.util.List; import org.apache.hc.client5.http.impl.ConnPoolSupport; -import org.apache.hc.client5.http.impl.logging.LogAppendable; -import org.apache.hc.client5.http.impl.logging.LoggingIOSession; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.http.ConnectionReuseStrategy; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java index d00145819..c6f0d93a4 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java @@ -248,7 +248,7 @@ class InternalHttpAsyncClient extends AbstractHttpAsyncClientBase { final HttpHost target = routePlanner.determineTargetHost(request, clientContext); final HttpRoute route = routePlanner.determineRoute(target, clientContext); - final String exchangeId = "ex-" + Long.toHexString(ExecSupport.getNextExecNumber()); + final String exchangeId = String.format("ex-%08X", ExecSupport.getNextExecNumber()); final AsyncExecRuntime execRuntime = new AsyncExecRuntimeImpl(log, connmgr, getConnectionInitiator(), versionPolicy); executeChain(exchangeId, execChain, route, request, entityDetails, exchangeHandler, clientContext, execRuntime); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LogAppendable.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java similarity index 98% rename from httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LogAppendable.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java index 181bb9559..5d5070d08 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LogAppendable.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java @@ -25,7 +25,7 @@ * */ -package org.apache.hc.client5.http.impl.logging; +package org.apache.hc.client5.http.impl.async; import java.io.IOException; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java similarity index 98% rename from httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java index c750f7a9b..fad7f1eb5 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java @@ -25,7 +25,7 @@ * */ -package org.apache.hc.client5.http.impl.logging; +package org.apache.hc.client5.http.impl.async; import java.io.IOException; import java.net.SocketAddress; @@ -35,6 +35,7 @@ import java.nio.channels.SelectionKey; import javax.net.ssl.SSLContext; +import org.apache.hc.client5.http.impl.Wire; import org.apache.hc.core5.io.ShutdownType; import org.apache.hc.core5.reactor.Command; import org.apache.hc.core5.reactor.IOEventHandler; @@ -45,7 +46,7 @@ import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier; import org.apache.hc.core5.reactor.ssl.TlsDetails; import org.apache.logging.log4j.Logger; -public class LoggingIOSession implements TlsCapableIOSession { +class LoggingIOSession implements TlsCapableIOSession { private final Logger log; private final Wire wirelog; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java index ac412ffbf..52dea8639 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java @@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocket; -import org.apache.hc.client5.http.impl.logging.LoggingSocketHolder; import org.apache.hc.client5.http.io.ManagedHttpClientConnection; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpResponse; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java similarity index 97% rename from httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java index 018fae64e..69aded2bb 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java @@ -25,11 +25,13 @@ * */ -package org.apache.hc.client5.http.impl.logging; +package org.apache.hc.client5.http.impl.io; import java.io.IOException; import java.io.InputStream; +import org.apache.hc.client5.http.impl.Wire; + class LoggingInputStream extends InputStream { private final InputStream in; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java similarity index 97% rename from httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java index ec82d1fd7..7484ee35f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java @@ -25,11 +25,13 @@ * */ -package org.apache.hc.client5.http.impl.logging; +package org.apache.hc.client5.http.impl.io; import java.io.IOException; import java.io.OutputStream; +import org.apache.hc.client5.http.impl.Wire; + /** * Internal class. * diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java similarity index 93% rename from httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java index ddde402f8..b7aae7646 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java @@ -25,17 +25,18 @@ * */ -package org.apache.hc.client5.http.impl.logging; +package org.apache.hc.client5.http.impl.io; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; +import org.apache.hc.client5.http.impl.Wire; import org.apache.hc.core5.http.impl.io.SocketHolder; import org.apache.logging.log4j.Logger; -public class LoggingSocketHolder extends SocketHolder { +class LoggingSocketHolder extends SocketHolder { private final Wire wire; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java index 4dca6a785..ecb237eff 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java @@ -64,7 +64,6 @@ import org.apache.hc.core5.http.io.HttpConnectionFactory; import org.apache.hc.core5.http.protocol.HttpContext; import org.apache.hc.core5.io.ShutdownType; import org.apache.hc.core5.pool.ConnPoolControl; -import org.apache.hc.core5.pool.ConnPoolListener; import org.apache.hc.core5.pool.PoolEntry; import org.apache.hc.core5.pool.PoolReusePolicy; import org.apache.hc.core5.pool.PoolStats; @@ -128,7 +127,7 @@ public class PoolingHttpClientConnectionManager } public PoolingHttpClientConnectionManager(final TimeValue timeToLive) { - this(getDefaultRegistry(), null, null ,null, PoolReusePolicy.LIFO, null, timeToLive); + this(getDefaultRegistry(), null, null ,null, PoolReusePolicy.LIFO, timeToLive); } public PoolingHttpClientConnectionManager( @@ -157,7 +156,7 @@ public class PoolingHttpClientConnectionManager final Registry socketFactoryRegistry, final HttpConnectionFactory connFactory, final DnsResolver dnsResolver) { - this(socketFactoryRegistry, connFactory, null, dnsResolver, PoolReusePolicy.LIFO, null, TimeValue.NEG_ONE_MILLISECONDS); + this(socketFactoryRegistry, connFactory, null, dnsResolver, PoolReusePolicy.LIFO, TimeValue.NEG_ONE_MILLISECONDS); } public PoolingHttpClientConnectionManager( @@ -166,23 +165,21 @@ public class PoolingHttpClientConnectionManager final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final PoolReusePolicy poolReusePolicy, - final ConnPoolListener connPoolListener, final TimeValue timeToLive) { this(new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver), - connFactory, poolReusePolicy, connPoolListener, timeToLive); + connFactory, poolReusePolicy, timeToLive); } public PoolingHttpClientConnectionManager( final HttpClientConnectionOperator httpClientConnectionOperator, final HttpConnectionFactory connFactory, final PoolReusePolicy poolReusePolicy, - final ConnPoolListener connPoolListener, final TimeValue timeToLive) { super(); this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator"); this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE; - this.pool = new StrictConnPool<>( - DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive, poolReusePolicy, connPoolListener); + this.pool = new StrictConnPool<>(DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive, + poolReusePolicy, null); this.closed = new AtomicBoolean(false); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java index 76c36b3ae..0e3b5539b 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java @@ -28,7 +28,6 @@ package org.apache.hc.client5.http.impl.io; import org.apache.hc.client5.http.DnsResolver; -import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.SchemePortResolver; import org.apache.hc.client5.http.io.ManagedHttpClientConnection; import org.apache.hc.client5.http.socket.ConnectionSocketFactory; @@ -38,7 +37,6 @@ import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.config.SocketConfig; import org.apache.hc.core5.http.io.HttpConnectionFactory; -import org.apache.hc.core5.pool.ConnPoolListener; import org.apache.hc.core5.pool.PoolReusePolicy; import org.apache.hc.core5.util.TimeValue; @@ -75,7 +73,6 @@ public class PoolingHttpClientConnectionManagerBuilder { private SchemePortResolver schemePortResolver; private DnsResolver dnsResolver; private PoolReusePolicy poolReusePolicy; - private ConnPoolListener connPoolListener; private SocketConfig defaultSocketConfig; private boolean systemProperties; @@ -136,14 +133,6 @@ public class PoolingHttpClientConnectionManagerBuilder { return this; } - /** - * Assigns {@link ConnPoolListener} instance. - */ - public final PoolingHttpClientConnectionManagerBuilder setConnPoolListener(final ConnPoolListener connPoolListener) { - this.connPoolListener = connPoolListener; - return this; - } - /** * Assigns maximum total connection value. */ @@ -210,7 +199,6 @@ public class PoolingHttpClientConnectionManagerBuilder { schemePortResolver, dnsResolver, poolReusePolicy, - connPoolListener, timeToLive != null ? timeToLive : TimeValue.NEG_ONE_MILLISECONDS); poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity); if (defaultSocketConfig != null) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java index 59d37bb62..93ce8eb38 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java @@ -58,7 +58,6 @@ import org.apache.hc.core5.http2.nio.command.PingCommand; import org.apache.hc.core5.http2.nio.support.BasicPingHandler; import org.apache.hc.core5.io.ShutdownType; import org.apache.hc.core5.pool.ConnPoolControl; -import org.apache.hc.core5.pool.ConnPoolListener; import org.apache.hc.core5.pool.PoolEntry; import org.apache.hc.core5.pool.PoolReusePolicy; import org.apache.hc.core5.pool.PoolStats; @@ -106,10 +105,9 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final TimeValue timeToLive, - final PoolReusePolicy poolReusePolicy, - final ConnPoolListener connPoolListener) { + final PoolReusePolicy poolReusePolicy) { this.connectionOperator = new AsyncClientConnectionOperator(schemePortResolver, dnsResolver, tlsStrategyLookup); - this.pool = new StrictConnPool<>(20, 50, timeToLive, poolReusePolicy != null ? poolReusePolicy : PoolReusePolicy.LIFO, connPoolListener); + this.pool = new StrictConnPool<>(20, 50, timeToLive, poolReusePolicy != null ? poolReusePolicy : PoolReusePolicy.LIFO, null); this.closed = new AtomicBoolean(false); } @@ -400,7 +398,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio InternalConnectionEndpoint(final PoolEntry poolEntry) { this.poolEntryRef = new AtomicReference<>(poolEntry); - this.id = "ep-" + Long.toHexString(COUNT.incrementAndGet()); + this.id = String.format("ep-%08X", COUNT.getAndIncrement()); } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java index 9a840adba..ed2e42d20 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java @@ -31,12 +31,10 @@ import java.security.AccessController; import java.security.PrivilegedAction; import org.apache.hc.client5.http.DnsResolver; -import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.SchemePortResolver; import org.apache.hc.client5.http.ssl.H2TlsStrategy; import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.nio.ssl.TlsStrategy; -import org.apache.hc.core5.pool.ConnPoolListener; import org.apache.hc.core5.pool.PoolReusePolicy; import org.apache.hc.core5.util.TimeValue; @@ -72,7 +70,6 @@ public class PoolingAsyncClientConnectionManagerBuilder { private SchemePortResolver schemePortResolver; private DnsResolver dnsResolver; private PoolReusePolicy poolReusePolicy; - private ConnPoolListener connPoolListener; private boolean systemProperties; @@ -123,14 +120,6 @@ public class PoolingAsyncClientConnectionManagerBuilder { return this; } - /** - * Assigns {@link ConnPoolListener} instance. - */ - public final PoolingAsyncClientConnectionManagerBuilder setConnPoolListener(final ConnPoolListener connPoolListener) { - this.connPoolListener = connPoolListener; - return this; - } - /** * Assigns maximum total connection value. */ @@ -184,8 +173,7 @@ public class PoolingAsyncClientConnectionManagerBuilder { schemePortResolver, dnsResolver, timeToLive, - poolReusePolicy, - connPoolListener); + poolReusePolicy); poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity); if (maxConnTotal > 0) { poolingmgr.setMaxTotal(maxConnTotal);