http-client-branch: Added a 'channel' category for high-level logs http-client-branch
authordfuchs
Fri, 15 Jun 2018 17:32:00 +0100
branchhttp-client-branch
changeset 56768 d6b08065edf5
parent 56767 014ef88f5066
child 56770 f1626bc0a010
http-client-branch: Added a 'channel' category for high-level logs
src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java
src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java
src/java.net.http/share/classes/jdk/internal/net/http/common/Log.java
test/jdk/java/net/httpclient/ShortResponseBody.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java	Fri Jun 15 15:39:07 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java	Fri Jun 15 17:32:00 2018 +0100
@@ -737,7 +737,7 @@
             List<AsyncEvent> readyList = new ArrayList<>();
             List<Runnable> resetList = new ArrayList<>();
             try {
-                if (Log.trace()) Log.logTrace(getName() + ": starting");
+                if (Log.channel()) Log.logChannel(getName() + ": starting");
                 while (!Thread.currentThread().isInterrupted()) {
                     synchronized (this) {
                         assert errorList.isEmpty();
@@ -914,6 +914,7 @@
                     e.printStackTrace(System.err); // always print the stack
                 }
             } finally {
+                if (Log.channel()) Log.logChannel(getName() + ": stopping");
                 shutdown();
             }
         }
--- a/src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java	Fri Jun 15 15:39:07 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java	Fri Jun 15 17:32:00 2018 +0100
@@ -41,6 +41,7 @@
 import jdk.internal.net.http.common.BufferSupplier;
 import jdk.internal.net.http.common.Demand;
 import jdk.internal.net.http.common.FlowTube;
+import jdk.internal.net.http.common.Log;
 import jdk.internal.net.http.common.Logger;
 import jdk.internal.net.http.common.SequentialScheduler;
 import jdk.internal.net.http.common.SequentialScheduler.DeferredCompleter;
@@ -149,6 +150,10 @@
     void signalClosed() {
         // Ensures that the subscriber will be terminated and that future
         // subscribers will be notified when the connection is closed.
+        if (Log.channel()) {
+            Log.logChannel("Connection close signalled: connection closed locally ({0})",
+                    channelDescr());
+        }
         readPublisher.subscriptionImpl.signalError(
                 new IOException("connection closed locally"));
     }
@@ -364,6 +369,10 @@
         void startSubscription() {
             try {
                 if (debug.on()) debug.log("write: starting subscription");
+                if (Log.channel()) {
+                    Log.logChannel("Start requesting bytes for writing to channel: {0}",
+                            channelDescr());
+                }
                 assert client.isSelectorThread();
                 // make sure read registrations are handled before;
                 readPublisher.subscriptionImpl.handlePending();
@@ -409,6 +418,10 @@
 
         void signalError(Throwable error) {
             debug.log(() -> "write error: " + error);
+            if (Log.channel()) {
+                Log.logChannel("Failed to write on channel ({0}: {1})",
+                        channelDescr(), error);
+            }
             completed = true;
             readPublisher.signalError(error);
         }
@@ -559,6 +572,10 @@
             if (!errorRef.compareAndSet(null, error)) {
                 return;
             }
+            if (Log.channel()) {
+                Log.logChannel("Error signalled on channel {0}: {1}",
+                        channelDescr(), error);
+            }
             subscriptionImpl.handleError();
         }
 
@@ -666,6 +683,7 @@
             final void handleSubscribeEvent() {
                 assert client.isSelectorThread();
                 debug.log("subscribe event raised");
+                if (Log.channel()) Log.logChannel("Start reading from {0}", channelDescr());
                 readScheduler.runOrSchedule();
                 if (readScheduler.isStopped() || completed) {
                     // if already completed or stopped we can handle any
@@ -789,6 +807,10 @@
                                 if (bytes == EOF) {
                                     if (!completed) {
                                         if (debug.on()) debug.log("got read EOF");
+                                        if (Log.channel()) {
+                                            Log.logChannel("EOF reached from channel: {0}",
+                                                        channelDescr());
+                                        }
                                         completed = true;
                                         // safe to pause here because we're finished
                                         // anyway.
@@ -1239,4 +1261,8 @@
     final String dbgString() {
         return "SocketTube("+id+")";
     }
+
+    final String channelDescr() {
+        return String.valueOf(channel);
+    }
 }
--- a/src/java.net.http/share/classes/jdk/internal/net/http/common/Log.java	Fri Jun 15 15:39:07 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/common/Log.java	Fri Jun 15 17:32:00 2018 +0100
@@ -43,7 +43,7 @@
 /**
  * -Djava.net.HttpClient.log=
  *          errors,requests,headers,
- *          frames[:control:data:window:all..],content,ssl,trace
+ *          frames[:control:data:window:all..],content,ssl,trace,channel
  *
  * Any of errors, requests, headers or content are optional.
  *
@@ -65,6 +65,7 @@
     public static final int FRAMES = 0x10;
     public static final int SSL = 0x20;
     public static final int TRACE = 0x40;
+    public static final int CHANNEL = 0x80;
     static int logging;
 
     // Frame types: "control", "data", "window", "all"
@@ -99,11 +100,15 @@
                     case "ssl":
                         logging |= SSL;
                         break;
+                    case "channel":
+                        logging |= CHANNEL;
+                        break;
                     case "trace":
                         logging |= TRACE;
                         break;
                     case "all":
-                        logging |= CONTENT|HEADERS|REQUESTS|FRAMES|ERRORS|TRACE|SSL;
+                        logging |= CONTENT|HEADERS|REQUESTS|FRAMES|ERRORS|TRACE|SSL| CHANNEL;
+                        frametypes |= ALL;
                         break;
                     default:
                         // ignore bad values
@@ -166,6 +171,10 @@
         return (logging & FRAMES) != 0;
     }
 
+    public static boolean channel() {
+        return (logging & CHANNEL) != 0;
+    }
+
     public static void logError(String s, Object... s1) {
         if (errors()) {
             logger.log(Level.INFO, "ERROR: " + s, s1);
@@ -191,9 +200,21 @@
         }
     }
 
+    public static void logChannel(String s, Object... s1) {
+        if (channel()) {
+            logger.log(Level.INFO, "CHANNEL: " + s, s1);
+        }
+    }
+
+    public static void logChannel(Supplier<String> msgSupplier) {
+        if (channel()) {
+            logger.log(Level.INFO, "CHANNEL: " + msgSupplier.get());
+        }
+    }
+
     public static void logTrace(String s, Object... s1) {
         if (trace()) {
-            String format = "TRACE: " + s;
+            String format = "MISC: " + s;
             logger.log(Level.INFO, format, s1);
         }
     }
--- a/test/jdk/java/net/httpclient/ShortResponseBody.java	Fri Jun 15 15:39:07 2018 +0100
+++ b/test/jdk/java/net/httpclient/ShortResponseBody.java	Fri Jun 15 17:32:00 2018 +0100
@@ -28,10 +28,10 @@
  * @library /lib/testlibrary
  * @build jdk.testlibrary.SimpleSSLContext
  * @run testng/othervm
- *       -Djdk.httpclient.HttpClient.log=headers,errors
+ *       -Djdk.httpclient.HttpClient.log=headers,errors,channel
  *       ShortResponseBody
  * @run testng/othervm
- *       -Djdk.httpclient.HttpClient.log=headers,errors
+ *       -Djdk.httpclient.HttpClient.log=headers,errors,channel
  *       -Djdk.httpclient.enableAllMethodRetry
  *       ShortResponseBody
  */