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