Skip to content

Commit cae177a

Browse files
committed
Drop NettyResponseBodyPart, remove one hierarchy level
1 parent 3a91628 commit cae177a

File tree

8 files changed

+34
-60
lines changed

8 files changed

+34
-60
lines changed

client/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
import org.asynchttpclient.filter.IOExceptionFilter;
1616
import org.asynchttpclient.filter.RequestFilter;
1717
import org.asynchttpclient.filter.ResponseFilter;
18-
import org.asynchttpclient.netty.EagerNettyResponseBodyPart;
19-
import org.asynchttpclient.netty.LazyNettyResponseBodyPart;
20-
import org.asynchttpclient.netty.NettyResponseBodyPart;
18+
import org.asynchttpclient.netty.EagerResponseBodyPart;
19+
import org.asynchttpclient.netty.LazyResponseBodyPart;
2120
import org.asynchttpclient.netty.channel.pool.ChannelPool;
2221
import org.asynchttpclient.proxy.ProxyServer;
2322
import org.asynchttpclient.proxy.ProxyServerSelector;
@@ -289,19 +288,19 @@ enum ResponseBodyPartFactory {
289288

290289
EAGER {
291290
@Override
292-
public NettyResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
293-
return new EagerNettyResponseBodyPart(buf, last);
291+
public HttpResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
292+
return new EagerResponseBodyPart(buf, last);
294293
}
295294
},
296295

297296
LAZY {
298297

299298
@Override
300-
public NettyResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
301-
return new LazyNettyResponseBodyPart(buf, last);
299+
public HttpResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
300+
return new LazyResponseBodyPart(buf, last);
302301
}
303302
};
304303

305-
public abstract NettyResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last);
304+
public abstract HttpResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last);
306305
}
307306
}

client/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,34 @@
2020
/**
2121
* A callback class used when an HTTP response body is received.
2222
*/
23-
public interface HttpResponseBodyPart {
23+
public abstract class HttpResponseBodyPart {
24+
25+
private final boolean last;
26+
27+
public HttpResponseBodyPart(boolean last) {
28+
this.last = last;
29+
}
2430

2531
/**
2632
* @return length of this part in bytes
2733
*/
28-
int length();
34+
public abstract int length();
2935

3036
/**
3137
* @return the response body's part bytes received.
3238
*/
33-
byte[] getBodyPartBytes();
39+
public abstract byte[] getBodyPartBytes();
3440

3541
/**
3642
* @return a {@link ByteBuffer} that wraps the actual bytes read from the response's chunk.
3743
* The {@link ByteBuffer}'s capacity is equal to the number of bytes available.
3844
*/
39-
ByteBuffer getBodyByteBuffer();
45+
public abstract ByteBuffer getBodyByteBuffer();
4046

4147
/**
4248
* @return true if this is the last part.
4349
*/
44-
boolean isLast();
50+
public boolean isLast() {
51+
return last;
52+
}
4553
}

client/src/main/java/org/asynchttpclient/netty/EagerNettyResponseBodyPart.java renamed to client/src/main/java/org/asynchttpclient/netty/EagerResponseBodyPart.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717

1818
import java.nio.ByteBuffer;
1919

20+
import org.asynchttpclient.HttpResponseBodyPart;
21+
2022
/**
2123
* A callback class used when an HTTP response body is received.
2224
* Bytes are eagerly fetched from the ByteBuf
2325
*/
24-
public class EagerNettyResponseBodyPart extends NettyResponseBodyPart {
26+
public class EagerResponseBodyPart extends HttpResponseBodyPart {
2527

2628
private final byte[] bytes;
2729

28-
public EagerNettyResponseBodyPart(ByteBuf buf, boolean last) {
30+
public EagerResponseBodyPart(ByteBuf buf, boolean last) {
2931
super(last);
3032
bytes = byteBuf2Bytes(buf);
3133
}

client/src/main/java/org/asynchttpclient/netty/LazyNettyResponseBodyPart.java renamed to client/src/main/java/org/asynchttpclient/netty/LazyResponseBodyPart.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616

1717
import java.nio.ByteBuffer;
1818

19+
import org.asynchttpclient.HttpResponseBodyPart;
1920
import org.asynchttpclient.netty.util.ByteBufUtils;
2021

2122
/**
2223
* A callback class used when an HTTP response body is received.
2324
*/
24-
public class LazyNettyResponseBodyPart extends NettyResponseBodyPart {
25+
public class LazyResponseBodyPart extends HttpResponseBodyPart {
2526

2627
private final ByteBuf buf;
2728

28-
public LazyNettyResponseBodyPart(ByteBuf buf, boolean last) {
29+
public LazyResponseBodyPart(ByteBuf buf, boolean last) {
2930
super(last);
3031
this.buf = buf;
3132
}

client/src/main/java/org/asynchttpclient/netty/NettyResponseBodyPart.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

client/src/main/java/org/asynchttpclient/netty/handler/AsyncHttpClientHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import java.nio.channels.ClosedChannelException;
3030

3131
import org.asynchttpclient.AsyncHttpClientConfig;
32+
import org.asynchttpclient.HttpResponseBodyPart;
3233
import org.asynchttpclient.netty.Callback;
3334
import org.asynchttpclient.netty.DiscardEvent;
34-
import org.asynchttpclient.netty.NettyResponseBodyPart;
3535
import org.asynchttpclient.netty.NettyResponseFuture;
3636
import org.asynchttpclient.netty.channel.ChannelManager;
3737
import org.asynchttpclient.netty.channel.Channels;
@@ -89,7 +89,7 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce
8989
ByteBuf content = ((HttpContent) msg).content();
9090
// Republish as a HttpResponseBodyPart
9191
if (content.readableBytes() > 0) {
92-
NettyResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(content, false);
92+
HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(content, false);
9393
ctx.fireChannelRead(part);
9494
}
9595
if (msg instanceof LastHttpContent) {

client/src/main/java/org/asynchttpclient/netty/handler/HttpProtocol.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
import org.asynchttpclient.AsyncHandler;
3333
import org.asynchttpclient.AsyncHandler.State;
3434
import org.asynchttpclient.AsyncHttpClientConfig;
35+
import org.asynchttpclient.HttpResponseBodyPart;
3536
import org.asynchttpclient.HttpResponseHeaders;
3637
import org.asynchttpclient.Realm;
3738
import org.asynchttpclient.Realm.AuthScheme;
3839
import org.asynchttpclient.Request;
3940
import org.asynchttpclient.RequestBuilder;
4041
import org.asynchttpclient.handler.StreamedAsyncHandler;
4142
import org.asynchttpclient.netty.Callback;
42-
import org.asynchttpclient.netty.NettyResponseBodyPart;
4343
import org.asynchttpclient.netty.NettyResponseFuture;
4444
import org.asynchttpclient.netty.NettyResponseStatus;
4545
import org.asynchttpclient.netty.channel.ChannelManager;
@@ -148,7 +148,7 @@ private void finishUpdate(final NettyResponseFuture<?> future, Channel channel,
148148
}
149149
}
150150

151-
private boolean updateBodyAndInterrupt(NettyResponseFuture<?> future, AsyncHandler<?> handler, NettyResponseBodyPart bodyPart) throws Exception {
151+
private boolean updateBodyAndInterrupt(NettyResponseFuture<?> future, AsyncHandler<?> handler, HttpResponseBodyPart bodyPart) throws Exception {
152152
boolean interrupt = handler.onBodyPartReceived(bodyPart) != State.CONTINUE;
153153
if (interrupt)
154154
future.setKeepAlive(false);
@@ -550,7 +550,7 @@ private void handleChunk(HttpContent chunk,//
550550

551551
ByteBuf buf = chunk.content();
552552
if (!interrupt && !(handler instanceof StreamedAsyncHandler) && (buf.readableBytes() > 0 || last)) {
553-
NettyResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, last);
553+
HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, last);
554554
interrupt = updateBodyAndInterrupt(future, handler, part);
555555
}
556556

client/src/main/java/org/asynchttpclient/netty/handler/WebSocketProtocol.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131

3232
import org.asynchttpclient.AsyncHandler.State;
3333
import org.asynchttpclient.AsyncHttpClientConfig;
34+
import org.asynchttpclient.HttpResponseBodyPart;
3435
import org.asynchttpclient.HttpResponseHeaders;
3536
import org.asynchttpclient.HttpResponseStatus;
3637
import org.asynchttpclient.Realm;
3738
import org.asynchttpclient.Request;
3839
import org.asynchttpclient.netty.Callback;
39-
import org.asynchttpclient.netty.NettyResponseBodyPart;
4040
import org.asynchttpclient.netty.NettyResponseFuture;
4141
import org.asynchttpclient.netty.NettyResponseStatus;
4242
import org.asynchttpclient.netty.channel.ChannelManager;
@@ -154,7 +154,7 @@ public void handle(Channel channel, NettyResponseFuture<?> future, Object e) thr
154154
} else {
155155
ByteBuf buf = frame.content();
156156
if (buf != null && buf.readableBytes() > 0) {
157-
NettyResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, frame.isFinalFragment());
157+
HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, frame.isFinalFragment());
158158
handler.onBodyPartReceived(part);
159159

160160
if (frame instanceof BinaryWebSocketFrame) {

0 commit comments

Comments
 (0)