author | prappo |
Sun, 18 Mar 2018 14:31:36 +0000 | |
branch | http-client-branch |
changeset 56318 | 2a96e88888b2 |
parent 56263 | 4933a477d628 |
child 56320 | f82729ca8660 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
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 |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56087
diff
changeset
|
26 |
package java.net.http; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
28 |
import java.io.IOException; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
29 |
import java.net.URI; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
30 |
import java.nio.ByteBuffer; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
31 |
import java.time.Duration; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
32 |
import java.util.concurrent.CompletableFuture; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
33 |
import java.util.concurrent.CompletionStage; |
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 |
/** |
48083 | 36 |
* A WebSocket client. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
* |
48083 | 38 |
* <p> To create a {@code WebSocket} use the {@link HttpClient#newWebSocketBuilder} |
39 |
* method. To close a {@code WebSocket} use one of the {@code sendClose} or |
|
40 |
* {@code abort} methods. |
|
41 |
* |
|
42 |
* <p> WebSocket messages are sent through a {@code WebSocket} and received |
|
43 |
* through the {@code WebSocket}'s {@code Listener}. Messages can be sent until |
|
44 |
* the output is closed, and received until the input is closed. |
|
45 |
* A {@code WebSocket} whose output and input are both closed may be considered |
|
46 |
* itself closed. To check these states use {@link #isOutputClosed()} and |
|
47 |
* {@link #isInputClosed()}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
48 |
* |
48083 | 49 |
* <p> Methods that send messages return {@code CompletableFuture} which |
50 |
* completes normally if the message is sent or completes exceptionally if an |
|
51 |
* error occurs. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
52 |
* |
48083 | 53 |
* <p> To receive a message, first request it. If {@code n} messages are |
54 |
* requested, the listener will receive up to {@code n} more invocations of the |
|
55 |
* designated methods from the {@code WebSocket}. To request messages use |
|
56 |
* {@link #request(long)}. Request is an additive operation, that is |
|
57 |
* {@code request(n)} followed by {@code request(m)} is equivalent to |
|
58 |
* {@code request(n + m)}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
59 |
* |
48083 | 60 |
* <p> When sending or receiving a message in parts, a whole message is |
61 |
* transferred as a sequence of one or more invocations where the last |
|
62 |
* invocation is identified via an additional method argument. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
63 |
* |
48083 | 64 |
* <p> Unless otherwise stated, {@code null} arguments will cause methods |
65 |
* of {@code WebSocket} to throw {@code NullPointerException}, similarly, |
|
66 |
* {@code WebSocket} will not pass {@code null} arguments to methods of |
|
67 |
* {@code Listener}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
68 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
69 |
* <p> The state of a {@code WebSocket} is not changed by the invocations that |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
70 |
* throw or return a {@code CompletableFuture} that completes with one of the |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
71 |
* {@code NullPointerException}, {@code IllegalArgumentException}, |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
72 |
* {@code IllegalStateException} exceptions. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
73 |
* |
48083 | 74 |
* <p> A {@code WebSocket} invokes methods of its listener in a thread-safe |
75 |
* manner. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
76 |
* |
48083 | 77 |
* <p> {@code WebSocket} handles Ping and Close messages automatically (as per |
78 |
* RFC 6455) by replying with Pong and Close messages respectively. If the |
|
79 |
* listener receives Ping or Close messages, no mandatory actions from the |
|
80 |
* listener are required. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
81 |
* |
56086 | 82 |
* @since 11 |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
83 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
84 |
public interface WebSocket { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
85 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
86 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
87 |
* The WebSocket Close message status code (<code>{@value}</code>), |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
88 |
* indicating normal closure, meaning that the purpose for which the |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
89 |
* connection was established has been fulfilled. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
90 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
91 |
* @see #sendClose(int, String) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
92 |
* @see Listener#onClose(WebSocket, int, String) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
93 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
94 |
int NORMAL_CLOSURE = 1000; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
95 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
96 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
97 |
* A builder for creating {@code WebSocket} instances. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
98 |
* |
48083 | 99 |
* <p> To obtain a {@code WebSocket} configure a builder as required by |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
100 |
* calling intermediate methods (the ones that return the builder itself), |
48083 | 101 |
* then call {@code buildAsync()}. If an intermediate method is not called, |
102 |
* an appropriate default value (or behavior) will be assumed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
103 |
* |
48083 | 104 |
* <p> Unless otherwise stated, {@code null} arguments will cause methods of |
105 |
* {@code Builder} to throw {@code NullPointerException}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
106 |
* |
56086 | 107 |
* @since 11 |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
108 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
interface Builder { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
110 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
111 |
/** |
48083 | 112 |
* Adds the given name-value pair to the list of additional HTTP headers |
113 |
* sent during the opening handshake. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
114 |
* |
56156
336393c75a93
http-client-branch: add link to illegal WebSocket headers
chegar
parents:
56151
diff
changeset
|
115 |
* <p> Headers defined in |
336393c75a93
http-client-branch: add link to illegal WebSocket headers
chegar
parents:
56151
diff
changeset
|
116 |
* <a href="https://tools.ietf.org/html/rfc6455#section-11.3">WebSocket |
336393c75a93
http-client-branch: add link to illegal WebSocket headers
chegar
parents:
56151
diff
changeset
|
117 |
* Protocol</a> are illegal. If this method is not invoked, no |
336393c75a93
http-client-branch: add link to illegal WebSocket headers
chegar
parents:
56151
diff
changeset
|
118 |
* additional HTTP headers will be sent. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
119 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
120 |
* @param name |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
121 |
* the header name |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
122 |
* @param value |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
123 |
* the header value |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
124 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
125 |
* @return this builder |
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 |
Builder header(String name, String value); |
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 |
* Sets a timeout for establishing a WebSocket connection. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
131 |
* |
48083 | 132 |
* <p> If the connection is not established within the specified |
133 |
* duration then building of the {@code WebSocket} will fail with |
|
134 |
* {@link HttpTimeoutException}. If this method is not invoked then the |
|
135 |
* infinite timeout is assumed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
136 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
137 |
* @param timeout |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
138 |
* the timeout, non-{@linkplain Duration#isNegative() negative}, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
139 |
* non-{@linkplain Duration#ZERO ZERO} |
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 |
* @return this builder |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
142 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
143 |
Builder connectTimeout(Duration timeout); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
144 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
145 |
/** |
48083 | 146 |
* Sets a request for the given subprotocols. |
147 |
* |
|
148 |
* <p> After the {@code WebSocket} has been built, the actual |
|
149 |
* subprotocol can be queried via |
|
150 |
* {@link WebSocket#getSubprotocol WebSocket.getSubprotocol()}. |
|
151 |
* |
|
152 |
* <p> Subprotocols are specified in the order of preference. The most |
|
153 |
* preferred subprotocol is specified first. If there are any additional |
|
154 |
* subprotocols they are enumerated from the most preferred to the least |
|
155 |
* preferred. |
|
156 |
* |
|
157 |
* <p> Subprotocols not conforming to the syntax of subprotocol |
|
158 |
* identifiers are illegal. If this method is not invoked then no |
|
159 |
* subprotocols will be requested. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
160 |
* |
48083 | 161 |
* @param mostPreferred |
162 |
* the most preferred subprotocol |
|
163 |
* @param lesserPreferred |
|
164 |
* the lesser preferred subprotocols |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
165 |
* |
48083 | 166 |
* @return this builder |
167 |
*/ |
|
168 |
Builder subprotocols(String mostPreferred, String... lesserPreferred); |
|
169 |
||
170 |
/** |
|
171 |
* Builds a {@link WebSocket} connected to the given {@code URI} and |
|
172 |
* associated with the given {@code Listener}. |
|
173 |
* |
|
174 |
* <p> Returns a {@code CompletableFuture} which will either complete |
|
175 |
* normally with the resulting {@code WebSocket} or complete |
|
176 |
* exceptionally with one of the following errors: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
177 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
178 |
* <li> {@link IOException} - |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
179 |
* if an I/O error occurs |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
180 |
* <li> {@link WebSocketHandshakeException} - |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
181 |
* if the opening handshake fails |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
182 |
* <li> {@link HttpTimeoutException} - |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
183 |
* if the opening handshake does not complete within |
48083 | 184 |
* the timeout |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
185 |
* <li> {@link InterruptedException} - |
48083 | 186 |
* if the operation is interrupted |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
187 |
* <li> {@link SecurityException} - |
48083 | 188 |
* if a security manager has been installed and it denies |
189 |
* {@link java.net.URLPermission access} to {@code uri}. |
|
190 |
* <a href="HttpRequest.html#securitychecks">Security checks</a> |
|
191 |
* contains more information relating to the security context |
|
192 |
* in which the the listener is invoked. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
193 |
* <li> {@link IllegalArgumentException} - |
48083 | 194 |
* if any of the arguments of this builder's methods are |
195 |
* illegal |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
196 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
197 |
* |
48083 | 198 |
* @param uri |
199 |
* the WebSocket URI |
|
200 |
* @param listener |
|
201 |
* the listener |
|
202 |
* |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
203 |
* @return a {@code CompletableFuture} with the {@code WebSocket} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
204 |
*/ |
48083 | 205 |
CompletableFuture<WebSocket> buildAsync(URI uri, Listener listener); |
42460
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 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
208 |
/** |
48083 | 209 |
* The receiving interface of {@code WebSocket}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
210 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
211 |
* <p> A {@code WebSocket} invokes methods on the associated listener when |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
212 |
* it receives messages or encounters events. A {@code WebSocket} invokes |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
213 |
* methods on the listener in a thread-safe manner. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
214 |
* |
56151
eae2b2d7fe52
http-client-branch: clarify strict size requirement for received ping/pong messages
chegar
parents:
56089
diff
changeset
|
215 |
* <p> Messages received by the {@code Listener} conform to the WebSocket |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
216 |
* Protocol, otherwise {@code onError} with a {@link IOException} is invoked. |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
217 |
* Any {@code IOException} raised by {@code WebSocket} will result in an |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
218 |
* invocation of {@code onError} with that exception. Unless otherwise |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
219 |
* stated if a listener's method throws an exception or a |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
220 |
* {@code CompletionStage} returned from a method completes exceptionally, |
48083 | 221 |
* the {@code WebSocket} will invoke {@code onError} with this exception. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
222 |
* |
48083 | 223 |
* <p> If a listener's method returns {@code null} rather than a |
224 |
* {@code CompletionStage}, {@code WebSocket} will behave as if the listener |
|
225 |
* returned a {@code CompletionStage} that is already completed normally. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
226 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
227 |
* @apiNote Methods of {@code Listener} have a {@code WebSocket} parameter |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
228 |
* which holds an invoking {@code WebSocket} at runtime. A careful attention |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
229 |
* is required if a listener is associated with more than a single |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
230 |
* {@code WebSocket}. In this case invocations related to different |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
231 |
* instances of {@code WebSocket} may not be ordered and may even happen |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
232 |
* concurrently. |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
233 |
* |
56086 | 234 |
* @since 11 |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
235 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
236 |
interface Listener { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
237 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
238 |
/** |
48083 | 239 |
* A {@code WebSocket} has been connected. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
240 |
* |
48083 | 241 |
* <p> This is the first invocation and it is made at most once. This |
242 |
* method is typically used to make an initial request for messages. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
243 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
244 |
* @implSpec The default implementation of this method behaves as if: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
245 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
246 |
* <pre>{@code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
247 |
* webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
248 |
* }</pre> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
249 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
250 |
* @param webSocket |
48083 | 251 |
* the WebSocket that has been connected |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
252 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
253 |
default void onOpen(WebSocket webSocket) { webSocket.request(1); } |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
254 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
255 |
/** |
48083 | 256 |
* A Text message has been received. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
257 |
* |
48083 | 258 |
* <p> If a whole message has been received, this method will be invoked |
259 |
* with {@code MessagePart.WHOLE} marker. Otherwise, it will be invoked |
|
260 |
* with {@code FIRST}, possibly a number of times with {@code PART} and, |
|
261 |
* finally, with {@code LAST} markers. If this message is partial, it |
|
262 |
* may be an incomplete UTF-16 sequence. However, the concatenation of |
|
263 |
* all messages through the last will be a complete UTF-16 sequence. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
264 |
* |
48083 | 265 |
* <p> Return a {@code CompletionStage} which will be used by the |
266 |
* {@code WebSocket} as a signal it may reclaim the |
|
267 |
* {@code CharSequence}. Do not access the {@code CharSequence} after |
|
268 |
* this {@ode CompletionStage} has completed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
269 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
270 |
* @implSpec The default implementation of this method behaves as if: |
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 |
* <pre>{@code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
273 |
* webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
274 |
* return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
275 |
* }</pre> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
276 |
* |
48083 | 277 |
* @implNote This method is always invoked with character sequences |
278 |
* which are complete UTF-16 sequences. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
279 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
280 |
* @param webSocket |
48083 | 281 |
* the WebSocket on which the message has been received |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
282 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
283 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
284 |
* @param part |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
285 |
* the part |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
286 |
* |
48083 | 287 |
* @return a {@code CompletionStage} which completes when the |
288 |
* {@code CharSequence} may be reclaimed; or {@code null} if it may be |
|
289 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
290 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
291 |
default CompletionStage<?> onText(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
292 |
CharSequence message, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
293 |
MessagePart part) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
294 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
295 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
296 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
297 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
298 |
/** |
48083 | 299 |
* A Binary message has been received. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
300 |
* |
48083 | 301 |
* <p> If a whole message has been received, this method will be invoked |
302 |
* with {@code MessagePart.WHOLE} marker. Otherwise, it will be invoked |
|
303 |
* with {@code FIRST}, possibly a number of times with {@code PART} and, |
|
304 |
* finally, with {@code LAST} markers. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
305 |
* |
48083 | 306 |
* <p> This message consists of bytes from the buffer's position to |
307 |
* its limit. |
|
308 |
* |
|
309 |
* <p> Return a {@code CompletionStage} which will be used by the |
|
310 |
* {@code WebSocket} as a signal it may reclaim the |
|
311 |
* {@code ByteBuffer}. Do not access the {@code ByteBuffer} after |
|
312 |
* this {@ode CompletionStage} has completed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
313 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
314 |
* @implSpec The default implementation of this method behaves as if: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
315 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
316 |
* <pre>{@code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
317 |
* webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
318 |
* return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
319 |
* }</pre> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
320 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
321 |
* @param webSocket |
48083 | 322 |
* the WebSocket on which the message has been received |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
323 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
324 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
325 |
* @param part |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
326 |
* the part |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
327 |
* |
48083 | 328 |
* @return a {@code CompletionStage} which completes when the |
329 |
* {@code ByteBuffer} may be reclaimed; or {@code null} if it may be |
|
330 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
331 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
332 |
default CompletionStage<?> onBinary(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
333 |
ByteBuffer message, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
334 |
MessagePart part) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
335 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
336 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
337 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
338 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
339 |
/** |
48083 | 340 |
* A Ping message has been received. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
341 |
* |
56151
eae2b2d7fe52
http-client-branch: clarify strict size requirement for received ping/pong messages
chegar
parents:
56089
diff
changeset
|
342 |
* <p> As guaranteed by the WebSocket Protocol, the message consists of |
eae2b2d7fe52
http-client-branch: clarify strict size requirement for received ping/pong messages
chegar
parents:
56089
diff
changeset
|
343 |
* not more than {@code 125} bytes. These bytes are located from the |
eae2b2d7fe52
http-client-branch: clarify strict size requirement for received ping/pong messages
chegar
parents:
56089
diff
changeset
|
344 |
* buffer's position to its limit. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
345 |
* |
48083 | 346 |
* <p> Return a {@code CompletionStage} which will be used by the |
347 |
* {@code WebSocket} as a signal it may reclaim the |
|
348 |
* {@code ByteBuffer}. Do not access the {@code ByteBuffer} after |
|
349 |
* this {@ode CompletionStage} has completed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
350 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
351 |
* @implSpec The default implementation of this method behaves as if: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
352 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
353 |
* <pre>{@code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
354 |
* webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
355 |
* return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
356 |
* }</pre> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
357 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
358 |
* @param webSocket |
48083 | 359 |
* the WebSocket on which the message has been received |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
360 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
361 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
362 |
* |
48083 | 363 |
* @return a {@code CompletionStage} which completes when the |
364 |
* {@code ByteBuffer} may be reclaimed; or {@code null} if it may be |
|
365 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
366 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
367 |
default CompletionStage<?> onPing(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
368 |
ByteBuffer message) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
369 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
370 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
371 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
372 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
373 |
/** |
48083 | 374 |
* A Pong message has been received. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
375 |
* |
56151
eae2b2d7fe52
http-client-branch: clarify strict size requirement for received ping/pong messages
chegar
parents:
56089
diff
changeset
|
376 |
* <p> As guaranteed by the WebSocket Protocol, the message consists of |
eae2b2d7fe52
http-client-branch: clarify strict size requirement for received ping/pong messages
chegar
parents:
56089
diff
changeset
|
377 |
* not more than {@code 125} bytes. These bytes are located from the |
eae2b2d7fe52
http-client-branch: clarify strict size requirement for received ping/pong messages
chegar
parents:
56089
diff
changeset
|
378 |
* buffer's position to its limit. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
379 |
* |
48083 | 380 |
* <p> Return a {@code CompletionStage} which will be used by the |
381 |
* {@code WebSocket} as a signal it may reclaim the |
|
382 |
* {@code ByteBuffer}. Do not access the {@code ByteBuffer} after |
|
383 |
* this {@ode CompletionStage} has completed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
384 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
385 |
* @implSpec The default implementation of this method behaves as if: |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
386 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
387 |
* <pre>{@code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
388 |
* webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
389 |
* return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
390 |
* }</pre> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
391 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
392 |
* @param webSocket |
48083 | 393 |
* the WebSocket on which the message has been received |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
394 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
395 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
396 |
* |
48083 | 397 |
* @return a {@code CompletionStage} which completes when the |
398 |
* {@code ByteBuffer} may be reclaimed; or {@code null} if it may be |
|
399 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
400 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
401 |
default CompletionStage<?> onPong(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
402 |
ByteBuffer message) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
403 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
404 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
405 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
406 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
407 |
/** |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
408 |
* Receives a Close message indicating the {@code WebSocket}'s input has |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
409 |
* been closed. |
48083 | 410 |
* |
411 |
* <p> This is the last invocation from the {@code WebSocket}. By the |
|
412 |
* time this invocation begins the {@code WebSocket}'s input will have |
|
413 |
* been closed. Be prepared to receive this invocation at any time after |
|
414 |
* {@code onOpen} regardless of whether or not any messages have been |
|
415 |
* requested from the {@code WebSocket}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
416 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
417 |
* <p> A Close message consists of a status code and a reason for |
48083 | 418 |
* closing. The status code is an integer from the range |
419 |
* {@code 1000 <= code <= 65535}. The {@code reason} is a string which |
|
420 |
* has an UTF-8 representation not longer than {@code 123} bytes. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
421 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
422 |
* <p> If the {@code WebSocket}'s output is not already closed, the |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
423 |
* {@code CompletionStage} returned by this method will be used as an |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
424 |
* indication that the {@code WebSocket}'s output may be closed. The |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
425 |
* {@code WebSocket} will close its output at the earliest of completion |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
426 |
* of the returned {@code CompletionStage} or invoking either of the |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
427 |
* {@code sendClose} or {@code abort} methods. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
428 |
* |
56039
01739771e48b
http-client-branch: add api/impl notes to WebSocket onClose
chegar
parents:
55973
diff
changeset
|
429 |
* @apiNote Returning a {@code CompletionStage} that never completes, |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
430 |
* effectively disables the reciprocating closure of the output. |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
431 |
* |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
432 |
* <p> To specify a custom closure code and/or reason code the sendClose |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
433 |
* may be invoked from inside onClose call: |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
434 |
* <pre>{@code |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
435 |
* public CompletionStage<?> onClose(WebSocket webSocket, |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
436 |
* int statusCode, |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
437 |
* String reason) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
438 |
* webSocket.sendClose(CUSTOM_STATUS_CODE, CUSTOM_REASON); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
439 |
* return new CompletableFuture<Void>(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
440 |
* } |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
441 |
* }</pre> |
56039
01739771e48b
http-client-branch: add api/impl notes to WebSocket onClose
chegar
parents:
55973
diff
changeset
|
442 |
* |
01739771e48b
http-client-branch: add api/impl notes to WebSocket onClose
chegar
parents:
55973
diff
changeset
|
443 |
* @implSpec The default implementation of this method returns |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
444 |
* {@code null}, indicating that the output should be closed |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
445 |
* immediately. |
56039
01739771e48b
http-client-branch: add api/impl notes to WebSocket onClose
chegar
parents:
55973
diff
changeset
|
446 |
* |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
447 |
* @param webSocket |
48083 | 448 |
* the WebSocket on which the message has been received |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
449 |
* @param statusCode |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
450 |
* the status code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
451 |
* @param reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
452 |
* the reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
453 |
* |
48083 | 454 |
* @return a {@code CompletionStage} which completes when the |
455 |
* {@code WebSocket} may be closed; or {@code null} if it may be |
|
456 |
* closed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
457 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
458 |
default CompletionStage<?> onClose(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
459 |
int statusCode, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
460 |
String reason) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
461 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
462 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
463 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
464 |
/** |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
465 |
* An error has occurred. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
466 |
* |
48083 | 467 |
* <p> This is the last invocation from the {@code WebSocket}. By the |
468 |
* time this invocation begins both {@code WebSocket}'s input and output |
|
469 |
* will have been closed. Be prepared to receive this invocation at any |
|
470 |
* time after {@code onOpen} regardless of whether or not any messages |
|
471 |
* have been requested from the {@code WebSocket}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
472 |
* |
48083 | 473 |
* <p> If an exception is thrown from this method, resulting behavior is |
474 |
* undefined. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
475 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
476 |
* @param webSocket |
48083 | 477 |
* the WebSocket on which the error has occurred |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
478 |
* @param error |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
479 |
* the error |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
480 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
481 |
default void onError(WebSocket webSocket, Throwable error) { } |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
482 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
483 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
484 |
/** |
48083 | 485 |
* A marker used by {@link WebSocket.Listener} for identifying partial |
486 |
* messages. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
487 |
* |
56086 | 488 |
* @since 11 |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
489 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
490 |
enum MessagePart { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
491 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
492 |
/** |
48083 | 493 |
* The first part of a message. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
494 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
495 |
FIRST, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
496 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
497 |
/** |
48083 | 498 |
* A middle part of a message. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
499 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
500 |
PART, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
501 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
502 |
/** |
48083 | 503 |
* The last part of a message. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
504 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
505 |
LAST, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
506 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
507 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
508 |
* A whole message consisting of a single part. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
509 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
510 |
WHOLE |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
511 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
512 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
513 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
514 |
* Sends a Text message with characters from the given {@code CharSequence}. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
515 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
516 |
* <p> The character sequence must not be modified until the |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
517 |
* {@code CompletableFuture} returned from this method has completed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
518 |
* |
48083 | 519 |
* <p> A {@code CompletableFuture} returned from this method can |
520 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
521 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
522 |
* <li> {@link IllegalStateException} - |
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
523 |
* if the previous Text or Binary message has not been sent yet |
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
524 |
* or if a previous Binary message has been sent with |
48083 | 525 |
* {@code isLast == false} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
526 |
* <li> {@link IOException} - |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
527 |
* if an I/O error occurs, or if the output is closed |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
528 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
529 |
* |
56263 | 530 |
* @implNote If a partial or malformed UTF-16 sequence is passed to this |
531 |
* method, a {@code CompletableFuture} returned will complete exceptionally |
|
532 |
* with {@code IOException}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
533 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
534 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
535 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
536 |
* @param isLast |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
537 |
* {@code true} if this is the last part of the message, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
538 |
* {@code false} otherwise |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
539 |
* |
48083 | 540 |
* @return a {@code CompletableFuture} that completes, with this |
541 |
* {@code WebSocket}, when the message has been sent |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
542 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
543 |
CompletableFuture<WebSocket> sendText(CharSequence message, boolean isLast); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
544 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
545 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
546 |
* Sends a Binary message with bytes from the given {@code ByteBuffer}. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
547 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
548 |
* <p> The message consists of bytes from the buffer's position to its |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
549 |
* limit. Upon normal completion of a {@code CompletableFuture} returned |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
550 |
* from this method the buffer will have no remaining bytes. The buffer must |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
551 |
* not be accessed until after that. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
552 |
* |
48083 | 553 |
* <p> The {@code CompletableFuture} returned from this method can |
554 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
555 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
556 |
* <li> {@link IllegalStateException} - |
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
557 |
* if the previous Binary or Text message has not been sent yet |
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
558 |
* or if a previous Text message has been sent with |
48083 | 559 |
* {@code isLast == false} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
560 |
* <li> {@link IOException} - |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
561 |
* if an I/O error occurs, or if the output is closed |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
562 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
563 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
564 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
565 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
566 |
* @param isLast |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
567 |
* {@code true} if this is the last part of the message, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
568 |
* {@code false} otherwise |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
569 |
* |
48083 | 570 |
* @return a {@code CompletableFuture} that completes, with this |
571 |
* {@code WebSocket}, when the message has been sent |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
572 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
573 |
CompletableFuture<WebSocket> sendBinary(ByteBuffer message, boolean isLast); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
574 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
575 |
/** |
48083 | 576 |
* Sends a Ping message with bytes from the given {@code ByteBuffer}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
577 |
* |
48083 | 578 |
* <p> The message consists of not more than {@code 125} bytes from the |
579 |
* buffer's position to its limit. Upon normal completion of a |
|
580 |
* {@code CompletableFuture} returned from this method the buffer will |
|
581 |
* have no remaining bytes. The buffer must not be accessed until after that. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
582 |
* |
48083 | 583 |
* <p> The {@code CompletableFuture} returned from this method can |
584 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
585 |
* <ul> |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
586 |
* <li> {@link IllegalStateException} - |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
587 |
* if the previous Ping or Pong message has not been sent yet |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
588 |
* <li> {@link IllegalArgumentException} - |
48083 | 589 |
* if the message is too long |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
590 |
* <li> {@link IOException} - |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
591 |
* if an I/O error occurs, or if the output is closed |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
592 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
593 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
594 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
595 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
596 |
* |
48083 | 597 |
* @return a {@code CompletableFuture} that completes, with this |
598 |
* {@code WebSocket}, when the Ping message has been sent |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
599 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
600 |
CompletableFuture<WebSocket> sendPing(ByteBuffer message); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
601 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
602 |
/** |
48083 | 603 |
* Sends a Pong message with bytes from the given {@code ByteBuffer}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
604 |
* |
48083 | 605 |
* <p> The message consists of not more than {@code 125} bytes from the |
606 |
* buffer's position to its limit. Upon normal completion of a |
|
607 |
* {@code CompletableFuture} returned from this method the buffer will have |
|
608 |
* no remaining bytes. The buffer must not be accessed until after that. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
609 |
* |
48083 | 610 |
* <p> The {@code CompletableFuture} returned from this method can |
611 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
612 |
* <ul> |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
613 |
* <li> {@link IllegalStateException} - |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
614 |
* if the previous Ping or Pong message has not been sent yet |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
615 |
* <li> {@link IllegalArgumentException} - |
48083 | 616 |
* if the message is too long |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
617 |
* <li> {@link IOException} - |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
618 |
* if an I/O error occurs, or if the output is closed |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
619 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
620 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
621 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
622 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
623 |
* |
48083 | 624 |
* @return a {@code CompletableFuture} that completes, with this |
625 |
* {@code WebSocket}, when the Pong message has been sent |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
626 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
627 |
CompletableFuture<WebSocket> sendPong(ByteBuffer message); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
628 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
629 |
/** |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
630 |
* Initiates an orderly closure of this {@code WebSocket}'s output by |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
631 |
* sending a Close message with the given status code and the reason. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
632 |
* |
48083 | 633 |
* <p> The {@code statusCode} is an integer from the range |
634 |
* {@code 1000 <= code <= 4999}. Status codes {@code 1002}, {@code 1003}, |
|
635 |
* {@code 1006}, {@code 1007}, {@code 1009}, {@code 1010}, {@code 1012}, |
|
636 |
* {@code 1013} and {@code 1015} are illegal. Behaviour in respect to other |
|
637 |
* status codes is implementation-specific. The {@code reason} is a string |
|
638 |
* that has an UTF-8 representation not longer than {@code 123} bytes. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
639 |
* |
48083 | 640 |
* <p> A {@code CompletableFuture} returned from this method can |
641 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
642 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
643 |
* <li> {@link IllegalArgumentException} - |
56263 | 644 |
* if {@code statusCode} is illegal |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
645 |
* <li> {@link IOException} - |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
646 |
* if an I/O error occurs, or if the output is closed |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
647 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
648 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
649 |
* <p> Unless the {@code CompletableFuture} returned from this method |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
650 |
* completes with {@code IllegalArgumentException}, or the method throws |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
651 |
* {@code NullPointerException}, the output will be closed. |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
652 |
* |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
653 |
* <p> If not already closed, the input remains open until it is |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
654 |
* {@linkplain Listener#onClose(WebSocket, int, String) closed} by the server, |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
655 |
* or {@code abort} is invoked, or an |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
656 |
* {@linkplain Listener#onError(WebSocket, Throwable) error} occurs. |
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
657 |
* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
658 |
* @apiNote Use the provided integer constant {@link #NORMAL_CLOSURE} as a |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
659 |
* status code and an empty string as a reason in a typical case |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
660 |
* <pre>{@code |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
661 |
* CompletableFuture<WebSocket> webSocket = ... |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
662 |
* webSocket.thenCompose(ws -> ws.sendText("Hello, ", false)) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
663 |
* .thenCompose(ws -> ws.sendText("world!", true)) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
664 |
* .thenCompose(ws -> ws.sendClose(WebSocket.NORMAL_CLOSURE, "")) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
665 |
* .join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
666 |
* }</pre> |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
667 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
668 |
* @param statusCode |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
669 |
* the status code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
670 |
* @param reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
671 |
* the reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
672 |
* |
48083 | 673 |
* @return a {@code CompletableFuture} that completes, with this |
674 |
* {@code WebSocket}, when the Close message has been sent |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
675 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
676 |
CompletableFuture<WebSocket> sendClose(int statusCode, String reason); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
677 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
678 |
/** |
48083 | 679 |
* Requests {@code n} more messages from this {@code WebSocket}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
680 |
* |
48083 | 681 |
* <p> This {@code WebSocket} will invoke its listener's {@code onText}, |
682 |
* {@code onBinary}, {@code onPing}, {@code onPong} or {@code onClose} |
|
683 |
* methods up to {@code n} more times. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
684 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
685 |
* @param n |
48083 | 686 |
* the number of messages requested |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
687 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
688 |
* @throws IllegalArgumentException |
48083 | 689 |
* if {@code n <= 0} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
690 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
691 |
void request(long n); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
692 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
693 |
/** |
48083 | 694 |
* Returns the subprotocol for this {@code WebSocket}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
695 |
* |
48083 | 696 |
* @return the subprotocol for this {@code WebSocket}, or an empty |
697 |
* {@code String} if there's no subprotocol |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
698 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
699 |
String getSubprotocol(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
700 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
701 |
/** |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
702 |
* Tells whether this {@code WebSocket}'s output is closed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
703 |
* |
48083 | 704 |
* <p> If this method returns {@code true}, subsequent invocations will also |
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
705 |
* return {@code true}. |
48083 | 706 |
* |
707 |
* @return {@code true} if closed, {@code false} otherwise |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
708 |
*/ |
48083 | 709 |
boolean isOutputClosed(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
710 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
711 |
/** |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
712 |
* Tells whether this {@code WebSocket}'s input is closed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
713 |
* |
48083 | 714 |
* <p> If this method returns {@code true}, subsequent invocations will also |
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
715 |
* return {@code true}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
716 |
* |
48083 | 717 |
* @return {@code true} if closed, {@code false} otherwise |
718 |
*/ |
|
719 |
boolean isInputClosed(); |
|
720 |
||
721 |
/** |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
722 |
* Closes this {@code WebSocket}'s input and output abruptly. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
723 |
* |
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56039
diff
changeset
|
724 |
* <p> When this method returns both the input and the output will have been |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
725 |
* closed. Any pending send operations will fail with {@code IOException}. |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56263
diff
changeset
|
726 |
* Subsequent invocations of {@code abort()} will have no effect. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
727 |
*/ |
48083 | 728 |
void abort(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
729 |
} |