http-client-branch: SequentialScheduler cleanup http-client-branch
authorprappo
Fri, 26 Jan 2018 11:08:42 +0000
branchhttp-client-branch
changeset 56040 f8eabb9a5c0f
parent 56039 01739771e48b
child 56041 b4b5e09ef3cc
http-client-branch: SequentialScheduler cleanup
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1AsyncReceiver.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1Exchange.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http2Connection.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SequentialScheduler.java
test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/SSLEchoTubeTest.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1AsyncReceiver.java	Wed Jan 24 12:26:15 2018 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1AsyncReceiver.java	Fri Jan 26 11:08:42 2018 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -364,7 +364,7 @@
         // Everything may have been received already. Make sure
         // we parse it.
         if (client.isSelectorThread()) {
-            scheduler.deferOrSchedule(executor);
+            scheduler.runOrSchedule(executor);
         } else {
             scheduler.runOrSchedule();
         }
@@ -393,7 +393,7 @@
         // This callback is called from within the selector thread.
         // Use an executor here to avoid doing the heavy lifting in the
         // selector.
-        scheduler.deferOrSchedule(executor);
+        scheduler.runOrSchedule(executor);
     }
 
     // Callback: Consumer of Throwable
@@ -434,7 +434,7 @@
             // This callback is called from within the selector thread.
             // Use an executor here to avoid doing the heavy lifting in the
             // selector.
-            scheduler.deferOrSchedule(executor);
+            scheduler.runOrSchedule(executor);
         }
     }
 
@@ -470,7 +470,7 @@
             dropped = false;
             canRequestMore.set(true);
             if (delegate != null) {
-                scheduler.deferOrSchedule(executor);
+                scheduler.runOrSchedule(executor);
             }
         }
 
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1Exchange.java	Wed Jan 24 12:26:15 2018 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1Exchange.java	Fri Jan 26 11:08:42 2018 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -596,7 +596,7 @@
                 demand.increase(n);
                 debug.log(Level.DEBUG,
                         "subscription request(%d), demand=%s", n, demand);
-                writeScheduler.deferOrSchedule(client.theExecutor());
+                writeScheduler.runOrSchedule(client.theExecutor());
             }
 
             @Override
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http2Connection.java	Wed Jan 24 12:26:15 2018 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http2Connection.java	Fri Jan 26 11:08:42 2018 +0000
@@ -1088,7 +1088,7 @@
             debug.log(Level.DEBUG, () -> "onNext: got " + Utils.remaining(item)
                     + " bytes in " + item.size() + " buffers");
             queue.addAll(item);
-            scheduler.deferOrSchedule(client().theExecutor());
+            scheduler.runOrSchedule(client().theExecutor());
         }
 
         @Override
@@ -1096,7 +1096,7 @@
             debug.log(Level.DEBUG, () -> "onError: " + throwable);
             error = throwable;
             completed = true;
-            scheduler.deferOrSchedule(client().theExecutor());
+            scheduler.runOrSchedule(client().theExecutor());
         }
 
         @Override
@@ -1104,7 +1104,7 @@
             debug.log(Level.DEBUG, "EOF");
             error = new EOFException("EOF reached while reading");
             completed = true;
-            scheduler.deferOrSchedule(client().theExecutor());
+            scheduler.runOrSchedule(client().theExecutor());
         }
 
         @Override
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SequentialScheduler.java	Wed Jan 24 12:26:15 2018 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SequentialScheduler.java	Fri Jan 26 11:08:42 2018 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -135,8 +135,8 @@
     }
 
     /**
-     * A complete restartable task is one which is simple and self-contained.
-     * It completes once its {@code run} method returns.
+     * A simple and self-contained task that completes once its {@code run}
+     * method returns.
      */
     public static abstract class CompleteRestartableTask
         implements RestartableTask
@@ -155,16 +155,16 @@
     }
 
     /**
-     * A RestartableTask that runs its main loop within a
-     * synchronized block to place a memory barrier around it.
-     * Because the main loop can't run concurrently in two treads,
-     * then the lock shouldn't be contended and no deadlock should
-     * ever be possible.
+     * A task that runs its main loop within a synchronized block to provide
+     * memory visibility between runs. Since the main loop can't run concurrently,
+     * the lock shouldn't be contended and no deadlock should ever be possible.
      */
     public static final class SynchronizedRestartableTask
             extends CompleteRestartableTask {
+
         private final Runnable mainLoop;
         private final Object lock = new Object();
+
         public SynchronizedRestartableTask(Runnable mainLoop) {
             this.mainLoop = mainLoop;
         }
@@ -189,7 +189,7 @@
     private final SchedulableTask schedulableTask;
 
     /**
-     * A simple task that can be pushed on an executor to execute
+     * An auxiliary task that starts the restartable task:
      * {@code restartableTask.run(completer)}.
      */
     private final class SchedulableTask implements Runnable {
@@ -225,7 +225,7 @@
     }
 
     /**
-     * Runs or schedules the task to be run in the provided executor.
+     * Executes or schedules the task to be executed in the provided executor.
      *
      * <p> This method can be used when potential executing from a calling
      * thread is not desirable.
@@ -235,10 +235,10 @@
      *         to be executed.
      *
      * @apiNote The given executor can be {@code null} in which case calling
-     * {@code deferOrSchedule(null)} is strictly equivalent to calling
+     * {@code runOrSchedule(null)} is strictly equivalent to calling
      * {@code runOrSchedule()}.
      */
-    public void deferOrSchedule(Executor executor) { // TODO: why this name? why not runOrSchedule?
+    public void runOrSchedule(Executor executor) {
         runOrSchedule(schedulableTask, executor);
     }
 
@@ -348,17 +348,15 @@
      * Returns a new {@code SequentialScheduler} that executes the provided
      * {@code mainLoop} from within a {@link SynchronizedRestartableTask}.
      *
-     * @apiNote
-     * This is equivalent to calling
-     * {@code new SequentialScheduler(new SynchronizedRestartableTask(mainloop));}
-     * The main loop must not do any blocking operation.
+     * @apiNote This is equivalent to calling
+     * {@code new SequentialScheduler(new SynchronizedRestartableTask(mainLoop))}
+     * The main loop must not perform any blocking operation.
      *
-     * @param mainloop The main loop of the new sequential scheduler.
+     * @param mainLoop The main loop of the new sequential scheduler
      * @return a new {@code SequentialScheduler} that executes the provided
      * {@code mainLoop} from within a {@link SynchronizedRestartableTask}.
      */
-    public static SequentialScheduler synchronizedScheduler(Runnable mainloop) {
-        return new SequentialScheduler(new SynchronizedRestartableTask(mainloop));
+    public static SequentialScheduler synchronizedScheduler(Runnable mainLoop) {
+        return new SequentialScheduler(new SynchronizedRestartableTask(mainLoop));
     }
-
 }
--- a/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/SSLEchoTubeTest.java	Wed Jan 24 12:26:15 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/SSLEchoTubeTest.java	Fri Jan 26 11:08:42 2018 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -313,21 +313,21 @@
             System.out.printf("EchoTube add %s [requested:%s, queue:%s]%n",
                     Utils.remaining(item), requested, queue.size());
             queue.add(item);
-            processingScheduler.deferOrSchedule(executor);
+            processingScheduler.runOrSchedule(executor);
         }
 
         @Override
         public void onError(Throwable throwable) {
             System.out.println("EchoTube add " + throwable);
             queue.add(throwable);
-            processingScheduler.deferOrSchedule(executor);
+            processingScheduler.runOrSchedule(executor);
         }
 
         @Override
         public void onComplete() {
             System.out.println("EchoTube add EOF");
             queue.add(EOF);
-            processingScheduler.deferOrSchedule(executor);
+            processingScheduler.runOrSchedule(executor);
         }
 
         @Override
@@ -344,7 +344,7 @@
                     throw new InternalError();
                 }
                 if (demand.increase(n)) {
-                    processingScheduler.deferOrSchedule(executor);
+                    processingScheduler.runOrSchedule(executor);
                 }
             }