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;
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) {

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 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;

View File

@ -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;

View File

@ -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);
}

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;

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.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;

View File

@ -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;

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.InputStream;
import org.apache.hc.client5.http.impl.Wire;
class LoggingInputStream extends InputStream {
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.OutputStream;
import org.apache.hc.client5.http.impl.Wire;
/**
* 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.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;

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.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<ConnectionSocketFactory> socketFactoryRegistry,
final HttpConnectionFactory<ManagedHttpClientConnection> 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<HttpRoute> connPoolListener,
final TimeValue timeToLive) {
this(new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver),
connFactory, poolReusePolicy, connPoolListener, timeToLive);
connFactory, poolReusePolicy, timeToLive);
}
public PoolingHttpClientConnectionManager(
final HttpClientConnectionOperator httpClientConnectionOperator,
final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
final PoolReusePolicy poolReusePolicy,
final ConnPoolListener<HttpRoute> 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);
}

View File

@ -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<HttpRoute> 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<HttpRoute> 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) {

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.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<HttpRoute> 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<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
this.poolEntryRef = new AtomicReference<>(poolEntry);
this.id = "ep-" + Long.toHexString(COUNT.incrementAndGet());
this.id = String.format("ep-%08X", COUNT.getAndIncrement());
}
@Override

View File

@ -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<HttpRoute> connPoolListener;
private boolean systemProperties;
@ -123,14 +120,6 @@ public class PoolingAsyncClientConnectionManagerBuilder {
return this;
}
/**
* Assigns {@link ConnPoolListener} instance.
*/
public final PoolingAsyncClientConnectionManagerBuilder setConnPoolListener(final ConnPoolListener<HttpRoute> 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);