Logging improvements

This commit is contained in:
Oleg Kalnichevski 2017-09-01 20:11:04 +02:00
parent b58e7d46d7
commit dcc09e92e0
14 changed files with 30 additions and 52 deletions

View File

@ -27,10 +27,12 @@
package org.apache.hc.client5.http.impl; package org.apache.hc.client5.http.impl;
import org.apache.hc.client5.http.HttpRoute; 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.ConnPoolControl;
import org.apache.hc.core5.pool.PoolStats; import org.apache.hc.core5.pool.PoolStats;
import org.apache.hc.core5.util.Identifiable; import org.apache.hc.core5.util.Identifiable;
@Internal
public final class ConnPoolSupport { public final class ConnPoolSupport {
public static String getId(final Object object) { public static String getId(final Object object) {

View File

@ -25,14 +25,16 @@
* *
*/ */
package org.apache.hc.client5.http.impl.logging; package org.apache.hc.client5.http.impl;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.util.Args; import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
class Wire { @Internal
public class Wire {
private static final int MAX_STRING_BUILDER_SIZE = 2048; private static final int MAX_STRING_BUILDER_SIZE = 2048;
@ -73,7 +75,7 @@ class Wire {
private final Logger log; private final Logger log;
private final String id; private final String id;
Wire(final Logger log, final String id) { public Wire(final Logger log, final String id) {
super(); super();
this.log = log; this.log = log;
this.id = id; this.id = id;

View File

@ -32,8 +32,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.hc.client5.http.impl.ConnPoolSupport; 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.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.ConnectionReuseStrategy; import org.apache.hc.core5.http.ConnectionReuseStrategy;

View File

@ -248,7 +248,7 @@ class InternalHttpAsyncClient extends AbstractHttpAsyncClientBase {
final HttpHost target = routePlanner.determineTargetHost(request, clientContext); final HttpHost target = routePlanner.determineTargetHost(request, clientContext);
final HttpRoute route = routePlanner.determineRoute(target, 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); final AsyncExecRuntime execRuntime = new AsyncExecRuntimeImpl(log, connmgr, getConnectionInitiator(), versionPolicy);
executeChain(exchangeId, execChain, route, request, entityDetails, exchangeHandler, clientContext, execRuntime); executeChain(exchangeId, execChain, route, request, entityDetails, exchangeHandler, clientContext, execRuntime);
} }

View File

@ -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.io.IOException;

View File

@ -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.io.IOException;
import java.net.SocketAddress; import java.net.SocketAddress;
@ -35,6 +35,7 @@ import java.nio.channels.SelectionKey;
import javax.net.ssl.SSLContext; 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.io.ShutdownType;
import org.apache.hc.core5.reactor.Command; import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.IOEventHandler; 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.hc.core5.reactor.ssl.TlsDetails;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
public class LoggingIOSession implements TlsCapableIOSession { class LoggingIOSession implements TlsCapableIOSession {
private final Logger log; private final Logger log;
private final Wire wirelog; private final Wire wirelog;

View File

@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket; 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.client5.http.io.ManagedHttpClientConnection;
import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.ClassicHttpResponse;

View File

@ -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.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.apache.hc.client5.http.impl.Wire;
class LoggingInputStream extends InputStream { class LoggingInputStream extends InputStream {
private final InputStream in; private final InputStream in;

View File

@ -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.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.hc.client5.http.impl.Wire;
/** /**
* Internal class. * Internal class.
* *

View File

@ -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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import org.apache.hc.client5.http.impl.Wire;
import org.apache.hc.core5.http.impl.io.SocketHolder; import org.apache.hc.core5.http.impl.io.SocketHolder;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
public class LoggingSocketHolder extends SocketHolder { class LoggingSocketHolder extends SocketHolder {
private final Wire wire; private final Wire wire;

View File

@ -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.http.protocol.HttpContext;
import org.apache.hc.core5.io.ShutdownType; import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.pool.ConnPoolControl; 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.PoolEntry;
import org.apache.hc.core5.pool.PoolReusePolicy; import org.apache.hc.core5.pool.PoolReusePolicy;
import org.apache.hc.core5.pool.PoolStats; import org.apache.hc.core5.pool.PoolStats;
@ -128,7 +127,7 @@ public class PoolingHttpClientConnectionManager
} }
public PoolingHttpClientConnectionManager(final TimeValue timeToLive) { public PoolingHttpClientConnectionManager(final TimeValue timeToLive) {
this(getDefaultRegistry(), null, null ,null, PoolReusePolicy.LIFO, null, timeToLive); this(getDefaultRegistry(), null, null ,null, PoolReusePolicy.LIFO, timeToLive);
} }
public PoolingHttpClientConnectionManager( public PoolingHttpClientConnectionManager(
@ -157,7 +156,7 @@ public class PoolingHttpClientConnectionManager
final Registry<ConnectionSocketFactory> socketFactoryRegistry, final Registry<ConnectionSocketFactory> socketFactoryRegistry,
final HttpConnectionFactory<ManagedHttpClientConnection> connFactory, final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
final DnsResolver dnsResolver) { 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( public PoolingHttpClientConnectionManager(
@ -166,23 +165,21 @@ public class PoolingHttpClientConnectionManager
final SchemePortResolver schemePortResolver, final SchemePortResolver schemePortResolver,
final DnsResolver dnsResolver, final DnsResolver dnsResolver,
final PoolReusePolicy poolReusePolicy, final PoolReusePolicy poolReusePolicy,
final ConnPoolListener<HttpRoute> connPoolListener,
final TimeValue timeToLive) { final TimeValue timeToLive) {
this(new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver), this(new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver),
connFactory, poolReusePolicy, connPoolListener, timeToLive); connFactory, poolReusePolicy, timeToLive);
} }
public PoolingHttpClientConnectionManager( public PoolingHttpClientConnectionManager(
final HttpClientConnectionOperator httpClientConnectionOperator, final HttpClientConnectionOperator httpClientConnectionOperator,
final HttpConnectionFactory<ManagedHttpClientConnection> connFactory, final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
final PoolReusePolicy poolReusePolicy, final PoolReusePolicy poolReusePolicy,
final ConnPoolListener<HttpRoute> connPoolListener,
final TimeValue timeToLive) { final TimeValue timeToLive) {
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.pool = new StrictConnPool<>( this.pool = new StrictConnPool<>(DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive,
DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive, poolReusePolicy, connPoolListener); poolReusePolicy, null);
this.closed = new AtomicBoolean(false); this.closed = new AtomicBoolean(false);
} }

View File

@ -28,7 +28,6 @@
package org.apache.hc.client5.http.impl.io; package org.apache.hc.client5.http.impl.io;
import org.apache.hc.client5.http.DnsResolver; 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.SchemePortResolver;
import org.apache.hc.client5.http.io.ManagedHttpClientConnection; import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
import org.apache.hc.client5.http.socket.ConnectionSocketFactory; 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.RegistryBuilder;
import org.apache.hc.core5.http.config.SocketConfig; import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.io.HttpConnectionFactory; 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.pool.PoolReusePolicy;
import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.TimeValue;
@ -75,7 +73,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
private SchemePortResolver schemePortResolver; private SchemePortResolver schemePortResolver;
private DnsResolver dnsResolver; private DnsResolver dnsResolver;
private PoolReusePolicy poolReusePolicy; private PoolReusePolicy poolReusePolicy;
private ConnPoolListener<HttpRoute> connPoolListener;
private SocketConfig defaultSocketConfig; private SocketConfig defaultSocketConfig;
private boolean systemProperties; private boolean systemProperties;
@ -136,14 +133,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
return this; return this;
} }
/**
* Assigns {@link ConnPoolListener} instance.
*/
public final PoolingHttpClientConnectionManagerBuilder setConnPoolListener(final ConnPoolListener<HttpRoute> connPoolListener) {
this.connPoolListener = connPoolListener;
return this;
}
/** /**
* Assigns maximum total connection value. * Assigns maximum total connection value.
*/ */
@ -210,7 +199,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
schemePortResolver, schemePortResolver,
dnsResolver, dnsResolver,
poolReusePolicy, poolReusePolicy,
connPoolListener,
timeToLive != null ? timeToLive : TimeValue.NEG_ONE_MILLISECONDS); timeToLive != null ? timeToLive : TimeValue.NEG_ONE_MILLISECONDS);
poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity); poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);
if (defaultSocketConfig != null) { if (defaultSocketConfig != null) {

View File

@ -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.http2.nio.support.BasicPingHandler;
import org.apache.hc.core5.io.ShutdownType; import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.pool.ConnPoolControl; 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.PoolEntry;
import org.apache.hc.core5.pool.PoolReusePolicy; import org.apache.hc.core5.pool.PoolReusePolicy;
import org.apache.hc.core5.pool.PoolStats; import org.apache.hc.core5.pool.PoolStats;
@ -106,10 +105,9 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
final SchemePortResolver schemePortResolver, final SchemePortResolver schemePortResolver,
final DnsResolver dnsResolver, final DnsResolver dnsResolver,
final TimeValue timeToLive, final TimeValue timeToLive,
final PoolReusePolicy poolReusePolicy, final PoolReusePolicy poolReusePolicy) {
final ConnPoolListener<HttpRoute> connPoolListener) {
this.connectionOperator = new AsyncClientConnectionOperator(schemePortResolver, dnsResolver, tlsStrategyLookup); 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); this.closed = new AtomicBoolean(false);
} }
@ -400,7 +398,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
InternalConnectionEndpoint(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) { InternalConnectionEndpoint(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
this.poolEntryRef = new AtomicReference<>(poolEntry); this.poolEntryRef = new AtomicReference<>(poolEntry);
this.id = "ep-" + Long.toHexString(COUNT.incrementAndGet()); this.id = String.format("ep-%08X", COUNT.getAndIncrement());
} }
@Override @Override

View File

@ -31,12 +31,10 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import org.apache.hc.client5.http.DnsResolver; 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.SchemePortResolver;
import org.apache.hc.client5.http.ssl.H2TlsStrategy; import org.apache.hc.client5.http.ssl.H2TlsStrategy;
import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.config.RegistryBuilder;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy; 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.pool.PoolReusePolicy;
import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.TimeValue;
@ -72,7 +70,6 @@ public class PoolingAsyncClientConnectionManagerBuilder {
private SchemePortResolver schemePortResolver; private SchemePortResolver schemePortResolver;
private DnsResolver dnsResolver; private DnsResolver dnsResolver;
private PoolReusePolicy poolReusePolicy; private PoolReusePolicy poolReusePolicy;
private ConnPoolListener<HttpRoute> connPoolListener;
private boolean systemProperties; private boolean systemProperties;
@ -123,14 +120,6 @@ public class PoolingAsyncClientConnectionManagerBuilder {
return this; return this;
} }
/**
* Assigns {@link ConnPoolListener} instance.
*/
public final PoolingAsyncClientConnectionManagerBuilder setConnPoolListener(final ConnPoolListener<HttpRoute> connPoolListener) {
this.connPoolListener = connPoolListener;
return this;
}
/** /**
* Assigns maximum total connection value. * Assigns maximum total connection value.
*/ */
@ -184,8 +173,7 @@ public class PoolingAsyncClientConnectionManagerBuilder {
schemePortResolver, schemePortResolver,
dnsResolver, dnsResolver,
timeToLive, timeToLive,
poolReusePolicy, poolReusePolicy);
connPoolListener);
poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity); poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);
if (maxConnTotal > 0) { if (maxConnTotal > 0) {
poolingmgr.setMaxTotal(maxConnTotal); poolingmgr.setMaxTotal(maxConnTotal);