author | chegar |
Wed, 07 Feb 2018 14:17:24 +0000 | |
branch | http-client-branch |
changeset 56089 | 42208b2f224e |
parent 55988 | test/jdk/java/net/httpclient/websocket/jdk.incubator.httpclient/jdk/incubator/http/internal/websocket/MockListener.java@7f1e0cf933a6 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
48083 | 2 |
* Copyright (c) 2017, 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. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* 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
|
10 |
* 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
|
11 |
* 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
|
12 |
* 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
|
13 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* 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
|
16 |
* 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
|
17 |
* 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
|
18 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* 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
|
20 |
* 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
|
21 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
*/ |
48083 | 23 |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55988
diff
changeset
|
24 |
package java.net.http.internal.websocket; |
42460
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:
55988
diff
changeset
|
26 |
import java.net.http.WebSocket; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55988
diff
changeset
|
27 |
import java.net.http.WebSocket.MessagePart; |
48083 | 28 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
29 |
import java.nio.ByteBuffer; |
48083 | 30 |
import java.util.ArrayList; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
31 |
import java.util.List; |
48083 | 32 |
import java.util.Objects; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
33 |
import java.util.concurrent.CompletableFuture; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
34 |
import java.util.concurrent.CompletionStage; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55988
diff
changeset
|
36 |
import static java.net.http.internal.websocket.TestSupport.fullCopy; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
|
48083 | 38 |
public class MockListener implements WebSocket.Listener { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
39 |
|
48083 | 40 |
private final long bufferSize; |
41 |
private long count; |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
42 |
private final List<Invocation> invocations = new ArrayList<>(); |
48083 | 43 |
private final CompletableFuture<?> lastCall = new CompletableFuture<>(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
44 |
|
48083 | 45 |
/* |
46 |
* Typical buffer sizes: 1, n, Long.MAX_VALUE |
|
47 |
*/ |
|
48 |
public MockListener(long bufferSize) { |
|
49 |
if (bufferSize < 1) { |
|
50 |
throw new IllegalArgumentException(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
51 |
} |
48083 | 52 |
this.bufferSize = bufferSize; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
53 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
54 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
55 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
56 |
public void onOpen(WebSocket webSocket) { |
48083 | 57 |
System.out.printf("onOpen(%s)%n", webSocket); |
58 |
invocations.add(new OnOpen(webSocket)); |
|
59 |
onOpen0(webSocket); |
|
60 |
} |
|
61 |
||
62 |
protected void onOpen0(WebSocket webSocket) { |
|
63 |
replenish(webSocket); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
66 |
@Override |
48083 | 67 |
public CompletionStage<?> onText(WebSocket webSocket, |
68 |
CharSequence message, |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
69 |
MessagePart part) { |
48083 | 70 |
System.out.printf("onText(%s, %s, %s)%n", webSocket, message, part); |
71 |
invocations.add(new OnText(webSocket, message.toString(), part)); |
|
72 |
return onText0(webSocket, message, part); |
|
73 |
} |
|
74 |
||
75 |
protected CompletionStage<?> onText0(WebSocket webSocket, |
|
76 |
CharSequence message, |
|
77 |
MessagePart part) { |
|
78 |
replenish(webSocket); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
79 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
80 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
81 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
82 |
@Override |
48083 | 83 |
public CompletionStage<?> onBinary(WebSocket webSocket, |
84 |
ByteBuffer message, |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
85 |
MessagePart part) { |
48083 | 86 |
System.out.printf("onBinary(%s, %s, %s)%n", webSocket, message, part); |
87 |
invocations.add(new OnBinary(webSocket, fullCopy(message), part)); |
|
88 |
return onBinary0(webSocket, message, part); |
|
89 |
} |
|
90 |
||
91 |
protected CompletionStage<?> onBinary0(WebSocket webSocket, |
|
92 |
ByteBuffer message, |
|
93 |
MessagePart part) { |
|
94 |
replenish(webSocket); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
95 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
96 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
97 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
98 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
99 |
public CompletionStage<?> onPing(WebSocket webSocket, ByteBuffer message) { |
48083 | 100 |
System.out.printf("onPing(%s, %s)%n", webSocket, message); |
101 |
invocations.add(new OnPing(webSocket, fullCopy(message))); |
|
102 |
return onPing0(webSocket, message); |
|
103 |
} |
|
104 |
||
105 |
protected CompletionStage<?> onPing0(WebSocket webSocket, ByteBuffer message) { |
|
106 |
replenish(webSocket); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
107 |
return null; |
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 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
110 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
111 |
public CompletionStage<?> onPong(WebSocket webSocket, ByteBuffer message) { |
48083 | 112 |
System.out.printf("onPong(%s, %s)%n", webSocket, message); |
113 |
invocations.add(new OnPong(webSocket, fullCopy(message))); |
|
114 |
return onPong0(webSocket, message); |
|
115 |
} |
|
116 |
||
117 |
protected CompletionStage<?> onPong0(WebSocket webSocket, ByteBuffer message) { |
|
118 |
replenish(webSocket); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
119 |
return null; |
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 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
122 |
@Override |
48083 | 123 |
public CompletionStage<?> onClose(WebSocket webSocket, |
124 |
int statusCode, |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
125 |
String reason) { |
48083 | 126 |
System.out.printf("onClose(%s, %s, %s)%n", webSocket, statusCode, reason); |
127 |
invocations.add(new OnClose(webSocket, statusCode, reason)); |
|
128 |
lastCall.complete(null); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
129 |
return null; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
130 |
} |
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 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
133 |
public void onError(WebSocket webSocket, Throwable error) { |
48083 | 134 |
System.out.printf("onError(%s, %s)%n", webSocket, error); |
135 |
invocations.add(new OnError(webSocket, error == null ? null : error.getClass())); |
|
136 |
lastCall.complete(null); |
|
137 |
} |
|
138 |
||
139 |
public CompletableFuture<?> onCloseOrOnErrorCalled() { |
|
140 |
return lastCall.copy(); |
|
141 |
} |
|
142 |
||
143 |
protected void replenish(WebSocket webSocket) { |
|
144 |
if (--count <= 0) { |
|
145 |
count = bufferSize - bufferSize / 2; |
|
146 |
} |
|
147 |
webSocket.request(count); |
|
148 |
} |
|
149 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
150 |
public List<Invocation> invocations() { |
48083 | 151 |
return new ArrayList<>(invocations); |
152 |
} |
|
153 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
154 |
public abstract static class Invocation { |
48083 | 155 |
|
156 |
public static OnOpen onOpen(WebSocket webSocket) { |
|
157 |
return new OnOpen(webSocket); |
|
158 |
} |
|
159 |
||
160 |
public static OnText onText(WebSocket webSocket, |
|
161 |
String text, |
|
162 |
MessagePart part) { |
|
163 |
return new OnText(webSocket, text, part); |
|
164 |
} |
|
165 |
||
166 |
public static OnBinary onBinary(WebSocket webSocket, |
|
167 |
ByteBuffer data, |
|
168 |
MessagePart part) { |
|
169 |
return new OnBinary(webSocket, data, part); |
|
170 |
} |
|
171 |
||
172 |
public static OnPing onPing(WebSocket webSocket, |
|
173 |
ByteBuffer data) { |
|
174 |
return new OnPing(webSocket, data); |
|
175 |
} |
|
176 |
||
177 |
public static OnPong onPong(WebSocket webSocket, |
|
178 |
ByteBuffer data) { |
|
179 |
return new OnPong(webSocket, data); |
|
180 |
} |
|
181 |
||
182 |
public static OnClose onClose(WebSocket webSocket, |
|
183 |
int statusCode, |
|
184 |
String reason) { |
|
185 |
return new OnClose(webSocket, statusCode, reason); |
|
186 |
} |
|
187 |
||
188 |
public static OnError onError(WebSocket webSocket, |
|
189 |
Class<? extends Throwable> clazz) { |
|
190 |
return new OnError(webSocket, clazz); |
|
191 |
} |
|
192 |
||
193 |
final WebSocket webSocket; |
|
194 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
195 |
private Invocation(WebSocket webSocket) { |
48083 | 196 |
this.webSocket = webSocket; |
197 |
} |
|
198 |
} |
|
199 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
200 |
public static final class OnOpen extends Invocation { |
48083 | 201 |
|
202 |
public OnOpen(WebSocket webSocket) { |
|
203 |
super(webSocket); |
|
204 |
} |
|
205 |
||
206 |
@Override |
|
207 |
public boolean equals(Object o) { |
|
208 |
if (this == o) return true; |
|
209 |
if (o == null || getClass() != o.getClass()) return false; |
|
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
210 |
Invocation that = (Invocation) o; |
48083 | 211 |
return Objects.equals(webSocket, that.webSocket); |
212 |
} |
|
213 |
||
214 |
@Override |
|
215 |
public int hashCode() { |
|
216 |
return Objects.hashCode(webSocket); |
|
217 |
} |
|
218 |
} |
|
219 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
220 |
public static final class OnText extends Invocation { |
48083 | 221 |
|
222 |
final String text; |
|
223 |
final MessagePart part; |
|
224 |
||
225 |
public OnText(WebSocket webSocket, String text, MessagePart part) { |
|
226 |
super(webSocket); |
|
227 |
this.text = text; |
|
228 |
this.part = part; |
|
229 |
} |
|
230 |
||
231 |
@Override |
|
232 |
public boolean equals(Object o) { |
|
233 |
if (this == o) return true; |
|
234 |
if (o == null || getClass() != o.getClass()) return false; |
|
235 |
OnText onText = (OnText) o; |
|
236 |
return Objects.equals(text, onText.text) && |
|
237 |
part == onText.part && |
|
238 |
Objects.equals(webSocket, onText.webSocket); |
|
239 |
} |
|
240 |
||
241 |
@Override |
|
242 |
public int hashCode() { |
|
243 |
return Objects.hash(text, part, webSocket); |
|
244 |
} |
|
245 |
||
246 |
@Override |
|
247 |
public String toString() { |
|
248 |
return String.format("onText(%s, %s, %s)", webSocket, text, part); |
|
249 |
} |
|
250 |
} |
|
251 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
252 |
public static final class OnBinary extends Invocation { |
48083 | 253 |
|
254 |
final ByteBuffer data; |
|
255 |
final MessagePart part; |
|
256 |
||
257 |
public OnBinary(WebSocket webSocket, ByteBuffer data, MessagePart part) { |
|
258 |
super(webSocket); |
|
259 |
this.data = data; |
|
260 |
this.part = part; |
|
261 |
} |
|
262 |
||
263 |
@Override |
|
264 |
public boolean equals(Object o) { |
|
265 |
if (this == o) return true; |
|
266 |
if (o == null || getClass() != o.getClass()) return false; |
|
267 |
OnBinary onBinary = (OnBinary) o; |
|
268 |
return Objects.equals(data, onBinary.data) && |
|
269 |
part == onBinary.part && |
|
270 |
Objects.equals(webSocket, onBinary.webSocket); |
|
271 |
} |
|
272 |
||
273 |
@Override |
|
274 |
public int hashCode() { |
|
275 |
return Objects.hash(data, part, webSocket); |
|
276 |
} |
|
277 |
||
278 |
@Override |
|
279 |
public String toString() { |
|
280 |
return String.format("onBinary(%s, %s, %s)", webSocket, data, part); |
|
281 |
} |
|
282 |
} |
|
283 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
284 |
public static final class OnPing extends Invocation { |
48083 | 285 |
|
286 |
final ByteBuffer data; |
|
287 |
||
288 |
public OnPing(WebSocket webSocket, ByteBuffer data) { |
|
289 |
super(webSocket); |
|
290 |
this.data = data; |
|
291 |
} |
|
292 |
||
293 |
@Override |
|
294 |
public boolean equals(Object o) { |
|
295 |
if (this == o) return true; |
|
296 |
if (o == null || getClass() != o.getClass()) return false; |
|
297 |
OnPing onPing = (OnPing) o; |
|
298 |
return Objects.equals(data, onPing.data) && |
|
299 |
Objects.equals(webSocket, onPing.webSocket); |
|
300 |
} |
|
301 |
||
302 |
@Override |
|
303 |
public int hashCode() { |
|
304 |
return Objects.hash(data, webSocket); |
|
305 |
} |
|
306 |
||
307 |
@Override |
|
308 |
public String toString() { |
|
309 |
return String.format("onPing(%s, %s)", webSocket, data); |
|
310 |
} |
|
311 |
} |
|
312 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
313 |
public static final class OnPong extends Invocation { |
48083 | 314 |
|
315 |
final ByteBuffer data; |
|
316 |
||
317 |
public OnPong(WebSocket webSocket, ByteBuffer data) { |
|
318 |
super(webSocket); |
|
319 |
this.data = data; |
|
320 |
} |
|
321 |
||
322 |
@Override |
|
323 |
public boolean equals(Object o) { |
|
324 |
if (this == o) return true; |
|
325 |
if (o == null || getClass() != o.getClass()) return false; |
|
326 |
OnPong onPong = (OnPong) o; |
|
327 |
return Objects.equals(data, onPong.data) && |
|
328 |
Objects.equals(webSocket, onPong.webSocket); |
|
329 |
} |
|
330 |
||
331 |
@Override |
|
332 |
public int hashCode() { |
|
333 |
return Objects.hash(data, webSocket); |
|
334 |
} |
|
335 |
||
336 |
@Override |
|
337 |
public String toString() { |
|
338 |
return String.format("onPong(%s, %s)", webSocket, data); |
|
339 |
} |
|
340 |
} |
|
341 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
342 |
public static final class OnClose extends Invocation { |
48083 | 343 |
|
344 |
final int statusCode; |
|
345 |
final String reason; |
|
346 |
||
347 |
public OnClose(WebSocket webSocket, int statusCode, String reason) { |
|
348 |
super(webSocket); |
|
349 |
this.statusCode = statusCode; |
|
350 |
this.reason = reason; |
|
351 |
} |
|
352 |
||
353 |
@Override |
|
354 |
public boolean equals(Object o) { |
|
355 |
if (this == o) return true; |
|
356 |
if (o == null || getClass() != o.getClass()) return false; |
|
357 |
OnClose onClose = (OnClose) o; |
|
358 |
return statusCode == onClose.statusCode && |
|
359 |
Objects.equals(reason, onClose.reason) && |
|
360 |
Objects.equals(webSocket, onClose.webSocket); |
|
361 |
} |
|
362 |
||
363 |
@Override |
|
364 |
public int hashCode() { |
|
365 |
return Objects.hash(statusCode, reason, webSocket); |
|
366 |
} |
|
367 |
||
368 |
@Override |
|
369 |
public String toString() { |
|
370 |
return String.format("onClose(%s, %s, %s)", webSocket, statusCode, reason); |
|
371 |
} |
|
372 |
} |
|
373 |
||
55988
7f1e0cf933a6
http-client-branch: (WebSocket) refactoring for the sake of extra test coverage
prappo
parents:
55973
diff
changeset
|
374 |
public static final class OnError extends Invocation { |
48083 | 375 |
|
376 |
final Class<? extends Throwable> clazz; |
|
377 |
||
378 |
public OnError(WebSocket webSocket, Class<? extends Throwable> clazz) { |
|
379 |
super(webSocket); |
|
380 |
this.clazz = clazz; |
|
381 |
} |
|
382 |
||
383 |
@Override |
|
384 |
public boolean equals(Object o) { |
|
385 |
if (this == o) return true; |
|
386 |
if (o == null || getClass() != o.getClass()) return false; |
|
387 |
OnError onError = (OnError) o; |
|
388 |
return Objects.equals(clazz, onError.clazz) && |
|
389 |
Objects.equals(webSocket, onError.webSocket); |
|
390 |
} |
|
391 |
||
392 |
@Override |
|
393 |
public int hashCode() { |
|
394 |
return Objects.hash(clazz, webSocket); |
|
395 |
} |
|
396 |
||
397 |
@Override |
|
398 |
public String toString() { |
|
399 |
return String.format("onError(%s, %s)", webSocket, clazz); |
|
400 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
401 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
402 |
} |