http-client-branch: (WebSocket) refactoring http-client-branch
authorprappo
Fri, 15 Dec 2017 13:35:56 +0300
branchhttp-client-branch
changeset 55992 10cefe168d6d
parent 55991 5683757b6771
child 55993 087a6b6d4955
http-client-branch: (WebSocket) refactoring
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/WebSocketImpl.java
test/jdk/java/net/httpclient/websocket/jdk.incubator.httpclient/jdk/incubator/http/internal/websocket/WebSocketImplTest.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/WebSocketImpl.java	Fri Dec 15 10:31:21 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/WebSocketImpl.java	Fri Dec 15 13:35:56 2017 +0300
@@ -164,11 +164,11 @@
         }
         CompletableFuture<WebSocket> cf = transport.sendBinary(message, isLast);
         // Optimize?
-        //        if (cf.isDone()) {
-        //            outstandingSend.set(false);
-        //        } else {
-        //            cf.whenComplete((r, e) -> outstandingSend.set(false));
-        //        }
+        //     if (cf.isDone()) {
+        //         outstandingSend.set(false);
+        //     } else {
+        //         cf.whenComplete((r, e) -> outstandingSend.set(false));
+        //     }
         return cf.whenComplete((r, e) -> outstandingSend.set(false));
     }
 
@@ -182,6 +182,9 @@
         return transport.sendPong(message);
     }
 
+    // TODO: this is the only method that works unconditionally: e.g. even if CF
+    // completes with an exception, the output will be closed
+    // Even if arguments are illegal the closure will happen (e.g. a default message)
     @Override
     public CompletableFuture<WebSocket> sendClose(int statusCode, String reason) {
         if (!isLegalToSendFromClient(statusCode)) {
@@ -193,15 +196,12 @@
     /*
      * Sends a Close message, then shuts down the output since no more
      * messages are expected to be sent after this.
-     *
-     * TODO: Even if arguments are illegal the default message will be sent.
      */
     private CompletableFuture<WebSocket> sendClose0(int statusCode, String reason ) {
         // TODO: MUST be a CF created once and shared across sendClose, otherwise
         // a second sendClose may prematurely close the channel
         outputClosed = true;
         return transport.sendClose(statusCode, reason)
-                .orTimeout(60, TimeUnit.SECONDS)
                 .whenComplete((r, error) -> {
                     try {
                         transport.closeOutput();
--- a/test/jdk/java/net/httpclient/websocket/jdk.incubator.httpclient/jdk/incubator/http/internal/websocket/WebSocketImplTest.java	Fri Dec 15 10:31:21 2017 +0000
+++ b/test/jdk/java/net/httpclient/websocket/jdk.incubator.httpclient/jdk/incubator/http/internal/websocket/WebSocketImplTest.java	Fri Dec 15 13:35:56 2017 +0300
@@ -412,14 +412,14 @@
         assertEquals(transport.invocations().size(), 3); // 6 minus 3 that were not accepted
     }
 
-    private static <T> CompletableFuture<T> seconds(long sec, T result) {
+    private static <T> CompletableFuture<T> seconds(long val, T result) {
         return new CompletableFuture<T>()
-                .completeOnTimeout(result, sec, TimeUnit.SECONDS);
+                .completeOnTimeout(result, val, TimeUnit.SECONDS);
     }
 
-    private static <T> CompletableFuture<T> millis(long sec, T result) {
+    private static <T> CompletableFuture<T> millis(long val, T result) {
         return new CompletableFuture<T>()
-                .completeOnTimeout(result, sec, TimeUnit.MILLISECONDS);
+                .completeOnTimeout(result, val, TimeUnit.MILLISECONDS);
     }
 
     private static <T> CompletableFuture<T> now(T result) {