author | bulasevich |
Wed, 20 Nov 2019 09:29:23 +0300 | |
changeset 59143 | 1037c4d14378 |
parent 52053 | 7ecbaece746f |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
49765 | 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 |
|
49765 | 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 |
/** |
49765 | 36 |
* A WebSocket Client. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
* |
50681 | 38 |
* <p> {@code WebSocket} instances are created through {@link WebSocket.Builder}. |
48083 | 39 |
* |
50681 | 40 |
* <p> WebSocket has an input and an output side. These sides are independent |
49765 | 41 |
* from each other. A side can either be open or closed. Once closed, the side |
42 |
* remains closed. WebSocket messages are sent through a {@code WebSocket} and |
|
43 |
* received through a {@code WebSocket.Listener} associated with it. Messages |
|
44 |
* can be sent until the WebSocket's output is closed, and received until the |
|
45 |
* WebSocket's input is closed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
46 |
* |
49765 | 47 |
* <p> A send method is any of the {@code sendText}, {@code sendBinary}, |
48 |
* {@code sendPing}, {@code sendPong} and {@code sendClose} methods of |
|
49 |
* {@code WebSocket}. A send method initiates a send operation and returns a |
|
50 |
* {@code CompletableFuture} which completes once the operation has completed. |
|
51 |
* If the {@code CompletableFuture} completes normally the operation is |
|
52 |
* considered succeeded. If the {@code CompletableFuture} completes |
|
53 |
* exceptionally, the operation is considered failed. An operation that has been |
|
54 |
* initiated but not yet completed is considered pending. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
55 |
* |
49765 | 56 |
* <p> A receive method is any of the {@code onText}, {@code onBinary}, |
57 |
* {@code onPing}, {@code onPong} and {@code onClose} methods of |
|
50681 | 58 |
* {@code Listener}. WebSocket initiates a receive operation by invoking a |
59 |
* receive method on the listener. The listener then must return a |
|
60 |
* {@code CompletionStage} which completes once the operation has completed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
61 |
* |
50681 | 62 |
* <p> To control receiving of messages, a WebSocket maintains an |
63 |
* <a id="counter">internal counter</a>. This counter's value is a number of |
|
64 |
* times the WebSocket has yet to invoke a receive method. While this counter is |
|
65 |
* zero the WebSocket does not invoke receive methods. The counter is |
|
66 |
* incremented by {@code n} when {@code request(n)} is called. The counter is |
|
67 |
* decremented by one when the WebSocket invokes a receive method. |
|
68 |
* {@code onOpen} and {@code onError} are not receive methods. WebSocket invokes |
|
69 |
* {@code onOpen} prior to any other methods on the listener. WebSocket invokes |
|
70 |
* {@code onOpen} at most once. WebSocket may invoke {@code onError} at any |
|
71 |
* given time. If the WebSocket invokes {@code onError} or {@code onClose}, then |
|
72 |
* no further listener's methods will be invoked, no matter the value of the |
|
73 |
* counter. For a newly built WebSocket the counter is zero. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
74 |
* |
48083 | 75 |
* <p> Unless otherwise stated, {@code null} arguments will cause methods |
76 |
* of {@code WebSocket} to throw {@code NullPointerException}, similarly, |
|
77 |
* {@code WebSocket} will not pass {@code null} arguments to methods of |
|
49765 | 78 |
* {@code Listener}. The state of a WebSocket is not changed by the invocations |
79 |
* that throw or return a {@code CompletableFuture} that completes with one of |
|
80 |
* the {@code NullPointerException}, {@code IllegalArgumentException}, |
|
81 |
* {@code IllegalStateException} exceptions. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
82 |
* |
49765 | 83 |
* <p> {@code WebSocket} handles received Ping and Close messages automatically |
84 |
* (as per the WebSocket Protocol) by replying with Pong and Close messages. If |
|
85 |
* the listener receives Ping or Close messages, no mandatory actions from the |
|
48083 | 86 |
* listener are required. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
87 |
* |
49765 | 88 |
* @apiNote The relationship between a WebSocket and the associated Listener is |
89 |
* analogous to that of a Subscription and the associated Subscriber of type |
|
90 |
* {@link java.util.concurrent.Flow}. |
|
91 |
* |
|
92 |
* @since 11 |
|
42460
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 |
public interface WebSocket { |
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 |
* 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
|
98 |
* 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
|
99 |
* connection was established has been fulfilled. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
100 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
101 |
* @see #sendClose(int, String) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
102 |
* @see Listener#onClose(WebSocket, int, String) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
103 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
104 |
int NORMAL_CLOSURE = 1000; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
105 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
106 |
/** |
49765 | 107 |
* A builder of {@linkplain WebSocket WebSocket Clients}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
108 |
* |
50681 | 109 |
* <p> Builders are created by invoking |
110 |
* {@link HttpClient#newWebSocketBuilder HttpClient.newWebSocketBuilder}. |
|
111 |
* The intermediate (setter-like) methods change the state of the builder |
|
112 |
* and return the same builder they have been invoked on. If an intermediate |
|
113 |
* method is not invoked, an appropriate default value (or behavior) will be |
|
114 |
* assumed. A {@code Builder} is not safe for use by multiple threads |
|
115 |
* without external synchronization. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
116 |
* |
49765 | 117 |
* @since 11 |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
118 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
119 |
interface Builder { |
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 |
/** |
48083 | 122 |
* Adds the given name-value pair to the list of additional HTTP headers |
123 |
* sent during the opening handshake. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
124 |
* |
49765 | 125 |
* <p> Headers defined in the |
126 |
* <a href="https://tools.ietf.org/html/rfc6455#section-11.3">WebSocket |
|
127 |
* Protocol</a> are illegal. If this method is not invoked, no |
|
128 |
* 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
|
129 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
130 |
* @param name |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
131 |
* the header name |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
132 |
* @param value |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
133 |
* the header value |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
134 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
135 |
* @return this builder |
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 |
Builder header(String name, String value); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
138 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
139 |
/** |
48083 | 140 |
* 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
|
141 |
* |
48083 | 142 |
* <p> If the connection is not established within the specified |
143 |
* duration then building of the {@code WebSocket} will fail with |
|
144 |
* {@link HttpTimeoutException}. If this method is not invoked then the |
|
145 |
* infinite timeout is assumed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
146 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
147 |
* @param timeout |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
148 |
* 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
|
149 |
* non-{@linkplain Duration#ZERO ZERO} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
150 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
151 |
* @return this builder |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
152 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
153 |
Builder connectTimeout(Duration timeout); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
154 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
155 |
/** |
48083 | 156 |
* Sets a request for the given subprotocols. |
157 |
* |
|
158 |
* <p> After the {@code WebSocket} has been built, the actual |
|
50681 | 159 |
* subprotocol can be queried through |
48083 | 160 |
* {@link WebSocket#getSubprotocol WebSocket.getSubprotocol()}. |
161 |
* |
|
162 |
* <p> Subprotocols are specified in the order of preference. The most |
|
163 |
* preferred subprotocol is specified first. If there are any additional |
|
164 |
* subprotocols they are enumerated from the most preferred to the least |
|
165 |
* preferred. |
|
166 |
* |
|
167 |
* <p> Subprotocols not conforming to the syntax of subprotocol |
|
168 |
* identifiers are illegal. If this method is not invoked then no |
|
169 |
* subprotocols will be requested. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
170 |
* |
48083 | 171 |
* @param mostPreferred |
172 |
* the most preferred subprotocol |
|
173 |
* @param lesserPreferred |
|
174 |
* the lesser preferred subprotocols |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
175 |
* |
48083 | 176 |
* @return this builder |
177 |
*/ |
|
178 |
Builder subprotocols(String mostPreferred, String... lesserPreferred); |
|
179 |
||
180 |
/** |
|
181 |
* Builds a {@link WebSocket} connected to the given {@code URI} and |
|
182 |
* associated with the given {@code Listener}. |
|
183 |
* |
|
184 |
* <p> Returns a {@code CompletableFuture} which will either complete |
|
185 |
* normally with the resulting {@code WebSocket} or complete |
|
186 |
* 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
|
187 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
188 |
* <li> {@link IOException} - |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
189 |
* if an I/O error occurs |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
190 |
* <li> {@link WebSocketHandshakeException} - |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
191 |
* if the opening handshake fails |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
192 |
* <li> {@link HttpTimeoutException} - |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
193 |
* if the opening handshake does not complete within |
48083 | 194 |
* the timeout |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
195 |
* <li> {@link InterruptedException} - |
48083 | 196 |
* if the operation is interrupted |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
197 |
* <li> {@link SecurityException} - |
48083 | 198 |
* if a security manager has been installed and it denies |
199 |
* {@link java.net.URLPermission access} to {@code uri}. |
|
52053
7ecbaece746f
8211902: broken link in java.net.http.WebSocket.Builder
chegar
parents:
50681
diff
changeset
|
200 |
* <a href="HttpClient.html#securitychecks">Security checks</a> |
48083 | 201 |
* contains more information relating to the security context |
52053
7ecbaece746f
8211902: broken link in java.net.http.WebSocket.Builder
chegar
parents:
50681
diff
changeset
|
202 |
* in which the listener is invoked. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
203 |
* <li> {@link IllegalArgumentException} - |
48083 | 204 |
* if any of the arguments of this builder's methods are |
205 |
* illegal |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
206 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
207 |
* |
48083 | 208 |
* @param uri |
209 |
* the WebSocket URI |
|
210 |
* @param listener |
|
211 |
* the listener |
|
212 |
* |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
213 |
* @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
|
214 |
*/ |
48083 | 215 |
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
|
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 |
/** |
48083 | 219 |
* 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
|
220 |
* |
49765 | 221 |
* <p> A {@code WebSocket} invokes methods of the associated listener |
50681 | 222 |
* passing itself as an argument. These methods are invoked in a thread-safe |
223 |
* manner, such that the next invocation may start only after the previous |
|
224 |
* one has finished. |
|
225 |
* |
|
226 |
* <p> When data has been received, the {@code WebSocket} invokes a receive |
|
227 |
* method. Methods {@code onText}, {@code onBinary}, {@code onPing} and |
|
228 |
* {@code onPong} must return a {@code CompletionStage} that completes once |
|
229 |
* the message has been received by the listener. If a listener's method |
|
230 |
* returns {@code null} rather than a {@code CompletionStage}, |
|
231 |
* {@code WebSocket} will behave as if the listener returned a |
|
232 |
* {@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
|
233 |
* |
49765 | 234 |
* <p> An {@code IOException} raised in {@code WebSocket} will result in an |
235 |
* invocation of {@code onError} with that exception (if the input is not |
|
236 |
* closed). Unless otherwise stated if the listener's method throws an |
|
237 |
* exception or a {@code CompletionStage} returned from a method completes |
|
238 |
* exceptionally, the WebSocket will invoke {@code onError} with this |
|
239 |
* exception. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
240 |
* |
50681 | 241 |
* @apiNote The strict sequential order of invocations from |
242 |
* {@code WebSocket} to {@code Listener} means, in particular, that the |
|
243 |
* {@code Listener}'s methods are treated as non-reentrant. This means that |
|
244 |
* {@code Listener} implementations do not need to be concerned with |
|
245 |
* possible recursion or the order in which they invoke |
|
246 |
* {@code WebSocket.request} in relation to their processing logic. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
247 |
* |
50681 | 248 |
* <p> Careful attention may be required if a listener is associated |
49765 | 249 |
* with more than a single {@code WebSocket}. In this case invocations |
250 |
* related to different instances of {@code WebSocket} may not be ordered |
|
251 |
* and may even happen concurrently. |
|
252 |
* |
|
253 |
* <p> {@code CompletionStage}s returned from the receive methods have |
|
254 |
* nothing to do with the |
|
255 |
* <a href="WebSocket.html#counter">counter of invocations</a>. |
|
256 |
* Namely, a {@code CompletionStage} does not have to be completed in order |
|
257 |
* to receive more invocations of the listener's methods. |
|
258 |
* Here is an example of a listener that requests invocations, one at a |
|
259 |
* time, until a complete message has been accumulated, then processes |
|
260 |
* the result, and completes the {@code CompletionStage}: |
|
261 |
* <pre>{@code WebSocket.Listener listener = new WebSocket.Listener() { |
|
262 |
* |
|
263 |
* List<CharSequence> parts = new ArrayList<>(); |
|
264 |
* CompletableFuture<?> accumulatedMessage = new CompletableFuture<>(); |
|
265 |
* |
|
266 |
* public CompletionStage<?> onText(WebSocket webSocket, |
|
267 |
* CharSequence message, |
|
268 |
* boolean last) { |
|
269 |
* parts.add(message); |
|
270 |
* webSocket.request(1); |
|
271 |
* if (last) { |
|
272 |
* processWholeText(parts); |
|
273 |
* parts = new ArrayList<>(); |
|
274 |
* accumulatedMessage.complete(null); |
|
275 |
* CompletionStage<?> cf = accumulatedMessage; |
|
276 |
* accumulatedMessage = new CompletableFuture<>(); |
|
277 |
* return cf; |
|
278 |
* } |
|
279 |
* return accumulatedMessage; |
|
280 |
* } |
|
281 |
* ... |
|
282 |
* } } </pre> |
|
283 |
* |
|
284 |
* @since 11 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
285 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
286 |
interface Listener { |
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 |
/** |
48083 | 289 |
* 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
|
290 |
* |
49765 | 291 |
* <p> This is the initial invocation and it is made once. It is |
292 |
* typically used to make a request for more invocations. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
293 |
* |
49765 | 294 |
* @implSpec The default implementation is equivalent to: |
295 |
* <pre>{@code webSocket.request(1); }</pre> |
|
42460
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 |
* @param webSocket |
48083 | 298 |
* 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
|
299 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
300 |
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
|
301 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
302 |
/** |
49765 | 303 |
* A textual data has been received. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
304 |
* |
48083 | 305 |
* <p> Return a {@code CompletionStage} which will be used by the |
49765 | 306 |
* {@code WebSocket} as an indication it may reclaim the |
48083 | 307 |
* {@code CharSequence}. Do not access the {@code CharSequence} after |
49765 | 308 |
* this {@code CompletionStage} has completed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
309 |
* |
49765 | 310 |
* @implSpec The default implementation is equivalent to: |
311 |
* <pre>{@code webSocket.request(1); |
|
312 |
* return null; }</pre> |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
313 |
* |
49765 | 314 |
* @implNote The {@code data} is always a legal UTF-16 sequence. |
42460
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 |
* @param webSocket |
49765 | 317 |
* the WebSocket on which the data has been received |
318 |
* @param data |
|
319 |
* the data |
|
320 |
* @param last |
|
321 |
* whether this invocation completes the message |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
322 |
* |
48083 | 323 |
* @return a {@code CompletionStage} which completes when the |
324 |
* {@code CharSequence} may be reclaimed; or {@code null} if it may be |
|
325 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
326 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
327 |
default CompletionStage<?> onText(WebSocket webSocket, |
49765 | 328 |
CharSequence data, |
329 |
boolean last) { |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
330 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
331 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
332 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
333 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
334 |
/** |
49765 | 335 |
* A binary data has been received. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
336 |
* |
49765 | 337 |
* <p> This data is located in bytes from the buffer's position to its |
338 |
* limit. |
|
48083 | 339 |
* |
340 |
* <p> Return a {@code CompletionStage} which will be used by the |
|
49765 | 341 |
* {@code WebSocket} as an indication it may reclaim the |
48083 | 342 |
* {@code ByteBuffer}. Do not access the {@code ByteBuffer} after |
49765 | 343 |
* this {@code CompletionStage} has completed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
344 |
* |
49765 | 345 |
* @implSpec The default implementation is equivalent to: |
346 |
* <pre>{@code webSocket.request(1); |
|
347 |
* return null; }</pre> |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
348 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
349 |
* @param webSocket |
49765 | 350 |
* the WebSocket on which the data has been received |
351 |
* @param data |
|
352 |
* the data |
|
353 |
* @param last |
|
354 |
* whether this invocation completes the message |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
355 |
* |
48083 | 356 |
* @return a {@code CompletionStage} which completes when the |
357 |
* {@code ByteBuffer} may be reclaimed; or {@code null} if it may be |
|
358 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
359 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
360 |
default CompletionStage<?> onBinary(WebSocket webSocket, |
49765 | 361 |
ByteBuffer data, |
362 |
boolean last) { |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
363 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
364 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
365 |
} |
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 |
/** |
48083 | 368 |
* 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
|
369 |
* |
49765 | 370 |
* <p> As guaranteed by the WebSocket Protocol, the message consists of |
371 |
* not more than {@code 125} bytes. These bytes are located from the |
|
372 |
* buffer's position to its limit. |
|
373 |
* |
|
374 |
* <p> Given that the WebSocket implementation will automatically send a |
|
375 |
* reciprocal pong when a ping is received, it is rarely required to |
|
376 |
* send a pong message explicitly when a ping is received. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
377 |
* |
48083 | 378 |
* <p> Return a {@code CompletionStage} which will be used by the |
379 |
* {@code WebSocket} as a signal it may reclaim the |
|
380 |
* {@code ByteBuffer}. Do not access the {@code ByteBuffer} after |
|
49765 | 381 |
* this {@code CompletionStage} has completed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
382 |
* |
49765 | 383 |
* @implSpec The default implementation is equivalent to: |
384 |
* <pre>{@code webSocket.request(1); |
|
385 |
* return null; }</pre> |
|
42460
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 |
* @param webSocket |
48083 | 388 |
* 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
|
389 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
390 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
391 |
* |
48083 | 392 |
* @return a {@code CompletionStage} which completes when the |
393 |
* {@code ByteBuffer} may be reclaimed; or {@code null} if it may be |
|
394 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
395 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
396 |
default CompletionStage<?> onPing(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
397 |
ByteBuffer message) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
398 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
399 |
return null; |
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 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
402 |
/** |
48083 | 403 |
* 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
|
404 |
* |
49765 | 405 |
* <p> As guaranteed by the WebSocket Protocol, the message consists of |
406 |
* not more than {@code 125} bytes. These bytes are located from the |
|
407 |
* 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
|
408 |
* |
48083 | 409 |
* <p> Return a {@code CompletionStage} which will be used by the |
410 |
* {@code WebSocket} as a signal it may reclaim the |
|
411 |
* {@code ByteBuffer}. Do not access the {@code ByteBuffer} after |
|
49765 | 412 |
* this {@code CompletionStage} has completed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
413 |
* |
49765 | 414 |
* @implSpec The default implementation is equivalent to: |
415 |
* <pre>{@code webSocket.request(1); |
|
416 |
* return null; }</pre> |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
417 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
418 |
* @param webSocket |
48083 | 419 |
* 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
|
420 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
421 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
422 |
* |
48083 | 423 |
* @return a {@code CompletionStage} which completes when the |
424 |
* {@code ByteBuffer} may be reclaimed; or {@code null} if it may be |
|
425 |
* reclaimed immediately |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
426 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
427 |
default CompletionStage<?> onPong(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
428 |
ByteBuffer message) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
429 |
webSocket.request(1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
430 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
431 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
432 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
433 |
/** |
49765 | 434 |
* Receives a Close message indicating the WebSocket's input has been |
435 |
* closed. |
|
48083 | 436 |
* |
49765 | 437 |
* <p> This is the last invocation from the specified {@code WebSocket}. |
438 |
* By the time this invocation begins the WebSocket's input will have |
|
439 |
* been closed. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
440 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
441 |
* <p> A Close message consists of a status code and a reason for |
48083 | 442 |
* closing. The status code is an integer from the range |
443 |
* {@code 1000 <= code <= 65535}. The {@code reason} is a string which |
|
49765 | 444 |
* has a UTF-8 representation not longer than {@code 123} bytes. |
445 |
* |
|
446 |
* <p> If the WebSocket's output is not already closed, the |
|
447 |
* {@code CompletionStage} returned by this method will be used as an |
|
448 |
* indication that the WebSocket's output may be closed. The WebSocket |
|
449 |
* will close its output at the earliest of completion of the returned |
|
450 |
* {@code CompletionStage} or invoking either of the {@code sendClose} |
|
451 |
* or {@code abort} methods. |
|
452 |
* |
|
453 |
* @apiNote Returning a {@code CompletionStage} that never completes, |
|
454 |
* effectively disables the reciprocating closure of the output. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
455 |
* |
49765 | 456 |
* <p> To specify a custom closure code or reason code the |
457 |
* {@code sendClose} method may be invoked from inside the |
|
458 |
* {@code onClose} invocation: |
|
459 |
* <pre>{@code public CompletionStage<?> onClose(WebSocket webSocket, |
|
460 |
* int statusCode, |
|
461 |
* String reason) { |
|
462 |
* webSocket.sendClose(CUSTOM_STATUS_CODE, CUSTOM_REASON); |
|
463 |
* return new CompletableFuture<Void>(); |
|
464 |
* } } </pre> |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
465 |
* |
49765 | 466 |
* @implSpec The default implementation of this method returns |
467 |
* {@code null}, indicating that the output should be closed |
|
468 |
* immediately. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
469 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
470 |
* @param webSocket |
48083 | 471 |
* 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
|
472 |
* @param statusCode |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
473 |
* the status code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
474 |
* @param reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
475 |
* the reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
476 |
* |
48083 | 477 |
* @return a {@code CompletionStage} which completes when the |
478 |
* {@code WebSocket} may be closed; or {@code null} if it may be |
|
479 |
* closed immediately |
|
42460
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 CompletionStage<?> onClose(WebSocket webSocket, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
482 |
int statusCode, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
483 |
String reason) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
484 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
485 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
486 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
487 |
/** |
49765 | 488 |
* An error has occurred. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
489 |
* |
49765 | 490 |
* <p> This is the last invocation from the specified WebSocket. By the |
491 |
* time this invocation begins both the WebSocket's input and output |
|
492 |
* will have been closed. A WebSocket may invoke this method on the |
|
493 |
* associated listener at any time after it has invoked {@code onOpen}, |
|
494 |
* regardless of whether or not any invocations have been requested from |
|
495 |
* the WebSocket. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
496 |
* |
48083 | 497 |
* <p> If an exception is thrown from this method, resulting behavior is |
498 |
* undefined. |
|
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 |
* @param webSocket |
48083 | 501 |
* 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
|
502 |
* @param error |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
503 |
* the error |
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 |
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
|
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 |
/** |
49765 | 509 |
* Sends textual data with characters from the given character sequence. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
510 |
* |
49765 | 511 |
* <p> The character sequence must not be modified until the |
512 |
* {@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
|
513 |
* |
48083 | 514 |
* <p> A {@code CompletableFuture} returned from this method can |
515 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
516 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
517 |
* <li> {@link IllegalStateException} - |
49765 | 518 |
* if there is a pending text or binary send operation |
519 |
* or if the previous binary data does not complete the message |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
520 |
* <li> {@link IOException} - |
49765 | 521 |
* 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
|
522 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
523 |
* |
49765 | 524 |
* @implNote If {@code data} is a malformed UTF-16 sequence, the operation |
525 |
* will fail with {@code IOException}. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
526 |
* |
49765 | 527 |
* @param data |
528 |
* the data |
|
529 |
* @param last |
|
530 |
* {@code true} if this invocation completes the message, |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
531 |
* {@code false} otherwise |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
532 |
* |
49765 | 533 |
* @return a {@code CompletableFuture} that completes, with this WebSocket, |
534 |
* when the data has been sent |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
535 |
*/ |
49765 | 536 |
CompletableFuture<WebSocket> sendText(CharSequence data, boolean last); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
537 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
538 |
/** |
49765 | 539 |
* Sends binary data with bytes from the given buffer. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
540 |
* |
49765 | 541 |
* <p> The data is located in bytes from the buffer's position to its limit. |
542 |
* Upon normal completion of a {@code CompletableFuture} returned from this |
|
543 |
* method the buffer will have no remaining bytes. The buffer must not be |
|
544 |
* accessed until after that. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
545 |
* |
48083 | 546 |
* <p> The {@code CompletableFuture} returned from this method can |
547 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
548 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
549 |
* <li> {@link IllegalStateException} - |
49765 | 550 |
* if there is a pending text or binary send operation |
551 |
* or if the previous textual data does not complete the message |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
552 |
* <li> {@link IOException} - |
49765 | 553 |
* 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
|
554 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
555 |
* |
49765 | 556 |
* @param data |
557 |
* the data |
|
558 |
* @param last |
|
559 |
* {@code true} if this invocation completes the message, |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
560 |
* {@code false} otherwise |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
561 |
* |
49765 | 562 |
* @return a {@code CompletableFuture} that completes, with this WebSocket, |
563 |
* when the data has been sent |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
564 |
*/ |
49765 | 565 |
CompletableFuture<WebSocket> sendBinary(ByteBuffer data, boolean last); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
566 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
567 |
/** |
49765 | 568 |
* Sends a Ping message with bytes from the given buffer. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
569 |
* |
48083 | 570 |
* <p> The message consists of not more than {@code 125} bytes from the |
571 |
* buffer's position to its limit. Upon normal completion of a |
|
572 |
* {@code CompletableFuture} returned from this method the buffer will |
|
573 |
* 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
|
574 |
* |
48083 | 575 |
* <p> The {@code CompletableFuture} returned from this method can |
576 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
577 |
* <ul> |
49765 | 578 |
* <li> {@link IllegalStateException} - |
579 |
* if there is a pending ping or pong send operation |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
580 |
* <li> {@link IllegalArgumentException} - |
48083 | 581 |
* 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
|
582 |
* <li> {@link IOException} - |
49765 | 583 |
* 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
|
584 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
585 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
586 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
587 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
588 |
* |
49765 | 589 |
* @return a {@code CompletableFuture} that completes, with this WebSocket, |
590 |
* 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
|
591 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
592 |
CompletableFuture<WebSocket> sendPing(ByteBuffer message); |
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 |
/** |
49765 | 595 |
* Sends a Pong message with bytes from the given buffer. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
596 |
* |
48083 | 597 |
* <p> The message consists of not more than {@code 125} bytes from the |
598 |
* buffer's position to its limit. Upon normal completion of a |
|
599 |
* {@code CompletableFuture} returned from this method the buffer will have |
|
600 |
* 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
|
601 |
* |
49765 | 602 |
* <p> Given that the WebSocket implementation will automatically send a |
603 |
* reciprocal pong when a ping is received, it is rarely required to send a |
|
604 |
* pong message explicitly. |
|
605 |
* |
|
48083 | 606 |
* <p> The {@code CompletableFuture} returned from this method can |
607 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
608 |
* <ul> |
49765 | 609 |
* <li> {@link IllegalStateException} - |
610 |
* if there is a pending ping or pong send operation |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
611 |
* <li> {@link IllegalArgumentException} - |
48083 | 612 |
* 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
|
613 |
* <li> {@link IOException} - |
49765 | 614 |
* 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
|
615 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
616 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
617 |
* @param message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
618 |
* the message |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
619 |
* |
49765 | 620 |
* @return a {@code CompletableFuture} that completes, with this WebSocket, |
621 |
* 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
|
622 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
623 |
CompletableFuture<WebSocket> sendPong(ByteBuffer message); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
624 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
625 |
/** |
49765 | 626 |
* Initiates an orderly closure of this WebSocket's output by |
627 |
* 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
|
628 |
* |
48083 | 629 |
* <p> The {@code statusCode} is an integer from the range |
630 |
* {@code 1000 <= code <= 4999}. Status codes {@code 1002}, {@code 1003}, |
|
631 |
* {@code 1006}, {@code 1007}, {@code 1009}, {@code 1010}, {@code 1012}, |
|
632 |
* {@code 1013} and {@code 1015} are illegal. Behaviour in respect to other |
|
49765 | 633 |
* status codes is implementation-specific. A legal {@code reason} is a |
634 |
* string that has a 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
|
635 |
* |
48083 | 636 |
* <p> A {@code CompletableFuture} returned from this method can |
637 |
* complete exceptionally with: |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
638 |
* <ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
639 |
* <li> {@link IllegalArgumentException} - |
49765 | 640 |
* if {@code statusCode} is illegal, or |
641 |
* if {@code reason} is illegal |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
642 |
* <li> {@link IOException} - |
49765 | 643 |
* 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
|
644 |
* </ul> |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
645 |
* |
49765 | 646 |
* <p> Unless the {@code CompletableFuture} returned from this method |
647 |
* completes with {@code IllegalArgumentException}, or the method throws |
|
648 |
* {@code NullPointerException}, the output will be closed. |
|
649 |
* |
|
650 |
* <p> If not already closed, the input remains open until a Close message |
|
651 |
* {@linkplain Listener#onClose(WebSocket, int, String) received}, or |
|
652 |
* {@code abort} is invoked, or an |
|
653 |
* {@linkplain Listener#onError(WebSocket, Throwable) error} occurs. |
|
654 |
* |
|
655 |
* @apiNote Use the provided integer constant {@link #NORMAL_CLOSURE} as a |
|
656 |
* status code and an empty string as a reason in a typical case: |
|
657 |
* <pre>{@code CompletableFuture<WebSocket> webSocket = ... |
|
658 |
* webSocket.thenCompose(ws -> ws.sendText("Hello, ", false)) |
|
659 |
* .thenCompose(ws -> ws.sendText("world!", true)) |
|
660 |
* .thenCompose(ws -> ws.sendClose(WebSocket.NORMAL_CLOSURE, "")) |
|
661 |
* .join(); }</pre> |
|
662 |
* |
|
663 |
* The {@code sendClose} method does not close this WebSocket's input. It |
|
664 |
* merely closes this WebSocket's output by sending a Close message. To |
|
665 |
* enforce closing the input, invoke the {@code abort} method. Here is an |
|
666 |
* example of an application that sends a Close message, and then starts a |
|
667 |
* timer. Once no data has been received within the specified timeout, the |
|
668 |
* timer goes off and the alarm aborts {@code WebSocket}: |
|
669 |
* <pre>{@code MyAlarm alarm = new MyAlarm(webSocket::abort); |
|
670 |
* WebSocket.Listener listener = new WebSocket.Listener() { |
|
671 |
* |
|
672 |
* public CompletionStage<?> onText(WebSocket webSocket, |
|
673 |
* CharSequence data, |
|
674 |
* boolean last) { |
|
675 |
* alarm.snooze(); |
|
676 |
* ... |
|
677 |
* } |
|
678 |
* ... |
|
679 |
* }; |
|
680 |
* ... |
|
681 |
* Runnable startTimer = () -> { |
|
682 |
* MyTimer idleTimer = new MyTimer(); |
|
683 |
* idleTimer.add(alarm, 30, TimeUnit.SECONDS); |
|
684 |
* }; |
|
685 |
* webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok").thenRun(startTimer); |
|
686 |
* } </pre> |
|
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 |
* @param statusCode |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
689 |
* the status code |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
690 |
* @param reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
691 |
* the reason |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
692 |
* |
49765 | 693 |
* @return a {@code CompletableFuture} that completes, with this WebSocket, |
694 |
* 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
|
695 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
696 |
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
|
697 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
698 |
/** |
49765 | 699 |
* Increments the counter of invocations of receive methods. |
700 |
* |
|
701 |
* <p> This WebSocket will invoke {@code onText}, {@code onBinary}, |
|
702 |
* {@code onPing}, {@code onPong} or {@code onClose} methods on the |
|
703 |
* associated listener (i.e. receive methods) up to {@code n} more times. |
|
704 |
* |
|
705 |
* @apiNote The parameter of this method is the number of invocations being |
|
706 |
* requested from this WebSocket to the associated listener, not the number |
|
707 |
* of messages. Sometimes a message may be delivered to the listener in a |
|
708 |
* single invocation, but not always. For example, Ping, Pong and Close |
|
709 |
* messages are delivered in a single invocation of {@code onPing}, |
|
710 |
* {@code onPong} and {@code onClose} methods respectively. However, whether |
|
711 |
* or not Text and Binary messages are delivered in a single invocation of |
|
712 |
* {@code onText} and {@code onBinary} methods depends on the boolean |
|
713 |
* argument ({@code last}) of these methods. If {@code last} is |
|
714 |
* {@code false}, then there is more to a message than has been delivered to |
|
715 |
* the invocation. |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
716 |
* |
49765 | 717 |
* <p> Here is an example of a listener that requests invocations, one at a |
718 |
* time, until a complete message has been accumulated, and then processes |
|
719 |
* the result: |
|
720 |
* <pre>{@code WebSocket.Listener listener = new WebSocket.Listener() { |
|
721 |
* |
|
722 |
* StringBuilder text = new StringBuilder(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
723 |
* |
49765 | 724 |
* public CompletionStage<?> onText(WebSocket webSocket, |
725 |
* CharSequence message, |
|
726 |
* boolean last) { |
|
727 |
* text.append(message); |
|
728 |
* if (last) { |
|
729 |
* processCompleteTextMessage(text); |
|
730 |
* text = new StringBuilder(); |
|
731 |
* } |
|
732 |
* webSocket.request(1); |
|
733 |
* return null; |
|
734 |
* } |
|
735 |
* ... |
|
736 |
* } } </pre> |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
737 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
738 |
* @param n |
49765 | 739 |
* the number of invocations |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
740 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
741 |
* @throws IllegalArgumentException |
48083 | 742 |
* if {@code n <= 0} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
743 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
744 |
void request(long n); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
745 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
746 |
/** |
49765 | 747 |
* Returns the subprotocol used by this WebSocket. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
748 |
* |
49765 | 749 |
* @return the subprotocol, or an empty 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
|
750 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
751 |
String getSubprotocol(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
752 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
753 |
/** |
49765 | 754 |
* Tells whether this WebSocket's output is closed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
755 |
* |
48083 | 756 |
* <p> If this method returns {@code true}, subsequent invocations will also |
49765 | 757 |
* return {@code true}. |
48083 | 758 |
* |
759 |
* @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
|
760 |
*/ |
48083 | 761 |
boolean isOutputClosed(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
762 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
763 |
/** |
49765 | 764 |
* Tells whether this WebSocket's input is closed. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
765 |
* |
48083 | 766 |
* <p> If this method returns {@code true}, subsequent invocations will also |
49765 | 767 |
* return {@code true}. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
768 |
* |
48083 | 769 |
* @return {@code true} if closed, {@code false} otherwise |
770 |
*/ |
|
771 |
boolean isInputClosed(); |
|
772 |
||
773 |
/** |
|
49765 | 774 |
* Closes this 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
|
775 |
* |
49765 | 776 |
* <p> When this method returns both the input and the output will have been |
777 |
* closed. Any pending send operations will fail with {@code IOException}. |
|
778 |
* 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
|
779 |
*/ |
48083 | 780 |
void abort(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
781 |
} |