http-client-branch: (WebSocket) Demand in Receiver http-client-branch
authorprappo
Sat, 25 Nov 2017 15:34:04 +0300
branchhttp-client-branch
changeset 55872 9c31615e8989
parent 55871 45c88bf0592b
child 55873 b5e6a3201081
http-client-branch: (WebSocket) Demand in Receiver
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/Receiver.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/Receiver.java	Fri Nov 24 20:48:35 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/Receiver.java	Sat Nov 25 15:34:04 2017 +0300
@@ -28,7 +28,8 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.SelectionKey;
-import java.util.concurrent.atomic.AtomicLong;
+
+import jdk.incubator.http.internal.common.Demand;
 import jdk.incubator.http.internal.common.SequentialScheduler;
 
 /*
@@ -57,7 +58,7 @@
     private final FrameConsumer frameConsumer;
     private final Frame.Reader reader = new Frame.Reader();
     private final RawChannel.RawEvent event = createHandler();
-    private final AtomicLong demand = new AtomicLong();
+    private final Demand demand = new Demand();
     private final SequentialScheduler pushScheduler;
 
     private ByteBuffer data;
@@ -98,12 +99,12 @@
         if (n <= 0L) {
             throw new IllegalArgumentException("Non-positive request: " + n);
         }
-        demand.accumulateAndGet(n, (p, i) -> p + i < 0 ? Long.MAX_VALUE : p + i);
+        demand.increase(n);
         pushScheduler.runOrSchedule();
     }
 
     void acknowledge() {
-        long x = demand.decrementAndGet();
+        long x = demand.decreaseAndGet(1);
         if (x < 0) {
             throw new InternalError(String.valueOf(x));
         }