hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [2/5] httpcomponents-core git commit: Improved logging in integration test classes
Date Sun, 18 Jun 2017 19:17:25 GMT
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
index 35a79a8..9b793a9 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
@@ -70,6 +70,8 @@ import org.junit.runners.Parameterized;
 @RunWith(Parameterized.class)
 public class Http2ServerAndRequesterTest {
 
+    private final Logger log = LogManager.getLogger(getClass());
+
     @Parameterized.Parameters(name = "{0}")
     public static Collection<Object[]> protocols() {
         return Arrays.asList(new Object[][]{
@@ -94,12 +96,16 @@ public class Http2ServerAndRequesterTest {
 
         @Override
         protected void before() throws Throwable {
+            log.debug("Starting up test server");
             server = H2ServerBootstrap.bootstrap()
                     .setVersionPolicy(versionPolicy)
                     .setIOReactorConfig(
                             IOReactorConfig.custom()
                                     .setSoTimeout(TIMEOUT)
                                     .build())
+                    .setConnectionListener(LoggingConnectionListener.INSTANCE)
+                    .setStreamListener(LoggingHttp1StreamListener.INSTANCE_SERVER)
+                    .setIOSessionDecorator(LoggingIOSessionDecorator.INSTANCE)
                     .register("*", new Supplier<AsyncServerExchangeHandler>() {
 
                         @Override
@@ -113,13 +119,13 @@ public class Http2ServerAndRequesterTest {
 
         @Override
         protected void after() {
+            log.debug("Shutting down test server");
             if (server != null) {
                 try {
                     server.shutdown(ShutdownType.GRACEFUL);
                     final List<ExceptionEvent> exceptionLog = server.getExceptionLog();
                     server = null;
                     if (!exceptionLog.isEmpty()) {
-                        final Logger log = LogManager.getLogger(getClass());
                         for (final ExceptionEvent event: exceptionLog) {
                             final Throwable cause = event.getCause();
                             log.error("Unexpected " + cause.getClass() + " at " + event.getTimestamp(),
cause);
@@ -139,23 +145,28 @@ public class Http2ServerAndRequesterTest {
 
         @Override
         protected void before() throws Throwable {
+            log.debug("Starting up test client");
             requester = H2RequesterBootstrap.bootstrap()
                     .setVersionPolicy(versionPolicy)
                     .setIOReactorConfig(IOReactorConfig.custom()
                             .setSoTimeout(TIMEOUT)
                             .build())
+                    .setConnectionListener(LoggingConnectionListener.INSTANCE)
+                    .setStreamListener(LoggingHttp1StreamListener.INSTANCE_CLIENT)
+                    .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
+                    .setIOSessionDecorator(LoggingIOSessionDecorator.INSTANCE)
                     .create();
         }
 
         @Override
         protected void after() {
+            log.debug("Shutting down test client");
             if (requester != null) {
                 try {
                     requester.shutdown(ShutdownType.GRACEFUL);
                     final List<ExceptionEvent> exceptionLog = requester.getExceptionLog();
                     requester = null;
                     if (!exceptionLog.isEmpty()) {
-                        final Logger log = LogManager.getLogger(getClass());
                         for (final ExceptionEvent event: exceptionLog) {
                             final Throwable cause = event.getCause();
                             log.error("Unexpected " + cause.getClass() + " at " + event.getTimestamp(),
cause);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
index 975fe16..7d78b59 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
@@ -60,6 +60,7 @@ public abstract class InternalHttp1ServerTestBase {
 
         @Override
         protected void before() throws Throwable {
+            log.debug("Starting up test server");
             server = new Http1TestServer(
                     IOReactorConfig.DEFAULT,
                     scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext()
: null);
@@ -67,6 +68,7 @@ public abstract class InternalHttp1ServerTestBase {
 
         @Override
         protected void after() {
+            log.debug("Shutting down test server");
             if (server != null) {
                 try {
                     server.shutdown(TimeValue.ofSeconds(5));

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
index 65f51e2..786d3f7 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
@@ -60,12 +60,14 @@ public abstract class InternalHttp2ServerTestBase {
 
         @Override
         protected void before() throws Throwable {
+            log.debug("Starting up test server");
             server = new Http2TestServer(IOReactorConfig.DEFAULT,
                     scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext()
: null);
         }
 
         @Override
         protected void after() {
+            log.debug("Shutting down test server");
             if (server != null) {
                 try {
                     server.shutdown(TimeValue.ofSeconds(5));

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
index dda109d..66b3533 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
@@ -92,7 +92,7 @@ public class TestDefaultListeningIOReactor {
         final IOReactorConfig reactorConfig = IOReactorConfig.custom()
                 .setIoThreadCount(1)
                 .build();
-        this.ioreactor = new DefaultListeningIOReactor(new NoopIOEventHandlerFactory(), reactorConfig,
null, null, null);
+        this.ioreactor = new DefaultListeningIOReactor(new NoopIOEventHandlerFactory(), reactorConfig,
null);
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java
new file mode 100644
index 0000000..cdfd699
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java
@@ -0,0 +1,39 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.function;
+
+/**
+ * Abstract decorator.
+ *
+ * @since 5.0
+ */
+public interface Decorator<T> {
+
+    T decorate(T object);
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
index 92a39e3..60c1dc9 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
@@ -36,6 +36,7 @@ import java.util.concurrent.Future;
 import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.io.ShutdownType;
@@ -58,11 +59,13 @@ public class AsyncRequester implements IOReactorService, ConnectionInitiator
{
     public AsyncRequester(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig ioReactorConfig,
+            final Decorator<IOSession> ioSessionDecorator,
             final Callback<IOSession> sessionShutdownCallback) {
         this.ioReactor = new DefaultConnectingIOReactor(
                 eventHandlerFactory,
                 ioReactorConfig,
                 new DefaultThreadFactory("requester-dispatch", true),
+                ioSessionDecorator,
                 sessionShutdownCallback);
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
index a728d43..a524816 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
@@ -26,6 +26,7 @@
  */
 package org.apache.hc.core5.http.impl.bootstrap;
 
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.CharCodingConfig;
@@ -61,6 +62,7 @@ public class AsyncRequesterBootstrap {
     private TimeValue timeToLive;
     private ConnPoolPolicy connPoolPolicy;
     private TlsStrategy tlsStrategy;
+    private Decorator<IOSession> ioSessionDecorator;
     private ConnectionListener connectionListener;
     private Http1StreamListener streamListener;
     private ConnPoolListener<HttpHost> connPoolListener;
@@ -144,6 +146,14 @@ public class AsyncRequesterBootstrap {
     }
 
     /**
+     * Assigns {@link IOSession} {@link Decorator} instance.
+     */
+    public final AsyncRequesterBootstrap setIOSessionDecorator(final Decorator<IOSession>
ioSessionDecorator) {
+        this.ioSessionDecorator = ioSessionDecorator;
+        return this;
+    }
+
+    /**
      * Assigns {@link ConnectionListener} instance.
      */
     public final AsyncRequesterBootstrap setConnectionListener(final ConnectionListener connectionListener)
{
@@ -183,11 +193,11 @@ public class AsyncRequesterBootstrap {
                 null,
                 connectionListener,
                 streamListener);
-        final IOEventHandlerFactory ioEventHandlerFactory = new ClientHttp1IOEventHandlerFactory(
-                streamDuplexerFactory);
+        final IOEventHandlerFactory ioEventHandlerFactory = new ClientHttp1IOEventHandlerFactory(streamDuplexerFactory);
         return new HttpAsyncRequester(
                 ioReactorConfig,
                 ioEventHandlerFactory,
+                ioSessionDecorator,
                 connPool,
                 tlsStrategy != null ? tlsStrategy : new BasicClientTlsStrategy());
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
index 7555c53..33a9815 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
@@ -36,6 +36,7 @@ import java.util.concurrent.Future;
 import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.reactor.ConnectionAcceptor;
@@ -57,12 +58,14 @@ public class AsyncServer implements IOReactorService, ConnectionInitiator,
Conne
     public AsyncServer(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig ioReactorConfig,
+            final Decorator<IOSession> ioSessionDecorator,
             final Callback<IOSession> sessionShutdownCallback) {
         this.ioReactor = new DefaultListeningIOReactor(
                 eventHandlerFactory,
                 ioReactorConfig,
                 new DefaultThreadFactory("server-dispatch", true),
                 new DefaultThreadFactory("server-listener", true),
+                ioSessionDecorator,
                 sessionShutdownCallback);
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
index 213fb73..b43e71b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
@@ -29,6 +29,7 @@ package org.apache.hc.core5.http.impl.bootstrap;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.config.CharCodingConfig;
@@ -52,10 +53,11 @@ import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.util.Args;
 
 /**
- * @since 4.4
+ * @since 5.0
  */
 public class AsyncServerBootstrap {
 
@@ -67,6 +69,7 @@ public class AsyncServerBootstrap {
     private HttpProcessor httpProcessor;
     private ConnectionReuseStrategy connStrategy;
     private TlsStrategy tlsStrategy;
+    private Decorator<IOSession> ioSessionDecorator;
     private ConnectionListener connectionListener;
     private Http1StreamListener streamListener;
 
@@ -137,6 +140,14 @@ public class AsyncServerBootstrap {
     }
 
     /**
+     * Assigns {@link IOSession} {@link Decorator} instance.
+     */
+    public final AsyncServerBootstrap setIOSessionDecorator(final Decorator<IOSession>
ioSessionDecorator) {
+        this.ioSessionDecorator = ioSessionDecorator;
+        return this;
+    }
+
+    /**
      * Assigns {@link ConnectionListener} instance.
      */
     public final AsyncServerBootstrap setConnectionListener(final ConnectionListener connectionListener)
{
@@ -221,7 +232,7 @@ public class AsyncServerBootstrap {
         final IOEventHandlerFactory ioEventHandlerFactory = new ServerHttp1IOEventHandlerFactory(
                 streamHandlerFactory,
                 tlsStrategy != null ? tlsStrategy : new BasicServerTlsStrategy(new int[]
{443, 8443}));
-        return new HttpAsyncServer(ioEventHandlerFactory, ioReactorConfig);
+        return new HttpAsyncServer(ioEventHandlerFactory, ioSessionDecorator, ioReactorConfig);
     }
 
     private static class HandlerEntry {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
index 6bda913..c8c4cf6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
@@ -37,6 +37,7 @@ import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.concurrent.ComplexFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
@@ -80,9 +81,10 @@ public class HttpAsyncRequester extends AsyncRequester {
     public HttpAsyncRequester(
             final IOReactorConfig ioReactorConfig,
             final IOEventHandlerFactory eventHandlerFactory,
+            final Decorator<IOSession> ioSessionDecorator,
             final ControlledConnPool<HttpHost, IOSession> connPool,
             final TlsStrategy tlsStrategy) {
-        super(eventHandlerFactory, ioReactorConfig, new Callback<IOSession>() {
+        super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, new Callback<IOSession>()
{
 
             @Override
             public void execute(final IOSession session) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
index 2475d59..43b22e0 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
@@ -27,6 +27,7 @@
 package org.apache.hc.core5.http.impl.bootstrap;
 
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.nio.command.ShutdownCommand;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -40,8 +41,9 @@ public class HttpAsyncServer extends AsyncServer {
 
     public HttpAsyncServer(
             final IOEventHandlerFactory eventHandlerFactory,
+            final Decorator<IOSession> ioSessionDecorator,
             final IOReactorConfig ioReactorConfig) {
-        super(eventHandlerFactory, ioReactorConfig, new Callback<IOSession>() {
+        super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, new Callback<IOSession>()
{
 
             @Override
             public void execute(final IOSession session) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
index 197ed1c..29a2f5f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
@@ -69,7 +69,6 @@ import org.apache.hc.core5.http.nio.SessionOutputBuffer;
 import org.apache.hc.core5.http.nio.command.ExecutionCommand;
 import org.apache.hc.core5.http.nio.command.ShutdownCommand;
 import org.apache.hc.core5.io.ShutdownType;
-import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.EventMask;
 import org.apache.hc.core5.reactor.IOEventHandler;
@@ -79,9 +78,10 @@ import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
 import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Identifiable;
 
 abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage, OutgoingMessage
extends HttpMessage>
-        implements ResourceHolder, UpgradeableHttpConnection {
+        implements Identifiable, ResourceHolder, UpgradeableHttpConnection {
 
     private enum ConnectionState { READY, ACTIVE, GRACEFUL_SHUTDOWN, SHUTDOWN}
 
@@ -133,6 +133,11 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends
HttpMessage,
         this.connState = ConnectionState.READY;
     }
 
+    @Override
+    public String getId() {
+        return ioSession.getId();
+    }
+
     void shutdownSession(final ShutdownType shutdownType) {
         if (shutdownType == ShutdownType.GRACEFUL) {
             connState = ConnectionState.GRACEFUL_SHUTDOWN;
@@ -612,15 +617,4 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends
HttpMessage,
         ioSession.setHandler(eventHandler);
     }
 
-    @Override
-    public String toString() {
-        final SocketAddress remoteAddress = ioSession.getRemoteAddress();
-        final SocketAddress localAddress = ioSession.getLocalAddress();
-        final StringBuilder buffer = new StringBuilder();
-        InetAddressUtils.formatAddress(buffer, localAddress);
-        buffer.append("->");
-        InetAddressUtils.formatAddress(buffer, remoteAddress);
-        return buffer.toString();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
index f5a55fc..b5578a7 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
@@ -64,6 +64,7 @@ import org.apache.hc.core5.http.nio.command.ExecutionCommand;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
@@ -396,4 +397,13 @@ public class ClientHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
         return outgoing != null && outgoing.handleTimeout();
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder();
+        InetAddressUtils.formatAddress(buffer, getLocalAddress());
+        buffer.append("->");
+        InetAddressUtils.formatAddress(buffer, getRemoteAddress());
+        return buffer.toString();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
index 86461d2..abaad96 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
@@ -63,6 +63,7 @@ import org.apache.hc.core5.http.nio.command.ExecutionCommand;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
@@ -401,6 +402,15 @@ public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
         return false;
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder();
+        InetAddressUtils.formatAddress(buffer, getRemoteAddress());
+        buffer.append("->");
+        InetAddressUtils.formatAddress(buffer, getLocalAddress());
+        return buffer.toString();
+    }
+
     private static class DelayedOutputChannel implements Http1StreamChannel<HttpResponse>
{
 
         private final Http1StreamChannel<HttpResponse> channel;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
index a1be6b1..5d41dfe 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
@@ -41,6 +41,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.util.Args;
@@ -63,12 +64,13 @@ public class DefaultConnectingIOReactor implements IOReactorService, ConnectionI
     private final MultiCoreIOReactor ioReactor;
     private final AtomicInteger currentWorker;
 
-    private final static ThreadFactory THREAD_FACTORY = new DefaultThreadFactory("I/O dispatch",
true);
+    private final static ThreadFactory THREAD_FACTORY = new DefaultThreadFactory("I/O client
dispatch", true);
 
     public DefaultConnectingIOReactor(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig ioReactorConfig,
             final ThreadFactory threadFactory,
+            final Decorator<IOSession> ioSessionDecorator,
             final Callback<IOSession> sessionShutdownCallback) {
         Args.notNull(eventHandlerFactory, "Event handler factory");
         this.auditLog = new ConcurrentLinkedDeque<>();
@@ -80,6 +82,7 @@ public class DefaultConnectingIOReactor implements IOReactorService, ConnectionI
                     auditLog,
                     eventHandlerFactory,
                     ioReactorConfig,
+                    ioSessionDecorator,
                     sessionShutdownCallback);
             this.dispatchers[i] = dispatcher;
             threads[i] = (threadFactory != null ? threadFactory : THREAD_FACTORY).newThread(new
IOReactorWorker(dispatcher));
@@ -92,7 +95,7 @@ public class DefaultConnectingIOReactor implements IOReactorService, ConnectionI
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig config,
             final Callback<IOSession> sessionShutdownCallback) {
-        this(eventHandlerFactory, config, null, sessionShutdownCallback);
+        this(eventHandlerFactory, config, null, null, sessionShutdownCallback);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
index 3f618e1..770c319 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
@@ -43,6 +43,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.util.Args;
@@ -59,7 +60,7 @@ import org.apache.hc.core5.util.TimeValue;
  */
 public class DefaultListeningIOReactor implements IOReactorService, ConnectionInitiator,
ConnectionAcceptor {
 
-    private final static ThreadFactory DISPATCH_THREAD_FACTORY = new DefaultThreadFactory("I/O
dispatch", true);
+    private final static ThreadFactory DISPATCH_THREAD_FACTORY = new DefaultThreadFactory("I/O
server dispatch", true);
     private final static ThreadFactory LISTENER_THREAD_FACTORY = new DefaultThreadFactory("I/O
listener", true);
 
     private final Deque<ExceptionEvent> auditLog;
@@ -86,6 +87,7 @@ public class DefaultListeningIOReactor implements IOReactorService, ConnectionIn
             final IOReactorConfig ioReactorConfig,
             final ThreadFactory dispatchThreadFactory,
             final ThreadFactory listenerThreadFactory,
+            final Decorator<IOSession> ioSessionDecorator,
             final Callback<IOSession> sessionShutdownCallback) {
         Args.notNull(eventHandlerFactory, "Event handler factory");
         this.auditLog = new ConcurrentLinkedDeque<>();
@@ -97,6 +99,7 @@ public class DefaultListeningIOReactor implements IOReactorService, ConnectionIn
                     auditLog,
                     eventHandlerFactory,
                     ioReactorConfig,
+                    ioSessionDecorator,
                     sessionShutdownCallback);
             this.dispatchers[i] = dispatcher;
             threads[i + 1] = (dispatchThreadFactory != null ? dispatchThreadFactory : DISPATCH_THREAD_FACTORY).newThread(new
IOReactorWorker(dispatcher));
@@ -131,7 +134,7 @@ public class DefaultListeningIOReactor implements IOReactorService, ConnectionIn
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig config,
             final Callback<IOSession> sessionShutdownCallback) {
-        this(eventHandlerFactory, config, null, null, sessionShutdownCallback);
+        this(eventHandlerFactory, config, null, null, null, sessionShutdownCallback);
     }
 
     /**
@@ -142,7 +145,7 @@ public class DefaultListeningIOReactor implements IOReactorService, ConnectionIn
      * @since 5.0
      */
     public DefaultListeningIOReactor(final IOEventHandlerFactory eventHandlerFactory) {
-        this(eventHandlerFactory, null, null, null, null);
+        this(eventHandlerFactory, null, null, null, null, null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
index 1188d07..08abfb2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
@@ -69,7 +69,7 @@ class IOSessionImpl implements IOSession {
         this.commandQueue = new ConcurrentLinkedDeque<>();
         this.socketTimeout = 0;
         this.eventMask = new AtomicInteger(key.interestOps());
-        this.id = "i/o-" + Long.toHexString(COUNT.incrementAndGet());
+        this.id = String.format("i/o-%08X", COUNT.getAndIncrement());
         this.status = new AtomicInteger(ACTIVE);
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
index def406d..40f8510 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
@@ -31,7 +31,6 @@ import java.io.IOException;
 import java.net.SocketAddress;
 import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
 import java.util.Queue;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
@@ -59,11 +58,10 @@ final class InternalDataChannel extends InternalChannel implements TlsCapableIOS
     private final AtomicBoolean closed;
 
     InternalDataChannel(
-            final SelectionKey key,
-            final SocketChannel socketChannel,
+            final IOSession ioSession,
             final NamedEndpoint namedEndpoint,
             final Queue<InternalDataChannel> closedSessions) {
-        this.ioSession = new IOSessionImpl(key, socketChannel);
+        this.ioSession = ioSession;
         this.namedEndpoint = namedEndpoint;
         this.closedSessions = closedSessions;
         this.tlsSessionRef = new AtomicReference<>(null);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41b47a5e/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
index 9bca4fd..0793ca7 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
@@ -45,6 +45,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.hc.core5.concurrent.ComplexFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.util.Args;
@@ -54,11 +55,12 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements
Connect
 
     private final IOEventHandlerFactory eventHandlerFactory;
     private final IOReactorConfig reactorConfig;
+    private final Decorator<IOSession> ioSessionDecorator;
+    private final Callback<IOSession> sessionShutdownCallback;
     private final Queue<InternalDataChannel> closedSessions;
     private final Queue<SocketChannel> channelQueue;
     private final Queue<IOSessionRequest> requestQueue;
     private final AtomicBoolean shutdownInitiated;
-    private final Callback<IOSession> sessionShutdownCallback;
 
     private volatile long lastTimeoutCheck;
 
@@ -66,10 +68,12 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements
Connect
             final Queue<ExceptionEvent> auditLog,
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig reactorConfig,
+            final Decorator<IOSession> ioSessionDecorator,
             final Callback<IOSession> sessionShutdownCallback) {
         super(auditLog);
         this.eventHandlerFactory = Args.notNull(eventHandlerFactory, "Event handler factory");
         this.reactorConfig = Args.notNull(reactorConfig, "I/O reactor config");
+        this.ioSessionDecorator = ioSessionDecorator;
         this.sessionShutdownCallback = sessionShutdownCallback;
         this.shutdownInitiated = new AtomicBoolean(false);
         this.closedSessions = new ConcurrentLinkedQueue<>();
@@ -191,7 +195,11 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements
Connect
             } catch (final ClosedChannelException ex) {
                 return;
             }
-            final InternalDataChannel dataChannel = new InternalDataChannel(key, socketChannel,
null, closedSessions);
+            IOSession ioSession = new IOSessionImpl(key, socketChannel);
+            if (ioSessionDecorator != null) {
+                ioSession = ioSessionDecorator.decorate(ioSession);
+            }
+            final InternalDataChannel dataChannel = new InternalDataChannel(ioSession, null,
closedSessions);
             dataChannel.setHandler(this.eventHandlerFactory.createHandler(dataChannel, null));
             dataChannel.setSocketTimeout(this.reactorConfig.getSoTimeout().toMillisIntBound());
             key.attach(dataChannel);
@@ -314,7 +322,11 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements
Connect
                     final SocketChannel socketChannel,
                     final NamedEndpoint namedEndpoint,
                     final Object attachment) {
-                final InternalDataChannel dataChannel = new InternalDataChannel(key, socketChannel,
namedEndpoint, closedSessions);
+                IOSession ioSession = new IOSessionImpl(key, socketChannel);
+                if (ioSessionDecorator != null) {
+                    ioSession = ioSessionDecorator.decorate(ioSession);
+                }
+                final InternalDataChannel dataChannel = new InternalDataChannel(ioSession,
namedEndpoint, closedSessions);
                 dataChannel.setHandler(eventHandlerFactory.createHandler(dataChannel, attachment));
                 dataChannel.setSocketTimeout(reactorConfig.getSoTimeout().toMillisIntBound());
                 return dataChannel;


Mime
View raw message