author | prappo |
Wed, 07 Mar 2018 17:16:28 +0000 | |
branch | http-client-branch |
changeset 56263 | 4933a477d628 |
parent 56092 | fd85b2bf2b0d |
child 56269 | 234813fd33bc |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
56024
de352132c7e8
http-client-branch: (WebSocket) a number of tests for exceptional completion
prappo
parents:
55992
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
4 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
10 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
16 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
20 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
23 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
24 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
|
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
26 |
package jdk.internal.net.http.websocket; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
|
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
28 |
import jdk.internal.net.http.common.Demand; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
29 |
import jdk.internal.net.http.common.Log; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
30 |
import jdk.internal.net.http.common.MinimalFuture; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
31 |
import jdk.internal.net.http.common.SequentialScheduler; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
32 |
import jdk.internal.net.http.common.Utils; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
33 |
import jdk.internal.net.http.websocket.OpeningHandshake.Result; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
34 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
import java.io.IOException; |
48083 | 36 |
import java.lang.ref.Reference; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
import java.net.ProtocolException; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
38 |
import java.net.URI; |
56263 | 39 |
import java.net.http.WebSocket; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
40 |
import java.nio.ByteBuffer; |
56045 | 41 |
import java.util.Objects; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
42 |
import java.util.concurrent.CompletableFuture; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
43 |
import java.util.concurrent.CompletionStage; |
48083 | 44 |
import java.util.concurrent.TimeoutException; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
45 |
import java.util.concurrent.atomic.AtomicBoolean; |
48083 | 46 |
import java.util.concurrent.atomic.AtomicReference; |
56263 | 47 |
import java.util.function.BiConsumer; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
48 |
import java.util.function.Function; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
49 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
50 |
import static java.util.Objects.requireNonNull; |
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
51 |
import static jdk.internal.net.http.common.MinimalFuture.failedFuture; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
52 |
import static jdk.internal.net.http.websocket.StatusCodes.CLOSED_ABNORMALLY; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
53 |
import static jdk.internal.net.http.websocket.StatusCodes.NO_STATUS_CODE; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
54 |
import static jdk.internal.net.http.websocket.StatusCodes.isLegalToSendFromClient; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
55 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.BINARY; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
56 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.CLOSE; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
57 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.ERROR; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
58 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.IDLE; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
59 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.OPEN; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
60 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.PING; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
61 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.PONG; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
62 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.TEXT; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
63 |
import static jdk.internal.net.http.websocket.WebSocketImpl.State.WAITING; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
/* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
66 |
* A WebSocket client. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
67 |
*/ |
48083 | 68 |
public final class WebSocketImpl implements WebSocket { |
69 |
||
56263 | 70 |
private final static boolean DEBUG = false; |
71 |
||
48083 | 72 |
enum State { |
73 |
OPEN, |
|
74 |
IDLE, |
|
75 |
WAITING, |
|
76 |
TEXT, |
|
77 |
BINARY, |
|
78 |
PING, |
|
79 |
PONG, |
|
80 |
CLOSE, |
|
81 |
ERROR; |
|
82 |
} |
|
83 |
||
56263 | 84 |
private final MinimalFuture<WebSocket> DONE = MinimalFuture.completedFuture(this); |
48083 | 85 |
private volatile boolean inputClosed; |
86 |
private volatile boolean outputClosed; |
|
87 |
||
88 |
private final AtomicReference<State> state = new AtomicReference<>(OPEN); |
|
89 |
||
90 |
/* Components of calls to Listener's methods */ |
|
91 |
private MessagePart part; |
|
92 |
private ByteBuffer binaryData; |
|
93 |
private CharSequence text; |
|
94 |
private int statusCode; |
|
95 |
private String reason; |
|
96 |
private final AtomicReference<Throwable> error = new AtomicReference<>(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
97 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
98 |
private final URI uri; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
99 |
private final String subprotocol; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
100 |
private final Listener listener; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
101 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
102 |
private final AtomicBoolean outstandingSend = new AtomicBoolean(); |
56263 | 103 |
private final Transport transport; |
104 |
private final SequentialScheduler receiveScheduler |
|
105 |
= new SequentialScheduler(new ReceiveTask()); |
|
48083 | 106 |
private final Demand demand = new Demand(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
107 |
|
48083 | 108 |
public static CompletableFuture<WebSocket> newInstanceAsync(BuilderImpl b) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
Function<Result, WebSocket> newWebSocket = r -> { |
48083 | 110 |
WebSocket ws = newInstance(b.getUri(), |
111 |
r.subprotocol, |
|
112 |
b.getListener(), |
|
113 |
r.transport); |
|
114 |
// Make sure we don't release the builder until this lambda |
|
115 |
// has been executed. The builder has a strong reference to |
|
116 |
// the HttpClientFacade, and we want to keep that live until |
|
117 |
// after the raw channel is created and passed to WebSocketImpl. |
|
118 |
Reference.reachabilityFence(b); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
119 |
return ws; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
120 |
}; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
121 |
OpeningHandshake h; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
122 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
123 |
h = new OpeningHandshake(b); |
48083 | 124 |
} catch (Throwable e) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
125 |
return failedFuture(e); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
126 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
127 |
return h.send().thenApply(newWebSocket); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
128 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
129 |
|
48083 | 130 |
/* Exposed for testing purposes */ |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
131 |
static WebSocketImpl newInstance(URI uri, |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
132 |
String subprotocol, |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
133 |
Listener listener, |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
134 |
TransportFactory transport) { |
48083 | 135 |
WebSocketImpl ws = new WebSocketImpl(uri, subprotocol, listener, transport); |
136 |
// This initialisation is outside of the constructor for the sake of |
|
137 |
// safe publication of WebSocketImpl.this |
|
138 |
ws.signalOpen(); |
|
139 |
return ws; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
140 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
141 |
|
48083 | 142 |
private WebSocketImpl(URI uri, |
143 |
String subprotocol, |
|
144 |
Listener listener, |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
145 |
TransportFactory transportFactory) { |
48083 | 146 |
this.uri = requireNonNull(uri); |
147 |
this.subprotocol = requireNonNull(subprotocol); |
|
148 |
this.listener = requireNonNull(listener); |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
149 |
this.transport = transportFactory.createTransport( |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
150 |
new SignallingMessageConsumer()); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
151 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
152 |
|
56263 | 153 |
// FIXME: add to action handling of errors -> signalError() |
154 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
155 |
@Override |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
156 |
public CompletableFuture<WebSocket> sendText(CharSequence message, |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
157 |
boolean isLast) { |
56045 | 158 |
Objects.requireNonNull(message); |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
159 |
if (!outstandingSend.compareAndSet(false, true)) { |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
160 |
return failedFuture(new IllegalStateException("Send pending")); |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
161 |
} |
56263 | 162 |
CompletableFuture<WebSocket> cf |
163 |
= transport.sendText(message, isLast, this, |
|
164 |
(r, e) -> outstandingSend.set(false)); |
|
165 |
return replaceNull(cf); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
166 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
167 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
168 |
@Override |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
169 |
public CompletableFuture<WebSocket> sendBinary(ByteBuffer message, |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
170 |
boolean isLast) { |
56045 | 171 |
Objects.requireNonNull(message); |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
172 |
if (!outstandingSend.compareAndSet(false, true)) { |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
173 |
return failedFuture(new IllegalStateException("Send pending")); |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
174 |
} |
56263 | 175 |
CompletableFuture<WebSocket> cf |
176 |
= transport.sendBinary(message, isLast, this, |
|
177 |
(r, e) -> outstandingSend.set(false)); |
|
178 |
return replaceNull(cf); |
|
179 |
} |
|
180 |
||
181 |
private CompletableFuture<WebSocket> replaceNull( |
|
182 |
CompletableFuture<WebSocket> cf) |
|
183 |
{ |
|
184 |
if (cf == null) { |
|
185 |
return DONE; |
|
186 |
} else { |
|
187 |
return cf; |
|
188 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
189 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
190 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
191 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
192 |
public CompletableFuture<WebSocket> sendPing(ByteBuffer message) { |
56263 | 193 |
Objects.requireNonNull(message); |
194 |
CompletableFuture<WebSocket> cf |
|
195 |
= transport.sendPing(message, this, (r, e) -> { }); |
|
196 |
return replaceNull(cf); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
197 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
198 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
199 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
200 |
public CompletableFuture<WebSocket> sendPong(ByteBuffer message) { |
56263 | 201 |
Objects.requireNonNull(message); |
202 |
CompletableFuture<WebSocket> cf |
|
203 |
= transport.sendPong(message, this, (r, e) -> { }); |
|
204 |
return replaceNull(cf); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
205 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
206 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
207 |
@Override |
56263 | 208 |
public CompletableFuture<WebSocket> sendClose(int statusCode, |
209 |
String reason) { |
|
56058 | 210 |
Objects.requireNonNull(reason); |
45119
decbbff9fdb4
8179021: Latest bugfixes to WebSocket/HPACK from the sandbox repo
prappo
parents:
43730
diff
changeset
|
211 |
if (!isLegalToSendFromClient(statusCode)) { |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
212 |
return failedFuture(new IllegalArgumentException("statusCode")); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
213 |
} |
56263 | 214 |
CompletableFuture<WebSocket> cf = sendClose0(statusCode, reason); |
215 |
return replaceNull(cf); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
216 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
217 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
218 |
/* |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
219 |
* Sends a Close message, then shuts down the output since no more |
56263 | 220 |
* messages are expected to be sent at this point. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
221 |
*/ |
56263 | 222 |
private CompletableFuture<WebSocket> sendClose0(int statusCode, |
223 |
String reason) { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
224 |
outputClosed = true; |
56263 | 225 |
BiConsumer<WebSocket, Throwable> closer = (r, e) -> { |
226 |
Throwable cause = Utils.getCompletionCause(e); |
|
227 |
if (cause instanceof IllegalArgumentException) { |
|
228 |
// or pre=check it (isLegalToSendFromClient(statusCode)) |
|
229 |
return; |
|
230 |
} |
|
231 |
try { |
|
232 |
transport.closeOutput(); |
|
233 |
} catch (IOException ex) { |
|
234 |
Log.logError(ex); |
|
235 |
} |
|
236 |
if (cause instanceof TimeoutException) { // FIXME: it is not the case anymore |
|
237 |
if (DEBUG) { |
|
238 |
System.out.println("[WebSocket] sendClose0 error: " + e); |
|
239 |
} |
|
240 |
try { |
|
241 |
transport.closeInput(); |
|
242 |
} catch (IOException ex) { |
|
243 |
Log.logError(ex); |
|
244 |
} |
|
245 |
} |
|
246 |
}; |
|
247 |
CompletableFuture<WebSocket> cf |
|
248 |
= transport.sendClose(statusCode, reason, this, closer); |
|
249 |
return cf; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
250 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
251 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
252 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
253 |
public void request(long n) { |
56263 | 254 |
if (DEBUG) { |
255 |
System.out.printf("[WebSocket] request(%s)%n", n); |
|
256 |
} |
|
48083 | 257 |
if (demand.increase(n)) { |
258 |
receiveScheduler.runOrSchedule(); |
|
259 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
260 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
261 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
262 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
263 |
public String getSubprotocol() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
264 |
return subprotocol; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
265 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
266 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
267 |
@Override |
48083 | 268 |
public boolean isOutputClosed() { |
269 |
return outputClosed; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
270 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
271 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
272 |
@Override |
48083 | 273 |
public boolean isInputClosed() { |
274 |
return inputClosed; |
|
275 |
} |
|
276 |
||
277 |
@Override |
|
278 |
public void abort() { |
|
56263 | 279 |
if (DEBUG) { |
280 |
System.out.printf("[WebSocket] abort()%n"); |
|
281 |
} |
|
48083 | 282 |
inputClosed = true; |
283 |
outputClosed = true; |
|
284 |
receiveScheduler.stop(); |
|
285 |
close(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
286 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
287 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
288 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
289 |
public String toString() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
290 |
return super.toString() |
48083 | 291 |
+ "[uri=" + uri |
292 |
+ (!subprotocol.isEmpty() ? ", subprotocol=" + subprotocol : "") |
|
293 |
+ "]"; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
294 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
295 |
|
48083 | 296 |
/* |
297 |
* The assumptions about order is as follows: |
|
298 |
* |
|
299 |
* - state is never changed more than twice inside the `run` method: |
|
300 |
* x --(1)--> IDLE --(2)--> y (otherwise we're loosing events, or |
|
301 |
* overwriting parts of messages creating a mess since there's no |
|
302 |
* queueing) |
|
303 |
* - OPEN is always the first state |
|
304 |
* - no messages are requested/delivered before onOpen is called (this |
|
305 |
* is implemented by making WebSocket instance accessible first in |
|
306 |
* onOpen) |
|
307 |
* - after the state has been observed as CLOSE/ERROR, the scheduler |
|
308 |
* is stopped |
|
309 |
*/ |
|
310 |
private class ReceiveTask extends SequentialScheduler.CompleteRestartableTask { |
|
311 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
312 |
// Transport only asked here and nowhere else because we must make sure |
48083 | 313 |
// onOpen is invoked first and no messages become pending before onOpen |
314 |
// finishes |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
315 |
|
48083 | 316 |
@Override |
317 |
public void run() { |
|
318 |
while (true) { |
|
319 |
State s = state.get(); |
|
320 |
try { |
|
321 |
switch (s) { |
|
322 |
case OPEN: |
|
323 |
processOpen(); |
|
324 |
tryChangeState(OPEN, IDLE); |
|
325 |
break; |
|
326 |
case TEXT: |
|
327 |
processText(); |
|
328 |
tryChangeState(TEXT, IDLE); |
|
329 |
break; |
|
330 |
case BINARY: |
|
331 |
processBinary(); |
|
332 |
tryChangeState(BINARY, IDLE); |
|
333 |
break; |
|
334 |
case PING: |
|
335 |
processPing(); |
|
336 |
tryChangeState(PING, IDLE); |
|
337 |
break; |
|
338 |
case PONG: |
|
339 |
processPong(); |
|
340 |
tryChangeState(PONG, IDLE); |
|
341 |
break; |
|
342 |
case CLOSE: |
|
343 |
processClose(); |
|
344 |
return; |
|
345 |
case ERROR: |
|
346 |
processError(); |
|
347 |
return; |
|
348 |
case IDLE: |
|
349 |
if (demand.tryDecrement() |
|
350 |
&& tryChangeState(IDLE, WAITING)) { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
351 |
transport.request(1); |
48083 | 352 |
} |
353 |
return; |
|
354 |
case WAITING: |
|
355 |
// For debugging spurious signalling: when there was a |
|
356 |
// signal, but apparently nothing has changed |
|
357 |
return; |
|
358 |
default: |
|
359 |
throw new InternalError(String.valueOf(s)); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
360 |
} |
48083 | 361 |
} catch (Throwable t) { |
362 |
signalError(t); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
363 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
364 |
} |
48083 | 365 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
366 |
|
48083 | 367 |
private void processError() throws IOException { |
56263 | 368 |
if (DEBUG) { |
369 |
System.out.println("[WebSocket] processError"); |
|
370 |
} |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
371 |
transport.closeInput(); |
48083 | 372 |
receiveScheduler.stop(); |
373 |
Throwable err = error.get(); |
|
374 |
if (err instanceof FailWebSocketException) { |
|
375 |
int code1 = ((FailWebSocketException) err).getStatusCode(); |
|
376 |
err = new ProtocolException().initCause(err); |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
377 |
sendClose0(code1, "") |
48083 | 378 |
.whenComplete( |
379 |
(r, e) -> { |
|
380 |
if (e != null) { |
|
381 |
Log.logError(e); |
|
382 |
} |
|
383 |
}); |
|
384 |
} |
|
385 |
listener.onError(WebSocketImpl.this, err); |
|
386 |
} |
|
387 |
||
388 |
private void processClose() throws IOException { |
|
56263 | 389 |
if (DEBUG) { |
390 |
System.out.println("[WebSocket] processClose"); |
|
391 |
} |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
392 |
transport.closeInput(); |
48083 | 393 |
receiveScheduler.stop(); |
394 |
CompletionStage<?> readyToClose; |
|
395 |
readyToClose = listener.onClose(WebSocketImpl.this, statusCode, reason); |
|
396 |
if (readyToClose == null) { |
|
56263 | 397 |
readyToClose = DONE; |
48083 | 398 |
} |
399 |
int code; |
|
400 |
if (statusCode == NO_STATUS_CODE || statusCode == CLOSED_ABNORMALLY) { |
|
401 |
code = NORMAL_CLOSURE; |
|
56263 | 402 |
if (DEBUG) { |
403 |
System.out.printf("[WebSocket] using statusCode %s instead of %s%n", |
|
404 |
statusCode, code); |
|
405 |
} |
|
48083 | 406 |
} else { |
407 |
code = statusCode; |
|
408 |
} |
|
409 |
readyToClose.whenComplete((r, e) -> { |
|
56263 | 410 |
sendClose0(code, "") // FIXME errors from here? |
48083 | 411 |
.whenComplete((r1, e1) -> { |
56263 | 412 |
if (DEBUG) { |
413 |
if (e1 != null) { |
|
414 |
e1.printStackTrace(System.out); |
|
415 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
416 |
} |
48083 | 417 |
}); |
418 |
}); |
|
419 |
} |
|
420 |
||
421 |
private void processPong() { |
|
422 |
listener.onPong(WebSocketImpl.this, binaryData); |
|
423 |
} |
|
424 |
||
425 |
private void processPing() { |
|
426 |
// Let's make a full copy of this tiny data. What we want here |
|
427 |
// is to rule out a possibility the shared data we send might be |
|
428 |
// corrupted by processing in the listener. |
|
429 |
ByteBuffer slice = binaryData.slice(); |
|
430 |
ByteBuffer copy = ByteBuffer.allocate(binaryData.remaining()) |
|
431 |
.put(binaryData) |
|
432 |
.flip(); |
|
433 |
// Non-exclusive send; |
|
56263 | 434 |
BiConsumer<WebSocketImpl, Throwable> reporter = (r, e) -> { |
435 |
if (e != null) { |
|
436 |
signalError(Utils.getCompletionCause(e)); |
|
437 |
} |
|
438 |
}; |
|
439 |
transport.sendPong(copy, WebSocketImpl.this, reporter); |
|
48083 | 440 |
listener.onPing(WebSocketImpl.this, slice); |
441 |
} |
|
442 |
||
443 |
private void processBinary() { |
|
444 |
listener.onBinary(WebSocketImpl.this, binaryData, part); |
|
445 |
} |
|
446 |
||
447 |
private void processText() { |
|
448 |
listener.onText(WebSocketImpl.this, text, part); |
|
449 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
450 |
|
48083 | 451 |
private void processOpen() { |
452 |
listener.onOpen(WebSocketImpl.this); |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
private void signalOpen() { |
|
56263 | 457 |
if (DEBUG) { |
458 |
System.out.printf("[WebSocket] signalOpen%n"); |
|
459 |
} |
|
48083 | 460 |
receiveScheduler.runOrSchedule(); |
461 |
} |
|
462 |
||
463 |
private void signalError(Throwable error) { |
|
56263 | 464 |
if (DEBUG) { |
465 |
System.out.printf("[WebSocket] signalError %s%n", error); |
|
466 |
} |
|
48083 | 467 |
inputClosed = true; |
468 |
outputClosed = true; |
|
469 |
if (!this.error.compareAndSet(null, error) || !trySetState(ERROR)) { |
|
470 |
Log.logError(error); |
|
471 |
} else { |
|
472 |
close(); |
|
473 |
} |
|
474 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
475 |
|
48083 | 476 |
private void close() { |
56263 | 477 |
if (DEBUG) { |
478 |
System.out.println("[WebSocket] close"); |
|
479 |
} |
|
480 |
Throwable first = null; |
|
48083 | 481 |
try { |
56263 | 482 |
transport.closeInput(); |
483 |
} catch (Throwable t1) { |
|
484 |
first = t1; |
|
485 |
} finally { |
|
486 |
Throwable second = null; |
|
48083 | 487 |
try { |
56263 | 488 |
transport.closeOutput(); |
489 |
} catch (Throwable t2) { |
|
490 |
second = t2; |
|
48083 | 491 |
} finally { |
56263 | 492 |
Throwable e = null; |
493 |
if (first != null && second != null) { |
|
494 |
first.addSuppressed(second); |
|
495 |
e = first; |
|
496 |
} else if (first != null) { |
|
497 |
e = first; |
|
498 |
} else if (second != null) { |
|
499 |
e = second; |
|
500 |
} |
|
501 |
if (DEBUG) { |
|
502 |
if (e != null) { |
|
503 |
e.printStackTrace(System.out); |
|
504 |
} |
|
505 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
506 |
} |
48083 | 507 |
} |
508 |
} |
|
509 |
||
510 |
private void signalClose(int statusCode, String reason) { |
|
56263 | 511 |
// FIXME: make sure no race reason & close are not intermixed |
48083 | 512 |
inputClosed = true; |
513 |
this.statusCode = statusCode; |
|
514 |
this.reason = reason; |
|
56263 | 515 |
boolean managed = trySetState(CLOSE); |
516 |
if (DEBUG) { |
|
517 |
System.out.printf("[WebSocket] signalClose statusCode=%s, reason.length()=%s: %s%n", |
|
518 |
statusCode, reason.length(), managed); |
|
519 |
} |
|
520 |
if (managed) { |
|
48083 | 521 |
try { |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
522 |
transport.closeInput(); |
48083 | 523 |
} catch (Throwable t) { |
56263 | 524 |
if (DEBUG) { |
525 |
t.printStackTrace(System.out); |
|
526 |
} |
|
48083 | 527 |
} |
528 |
} |
|
529 |
} |
|
530 |
||
531 |
private class SignallingMessageConsumer implements MessageStreamConsumer { |
|
532 |
||
533 |
@Override |
|
534 |
public void onText(CharSequence data, MessagePart part) { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
535 |
transport.acknowledgeReception(); |
48083 | 536 |
text = data; |
537 |
WebSocketImpl.this.part = part; |
|
538 |
tryChangeState(WAITING, TEXT); |
|
539 |
} |
|
540 |
||
541 |
@Override |
|
542 |
public void onBinary(ByteBuffer data, MessagePart part) { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
543 |
transport.acknowledgeReception(); |
48083 | 544 |
binaryData = data; |
545 |
WebSocketImpl.this.part = part; |
|
546 |
tryChangeState(WAITING, BINARY); |
|
547 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
548 |
|
48083 | 549 |
@Override |
550 |
public void onPing(ByteBuffer data) { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
551 |
transport.acknowledgeReception(); |
48083 | 552 |
binaryData = data; |
553 |
tryChangeState(WAITING, PING); |
|
554 |
} |
|
555 |
||
556 |
@Override |
|
557 |
public void onPong(ByteBuffer data) { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
558 |
transport.acknowledgeReception(); |
48083 | 559 |
binaryData = data; |
560 |
tryChangeState(WAITING, PONG); |
|
561 |
} |
|
562 |
||
563 |
@Override |
|
564 |
public void onClose(int statusCode, CharSequence reason) { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
565 |
transport.acknowledgeReception(); |
48083 | 566 |
signalClose(statusCode, reason.toString()); |
567 |
} |
|
568 |
||
569 |
@Override |
|
570 |
public void onComplete() { |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
571 |
transport.acknowledgeReception(); |
48083 | 572 |
signalClose(CLOSED_ABNORMALLY, ""); |
573 |
} |
|
574 |
||
575 |
@Override |
|
576 |
public void onError(Throwable error) { |
|
577 |
signalError(error); |
|
578 |
} |
|
579 |
} |
|
580 |
||
581 |
private boolean trySetState(State newState) { |
|
56263 | 582 |
State currentState; |
583 |
boolean success = false; |
|
48083 | 584 |
while (true) { |
56263 | 585 |
currentState = state.get(); |
48083 | 586 |
if (currentState == ERROR || currentState == CLOSE) { |
56263 | 587 |
break; |
48083 | 588 |
} else if (state.compareAndSet(currentState, newState)) { |
589 |
receiveScheduler.runOrSchedule(); |
|
56263 | 590 |
success = true; |
591 |
break; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
592 |
} |
48083 | 593 |
} |
56263 | 594 |
if (DEBUG) { |
595 |
System.out.printf("[WebSocket] set state %s (previous %s) %s%n", |
|
596 |
newState, currentState, success); |
|
597 |
} |
|
598 |
return success; |
|
48083 | 599 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
600 |
|
48083 | 601 |
private boolean tryChangeState(State expectedState, State newState) { |
602 |
State witness = state.compareAndExchange(expectedState, newState); |
|
56263 | 603 |
boolean success = false; |
48083 | 604 |
if (witness == expectedState) { |
605 |
receiveScheduler.runOrSchedule(); |
|
56263 | 606 |
success = true; |
607 |
} else if (witness != ERROR && witness != CLOSE) { |
|
608 |
// This should be the only reason for inability to change the state |
|
609 |
// from IDLE to WAITING: the state has changed to terminal |
|
48083 | 610 |
throw new InternalError(); |
611 |
} |
|
56263 | 612 |
if (DEBUG) { |
613 |
System.out.printf("[WebSocket] change state from %s to %s %s%n", |
|
614 |
expectedState, newState, success); |
|
615 |
} |
|
616 |
return success; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
617 |
} |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
618 |
|
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
619 |
/* Exposed for testing purposes */ |
56263 | 620 |
protected Transport transport() { |
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
621 |
return transport; |
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
622 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
623 |
} |