Added more state info to #toString output of HTTP/1.1 and HTTP/2 async protocol handlers
authorOleg Kalnichevski <olegk@apache.org>
Tue, 20 Nov 2018 10:30:28 +0000 (11:30 +0100)
committerOleg Kalnichevski <olegk@apache.org>
Tue, 20 Nov 2018 10:48:24 +0000 (11:48 +0100)
20 files changed:
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2IOEventHandler.java
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2IOEventHandler.java
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexer.java
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandler.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandler.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionRequest.java
httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java

index 7efa809..c66da29 100644 (file)
@@ -43,7 +43,7 @@ import org.apache.hc.core5.util.Timeout;
 
 class AbstractHttp2IOEventHandler implements HttpConnectionEventHandler {
 
-    private final AbstractHttp2StreamMultiplexer streamMultiplexer;
+    final AbstractHttp2StreamMultiplexer streamMultiplexer;
 
     AbstractHttp2IOEventHandler(final AbstractHttp2StreamMultiplexer streamMultiplexer) {
         this.streamMultiplexer = Args.notNull(streamMultiplexer, "Stream multiplexer");
@@ -145,8 +145,4 @@ class AbstractHttp2IOEventHandler implements HttpConnectionEventHandler {
         return streamMultiplexer.getLocalAddress();
     }
 
-    @Override
-    public String toString() {
-        return streamMultiplexer.toString();
-    }
 }
index 6d2cd3c..0615a83 100644 (file)
@@ -1242,6 +1242,15 @@ abstract class AbstractHttp2StreamMultiplexer implements Identifiable, HttpConne
         return ioSession.getLocalAddress();
     }
 
+    void dumpState(final StringBuilder buf) {
+        buf.append("connState=").append(connState)
+                .append(", connInputWindow=").append(connInputWindow)
+                .append(", connOutputWindow=").append(connOutputWindow)
+                .append(", outputQueue=").append(outputQueue.size())
+                .append(", streamMap=").append(streamMap.size())
+                .append(", processedRemoteStreamId=").append(processedRemoteStreamId);
+    }
+
     private static class Continuation {
 
         final int streamId;
@@ -1458,15 +1467,22 @@ abstract class AbstractHttp2StreamMultiplexer implements Identifiable, HttpConne
             }
         }
 
+        void dumpState(final StringBuilder buf) {
+            buf.append("id=").append(id)
+                    .append(", connState=").append(connState)
+                    .append(", inputWindow=").append(inputWindow)
+                    .append(", outputWindow=").append(outputWindow)
+                    .append(", localEndStream=").append(localEndStream)
+                    .append(", idle=").append(idle);
+        }
+
         @Override
         public String toString() {
-            return "[" +
-                    "id=" + id +
-                    ", inputWindow=" + inputWindow +
-                    ", outputWindow=" + outputWindow +
-                    ", remoteEndStream=" + remoteEndStream +
-                    ", localEndStream=" + localEndStream +
-                    ']';
+            final StringBuilder buf = new StringBuilder();
+            buf.append("[");
+            dumpState(buf);
+            buf.append("]");
+            return buf.toString();
         }
 
     }
@@ -1603,9 +1619,19 @@ abstract class AbstractHttp2StreamMultiplexer implements Identifiable, HttpConne
             channel.requestOutput();
         }
 
+        void dumpState(final StringBuilder buf) {
+            buf.append("channel=[");
+            channel.dumpState(buf);
+            buf.append("]");
+        }
+
         @Override
         public String toString() {
-            return channel.toString();
+            final StringBuilder buf = new StringBuilder();
+            buf.append("[");
+            dumpState(buf);
+            buf.append("]");
+            return buf.toString();
         }
 
     }
index 7503d27..f8632ae 100644 (file)
@@ -27,6 +27,8 @@
 
 package org.apache.hc.core5.http2.impl.nio;
 
+import org.apache.hc.core5.net.InetAddressUtils;
+
 /**
  * {@link org.apache.hc.core5.reactor.IOEventHandler} that implements
  * client side HTTP/2 messaging protocol with full support for
@@ -40,4 +42,16 @@ public class ClientHttp2IOEventHandler extends AbstractHttp2IOEventHandler {
         super(streamMultiplexer);
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder buf = new StringBuilder();
+        InetAddressUtils.formatAddress(buf, getLocalAddress());
+        buf.append("->");
+        InetAddressUtils.formatAddress(buf, getRemoteAddress());
+        buf.append(" [");
+        streamMultiplexer.dumpState(buf);
+        buf.append("]");
+        return buf.toString();
+    }
+
 }
index 1f51a72..997a709 100644 (file)
@@ -44,7 +44,6 @@ import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
 import org.apache.hc.core5.http2.frame.FrameFactory;
 import org.apache.hc.core5.http2.frame.StreamIdGenerator;
-import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.ProtocolIOSession;
 
 /**
@@ -138,11 +137,11 @@ public class ClientHttp2StreamMultiplexer extends AbstractHttp2StreamMultiplexer
 
     @Override
     public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        InetAddressUtils.formatAddress(buffer, getLocalAddress());
-        buffer.append("->");
-        InetAddressUtils.formatAddress(buffer, getRemoteAddress());
-        return buffer.toString();
+        final StringBuilder buf = new StringBuilder();
+        buf.append("[");
+        dumpState(buf);
+        buf.append("]");
+        return buf.toString();
     }
 
 }
index 7934b76..003f118 100644 (file)
@@ -261,4 +261,11 @@ public class ClientHttpProtocolNegotiator implements HttpConnectionEventHandler
         ioSession.close(closeMode);
     }
 
+    @Override
+    public String toString() {
+        return "[" +
+                "versionPolicy=" + versionPolicy +
+                ']';
+    }
+
 }
index bbd5c5c..73a0507 100644 (file)
@@ -27,6 +27,8 @@
 
 package org.apache.hc.core5.http2.impl.nio;
 
+import org.apache.hc.core5.net.InetAddressUtils;
+
 /**
  * {@link org.apache.hc.core5.reactor.IOEventHandler} that implements
  * server side HTTP/2 messaging protocol with full support for
@@ -40,4 +42,16 @@ public class ServerHttp2IOEventHandler extends AbstractHttp2IOEventHandler{
         super(streamMultiplexer);
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder buf = new StringBuilder();
+        InetAddressUtils.formatAddress(buf, getRemoteAddress());
+        buf.append("->");
+        InetAddressUtils.formatAddress(buf, getLocalAddress());
+        buf.append(" [");
+        streamMultiplexer.dumpState(buf);
+        buf.append("]");
+        return buf.toString();
+    }
+
 }
index e2fbc4d..336080c 100644 (file)
@@ -43,7 +43,6 @@ import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
 import org.apache.hc.core5.http2.frame.FrameFactory;
 import org.apache.hc.core5.http2.frame.StreamIdGenerator;
-import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.ProtocolIOSession;
 import org.apache.hc.core5.util.Args;
 
@@ -116,11 +115,11 @@ public class ServerHttp2StreamMultiplexer extends AbstractHttp2StreamMultiplexer
 
     @Override
     public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        InetAddressUtils.formatAddress(buffer, getRemoteAddress());
-        buffer.append("->");
-        InetAddressUtils.formatAddress(buffer, getLocalAddress());
-        return buffer.toString();
+        final StringBuilder buf = new StringBuilder();
+        buf.append("[");
+        dumpState(buf);
+        buf.append("]");
+        return buf.toString();
     }
 
 }
index f5d2315..3c811b7 100644 (file)
@@ -231,4 +231,12 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
         ioSession.close(closeMode);
     }
 
+    @Override
+    public String toString() {
+        return "[" +
+                "versionPolicy=" + versionPolicy +
+                ", expectValidH2Preface=" + expectValidH2Preface +
+                ']';
+    }
+
 }
index 564095c..20b3401 100644 (file)
@@ -142,7 +142,8 @@ public class AsyncReverseProxyExample {
 
                     @Override
                     public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
-                        System.out.println("[proxy<-origin] connection " + connection +
+                        System.out.println("[proxy<-origin] connection " +
+                                connection.getLocalAddress() + "->" + connection.getRemoteAddress() +
                                 (keepAlive ? " kept alive" : " cannot be kept alive"));
                     }
 
@@ -167,7 +168,8 @@ public class AsyncReverseProxyExample {
 
                     @Override
                     public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
-                        System.out.println("[client<-proxy] connection " + connection +
+                        System.out.println("[client<-proxy] connection " +
+                                connection.getLocalAddress() + "->" + connection.getRemoteAddress() +
                                 (keepAlive ? " kept alive" : " cannot be kept alive"));
                     }
 
index 32b4aa0..81211fa 100644 (file)
@@ -42,7 +42,7 @@ import org.apache.hc.core5.util.Timeout;
 
 class AbstractHttp1IOEventHandler implements HttpConnectionEventHandler {
 
-    private final AbstractHttp1StreamDuplexer<?, ?> streamDuplexer;
+    final AbstractHttp1StreamDuplexer<?, ?> streamDuplexer;
 
     AbstractHttp1IOEventHandler(final AbstractHttp1StreamDuplexer<?, ?> streamDuplexer) {
         this.streamDuplexer = Args.notNull(streamDuplexer, "Stream multiplexer");
@@ -144,9 +144,4 @@ class AbstractHttp1IOEventHandler implements HttpConnectionEventHandler {
         return streamDuplexer.getLocalAddress();
     }
 
-    @Override
-    public String toString() {
-        return streamDuplexer.toString();
-    }
-
 }
index 585cbed..4fc661c 100644 (file)
@@ -623,4 +623,11 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
         return tlsDetails != null ? tlsDetails.getSSLSession() : null;
     }
 
+    void dumpState(final StringBuilder buf) {
+        buf.append("connState=").append(connState)
+                .append(", inbuf=").append(inbuf)
+                .append(", outbuf=").append(outbuf)
+                .append(", inputWindow=").append(inputWindow);
+    }
+
 }
index 3cf7d8f..de7fa16 100644 (file)
@@ -27,6 +27,8 @@
 
 package org.apache.hc.core5.http.impl.nio;
 
+import org.apache.hc.core5.net.InetAddressUtils;
+
 /**
  * {@link org.apache.hc.core5.reactor.IOEventHandler} that implements
  *  client side HTTP/1.1 messaging protocol with full support for
@@ -40,5 +42,17 @@ public class ClientHttp1IOEventHandler extends AbstractHttp1IOEventHandler {
         super(streamDuplexer);
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder buf = new StringBuilder();
+        InetAddressUtils.formatAddress(buf, getLocalAddress());
+        buf.append("->");
+        InetAddressUtils.formatAddress(buf, getRemoteAddress());
+        buf.append(" [");
+        streamDuplexer.dumpState(buf);
+        buf.append("]");
+        return buf.toString();
+    }
+
 }
 
index 86caed7..a2661c1 100644 (file)
@@ -64,7 +64,6 @@ import org.apache.hc.core5.http.nio.command.RequestExecutionCommand;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.io.CloseMode;
-import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.ProtocolIOSession;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
@@ -388,12 +387,28 @@ public class ClientHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
     }
 
     @Override
+    void dumpState(final StringBuilder buf) {
+        super.dumpState(buf);
+        super.dumpState(buf);
+        buf.append(", incoming=[");
+        if (incoming != null) {
+            incoming.dumpState(buf);
+        }
+        buf.append("], outgoing=[");
+        if (outgoing != null) {
+            outgoing.dumpState(buf);
+        }
+        buf.append("], pipeline=");
+        buf.append(pipeline.size());
+    }
+
+    @Override
     public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        InetAddressUtils.formatAddress(buffer, getLocalAddress());
-        buffer.append("->");
-        InetAddressUtils.formatAddress(buffer, getRemoteAddress());
-        return buffer.toString();
+        final StringBuilder buf = new StringBuilder();
+        buf.append("[");
+        dumpState(buf);
+        buf.append("]");
+        return buf.toString();
     }
 
 }
index 0a8fe04..58f7d1d 100644 (file)
@@ -304,12 +304,21 @@ class ClientHttp1StreamHandler implements ResourceHolder {
         }
     }
 
+    void dumpState(final StringBuilder buf) {
+        buf.append("requestState=").append(requestState)
+                .append(", responseState=").append(responseState)
+                .append(", responseCommitted=").append(requestCommitted)
+                .append(", keepAlive=").append(keepAlive)
+                .append(", done=").append(done);
+    }
+
     @Override
     public String toString() {
-        return "[" +
-                "requestState=" + requestState +
-                ", responseState=" + responseState +
-                ']';
+        final StringBuilder buf = new StringBuilder();
+        buf.append("[");
+        dumpState(buf);
+        buf.append("]");
+        return buf.toString();
     }
 
 }
index 8e16470..2e74a99 100644 (file)
@@ -29,6 +29,7 @@ package org.apache.hc.core5.http.impl.nio;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.net.InetAddressUtils;
 
 /**
  * {@link org.apache.hc.core5.reactor.IOEventHandler} that implements
@@ -44,4 +45,16 @@ public class ServerHttp1IOEventHandler extends AbstractHttp1IOEventHandler {
         super(streamDuplexer);
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder buf = new StringBuilder();
+        InetAddressUtils.formatAddress(buf, getRemoteAddress());
+        buf.append("->");
+        InetAddressUtils.formatAddress(buf, getLocalAddress());
+        buf.append(" [");
+        streamDuplexer.dumpState(buf);
+        buf.append("]");
+        return buf.toString();
+    }
+
 }
index c8f481c..9b249a2 100644 (file)
@@ -63,7 +63,6 @@ import org.apache.hc.core5.http.nio.command.RequestExecutionCommand;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.io.CloseMode;
-import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.ProtocolIOSession;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
@@ -402,12 +401,27 @@ public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
     }
 
     @Override
+    void dumpState(final StringBuilder buf) {
+        super.dumpState(buf);
+        buf.append(", incoming=[");
+        if (incoming != null) {
+            incoming.dumpState(buf);
+        }
+        buf.append("], outgoing=[");
+        if (outgoing != null) {
+            outgoing.dumpState(buf);
+        }
+        buf.append("], pipeline=");
+        buf.append(pipeline.size());
+    }
+
+    @Override
     public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        InetAddressUtils.formatAddress(buffer, getRemoteAddress());
-        buffer.append("->");
-        InetAddressUtils.formatAddress(buffer, getLocalAddress());
-        return buffer.toString();
+        final StringBuilder buf = new StringBuilder();
+        buf.append("[");
+        dumpState(buf);
+        buf.append("]");
+        return buf.toString();
     }
 
     private static class DelayedOutputChannel implements Http1StreamChannel<HttpResponse> {
index b87b04c..8478069 100644 (file)
@@ -315,13 +315,21 @@ class ServerHttp1StreamHandler implements ResourceHolder {
         }
     }
 
+    void dumpState(final StringBuilder buf) {
+        buf.append("requestState=").append(requestState)
+                .append(", responseState=").append(responseState)
+                .append(", responseCommitted=").append(responseCommitted)
+                .append(", keepAlive=").append(keepAlive)
+                .append(", done=").append(done);
+    }
+
     @Override
     public String toString() {
-        return "[" +
-                "requestState=" + requestState +
-                ", responseState=" + responseState +
-                ", outputChannel=" + outputChannel +
-                ']';
+        final StringBuilder buf = new StringBuilder();
+        buf.append("[");
+        dumpState(buf);
+        buf.append("]");
+        return buf.toString();
     }
 
 }
index 96f1bbd..1eafc0e 100644 (file)
@@ -117,4 +117,14 @@ final class IOSessionRequest implements Future<IOSession> {
         return future.get(timeout, unit);
     }
 
+    @Override
+    public String toString() {
+        return "[" +
+                "remoteEndpoint=" + remoteEndpoint +
+                ", remoteAddress=" + remoteAddress +
+                ", localAddress=" + localAddress +
+                ", attachment=" + attachment +
+                ']';
+    }
+
 }
index edabe30..55e5fd7 100644 (file)
@@ -111,4 +111,10 @@ final class InternalConnectChannel extends InternalChannel {
         } catch (final IOException ignore) {
         }
     }
+
+    @Override
+    public String toString() {
+        return sessionRequest.toString();
+    }
+
 }
index 0ef7d49..5c66daa 100644 (file)
@@ -378,7 +378,18 @@ final class InternalDataChannel extends InternalChannel implements ProtocolIOSes
 
     @Override
     public String toString() {
-        return getSessionImpl().toString();
+        final StringBuilder buf = new StringBuilder();
+        final SSLIOSession tlsSession = tlsSessionRef.get();
+        if (tlsSession != null) {
+            buf.append(tlsSession);
+        } else {
+            buf.append(ioSession);
+        }
+        final IOEventHandler handler = getHandler();
+        if (handler != null) {
+            buf.append(handler);
+        }
+        return buf.toString();
     }
 
 }