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