Skip to content

Commit 0e4aa68

Browse files
author
Stephane Landelle
committed
Extract Fragment listening concern into dedicated interfaces, close AsyncHttpClient#655
1 parent 2c38d01 commit 0e4aa68

File tree

13 files changed

+217
-235
lines changed

13 files changed

+217
-235
lines changed

api/src/main/java/org/asynchttpclient/websocket/DefaultWebSocketListener.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ public class DefaultWebSocketListener implements WebSocketByteListener, WebSocke
3333
public void onMessage(byte[] message) {
3434
}
3535

36-
/**
37-
* {@inheritDoc}
38-
*/
39-
@Override
40-
public void onFragment(byte[] fragment, boolean last) {
41-
}
42-
4336
// -------------------------------------- Methods from WebSocketPingListener
4437

4538
/**
@@ -67,13 +60,6 @@ public void onPong(byte[] message) {
6760
public void onMessage(String message) {
6861
}
6962

70-
/**
71-
* {@inheritDoc}
72-
*/
73-
@Override
74-
public void onFragment(String fragment, boolean last) {
75-
}
76-
7763
// ------------------------------------------ Methods from WebSocketListener
7864

7965
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2014 AsyncHttpClient Project. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at
7+
* http://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the Apache License Version 2.0 is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
13+
*/
14+
package org.asynchttpclient.websocket;
15+
16+
import org.asynchttpclient.HttpResponseBodyPart;
17+
18+
/**
19+
* Invoked when WebSocket binary fragments are received.
20+
*
21+
* @param fragment text fragment
22+
*/
23+
public interface WebSocketByteFragmentListener extends WebSocketListener {
24+
25+
void onFragment(HttpResponseBodyPart fragment);
26+
}

api/src/main/java/org/asynchttpclient/websocket/WebSocketByteListener.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,8 @@ public interface WebSocketByteListener extends WebSocketListener {
1919

2020
/**
2121
* Invoked when bytes are available.
22+
*
2223
* @param message a byte array.
2324
*/
2425
void onMessage(byte[] message);
25-
26-
/**
27-
* Invoked when bytes of a fragmented message are available.
28-
*
29-
* @param fragment byte[] fragment.
30-
* @param last if this fragment is the last in the series.
31-
*/
32-
void onFragment(byte[] fragment, boolean last);
3326
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2014 AsyncHttpClient Project. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at
7+
* http://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the Apache License Version 2.0 is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
13+
*/
14+
package org.asynchttpclient.websocket;
15+
16+
import org.asynchttpclient.HttpResponseBodyPart;
17+
18+
/**
19+
* Invoked when WebSocket text fragments are received.
20+
*
21+
* @param fragment text fragment
22+
*/
23+
public interface WebSocketTextFragmentListener extends WebSocketListener {
24+
25+
void onFragment(HttpResponseBodyPart fragment);
26+
}

api/src/main/java/org/asynchttpclient/websocket/WebSocketTextListener.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,4 @@ public interface WebSocketTextListener extends WebSocketListener {
2222
* @param message a {@link String} message
2323
*/
2424
void onMessage(String message);
25-
26-
/**
27-
* Invoked when WebSocket text fragments are received.
28-
*
29-
* @param fragment text fragment
30-
* @param last if this fragment is the last of the series.
31-
*/
32-
void onFragment(String fragment, boolean last);
3325
}

api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ public void onMessage(byte[] message) {
6464
latch.countDown();
6565
}
6666

67-
@Override
68-
public void onFragment(byte[] fragment, boolean last) {
69-
}
7067
}).build()).get();
7168

7269
websocket.sendMessage("ECHO".getBytes());
@@ -115,9 +112,6 @@ public void onMessage(byte[] message) {
115112
latch.countDown();
116113
}
117114

118-
@Override
119-
public void onFragment(byte[] fragment, boolean last) {
120-
}
121115
}).build()).get();
122116

123117
websocket.sendMessage("ECHO".getBytes()).sendMessage("ECHO".getBytes());
@@ -167,9 +161,6 @@ public void onMessage(byte[] message) {
167161
latch.countDown();
168162
}
169163

170-
@Override
171-
public void onFragment(byte[] fragment, boolean last) {
172-
}
173164
}).build()).get();
174165

175166
latch.await();
@@ -215,9 +206,6 @@ public void onMessage(byte[] message) {
215206
latch.countDown();
216207
}
217208

218-
@Override
219-
public void onFragment(byte[] fragment, boolean last) {
220-
}
221209
}).build()).get();
222210
websocket.stream("ECHO".getBytes(), false);
223211
websocket.stream("ECHO".getBytes(), true);

api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ public void wrongStatusCode() throws Throwable {
115115
public void onMessage(String message) {
116116
}
117117

118-
@Override
119-
public void onFragment(String fragment, boolean last) {
120-
}
121-
122118
@Override
123119
public void onOpen(WebSocket websocket) {
124120
}
@@ -155,10 +151,6 @@ public void wrongProtocolCode() throws Throwable {
155151
public void onMessage(String message) {
156152
}
157153

158-
@Override
159-
public void onFragment(String fragment, boolean last) {
160-
}
161-
162154
@Override
163155
public void onOpen(WebSocket websocket) {
164156
}

api/src/test/java/org/asynchttpclient/websocket/ProxyTunnellingTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ public void onMessage(String message) {
100100
latch.countDown();
101101
}
102102

103-
@Override
104-
public void onFragment(String fragment, boolean last) {
105-
}
106-
107103
@Override
108104
public void onOpen(WebSocket websocket) {
109105
}

api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ public void onMessage(String message) {
184184
latch.countDown();
185185
}
186186

187-
@Override
188-
public void onFragment(String fragment, boolean last) {
189-
}
190-
191187
@Override
192188
public void onOpen(WebSocket websocket) {
193189
}
@@ -228,10 +224,6 @@ public void onMessage(String message) {
228224
latch.countDown();
229225
}
230226

231-
@Override
232-
public void onFragment(String fragment, boolean last) {
233-
}
234-
235227
@Override
236228
public void onOpen(WebSocket websocket) {
237229
}
@@ -254,10 +246,6 @@ public void onMessage(String message) {
254246
latch.countDown();
255247
}
256248

257-
@Override
258-
public void onFragment(String fragment, boolean last) {
259-
}
260-
261249
@Override
262250
public void onOpen(WebSocket websocket) {
263251
}
@@ -298,10 +286,6 @@ public void onMessage(String message) {
298286
latch.countDown();
299287
}
300288

301-
@Override
302-
public void onFragment(String fragment, boolean last) {
303-
}
304-
305289
@Override
306290
public void onOpen(WebSocket websocket) {
307291
websocket.sendTextMessage("ECHO").sendTextMessage("ECHO");
@@ -340,10 +324,6 @@ public void onMessage(String message) {
340324
latch.countDown();
341325
}
342326

343-
@Override
344-
public void onFragment(String fragment, boolean last) {
345-
}
346-
347327
@Override
348328
public void onOpen(WebSocket websocket) {
349329
}
@@ -386,10 +366,6 @@ public void onMessage(String message) {
386366
textLatch.countDown();
387367
}
388368

389-
@Override
390-
public void onFragment(String fragment, boolean last) {
391-
}
392-
393369
@Override
394370
public void onOpen(WebSocket websocket) {
395371
}

providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ public void onFragment(org.glassfish.grizzly.websockets.WebSocket webSocket, Str
128128
}
129129
}
130130
}
131-
} else {
132-
if (ahcListener instanceof WebSocketTextListener) {
133-
WebSocketTextListener.class.cast(ahcListener).onFragment(s, last);
134-
}
135131
}
136132
} catch (Throwable e) {
137133
ahcListener.onError(e);
@@ -152,10 +148,6 @@ public void onFragment(org.glassfish.grizzly.websockets.WebSocket webSocket, byt
152148
}
153149
}
154150
}
155-
} else {
156-
if (ahcListener instanceof WebSocketByteListener) {
157-
WebSocketByteListener.class.cast(ahcListener).onFragment(bytes, last);
158-
}
159151
}
160152
} catch (Throwable e) {
161153
ahcListener.onError(e);

providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.asynchttpclient.providers.netty.response.EagerNettyResponseBodyPart;
3030
import org.asynchttpclient.providers.netty.response.LazyNettyResponseBodyPart;
3131
import org.asynchttpclient.providers.netty.response.NettyResponseBodyPart;
32-
import org.asynchttpclient.providers.netty.ws.DefaultNettyWebSocket;
3332
import org.asynchttpclient.providers.netty.ws.NettyWebSocket;
3433

3534
/**
@@ -124,7 +123,7 @@ public class DefaultNettyWebSocketFactory implements NettyWebSocketFactory {
124123

125124
@Override
126125
public NettyWebSocket newNettyWebSocket(Channel channel) {
127-
return new DefaultNettyWebSocket(channel);
126+
return new NettyWebSocket(channel);
128127
}
129128
}
130129

0 commit comments

Comments
 (0)