Skip to content

Commit 1ef6d82

Browse files
committed
More clean up
1 parent bfb9ed2 commit 1ef6d82

File tree

8 files changed

+25
-32
lines changed

8 files changed

+25
-32
lines changed

client/src/main/java/org/asynchttpclient/request/body/generator/BlockingFeedableBodyGenerator.java renamed to client/src/main/java/org/asynchttpclient/request/body/generator/BlockingQueueFeedableBodyGenerator.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,18 @@
1313
*/
1414
package org.asynchttpclient.request.body.generator;
1515

16-
import java.util.Queue;
1716
import java.util.concurrent.ArrayBlockingQueue;
1817
import java.util.concurrent.BlockingQueue;
1918

20-
public final class BlockingFeedableBodyGenerator extends QueueBasedFeedableBodyGenerator<BlockingQueue<BodyChunk>> {
21-
private final ArrayBlockingQueue<BodyChunk> queue;
19+
public final class BlockingQueueFeedableBodyGenerator extends QueueBasedFeedableBodyGenerator<BlockingQueue<BodyChunk>> {
2220

23-
public BlockingFeedableBodyGenerator(int capacity) {
24-
queue = new ArrayBlockingQueue<>(capacity, true);
21+
public BlockingQueueFeedableBodyGenerator(int capacity) {
22+
super(new ArrayBlockingQueue<>(capacity, true));
2523
}
2624

2725
@Override
2826
protected boolean offer(BodyChunk chunk) throws InterruptedException {
2927
queue.put(chunk);
3028
return true;
3129
}
32-
33-
@Override
34-
protected Queue<org.asynchttpclient.request.body.generator.BodyChunk> queue() {
35-
return queue;
36-
}
3730
}

client/src/main/java/org/asynchttpclient/request/body/generator/BodyChunk.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import java.nio.ByteBuffer;
1717

1818
public final class BodyChunk {
19-
final boolean isLast;
20-
final ByteBuffer buffer;
19+
public final boolean last;
20+
public final ByteBuffer buffer;
2121

22-
public BodyChunk(final ByteBuffer buffer, final boolean isLast) {
22+
public BodyChunk(final ByteBuffer buffer, final boolean last) {
2323
this.buffer = buffer;
24-
this.isLast = isLast;
24+
this.last = last;
2525
}
2626
}

client/src/main/java/org/asynchttpclient/request/body/generator/PushBody.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private BodyState readNextChunk(ByteBuf target) throws IOException {
5454
if (nextChunk == null) {
5555
// Nothing in the queue. suspend stream if nothing was read. (reads == 0)
5656
return res;
57-
} else if (!nextChunk.buffer.hasRemaining() && !nextChunk.isLast) {
57+
} else if (!nextChunk.buffer.hasRemaining() && !nextChunk.last) {
5858
// skip empty buffers
5959
queue.remove();
6060
} else {
@@ -69,7 +69,7 @@ private void readChunk(ByteBuf target, BodyChunk part) {
6969
move(target, part.buffer);
7070

7171
if (!part.buffer.hasRemaining()) {
72-
if (part.isLast) {
72+
if (part.last) {
7373
state = BodyState.STOP;
7474
}
7575
queue.remove();

client/src/main/java/org/asynchttpclient/request/body/generator/QueueBasedFeedableBodyGenerator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020

2121
public abstract class QueueBasedFeedableBodyGenerator<T extends Queue<BodyChunk>> implements FeedableBodyGenerator {
2222

23+
protected final T queue;
2324
private FeedListener listener;
2425

26+
public QueueBasedFeedableBodyGenerator(T queue) {
27+
this.queue = queue;
28+
}
29+
2530
@Override
2631
public Body createBody() {
27-
return new PushBody(queue());
32+
return new PushBody(queue);
2833
}
2934

3035
protected abstract boolean offer(BodyChunk chunk) throws Exception;
3136

32-
protected abstract Queue<BodyChunk> queue();
33-
3437
@Override
3538
public boolean feed(final ByteBuffer buffer, final boolean isLast) throws Exception {
3639
boolean offered = offer(new BodyChunk(buffer, isLast));

client/src/main/java/org/asynchttpclient/request/body/generator/ReactiveStreamsBodyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ReactiveStreamsBodyGenerator implements FeedableBodyGenerator {
3535

3636
public ReactiveStreamsBodyGenerator(Publisher<ByteBuffer> publisher) {
3737
this.publisher = publisher;
38-
this.feedableBodyGenerator = new UnboundedFeedableBodyGenerator();
38+
this.feedableBodyGenerator = new UnboundedQueueFeedableBodyGenerator();
3939
}
4040

4141
public Publisher<ByteBuffer> getPublisher() {

client/src/main/java/org/asynchttpclient/request/body/generator/UnboundedFeedableBodyGenerator.java renamed to client/src/main/java/org/asynchttpclient/request/body/generator/UnboundedQueueFeedableBodyGenerator.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@
1313
*/
1414
package org.asynchttpclient.request.body.generator;
1515

16-
import java.util.Queue;
1716
import java.util.concurrent.ConcurrentLinkedQueue;
1817

19-
public final class UnboundedFeedableBodyGenerator extends QueueBasedFeedableBodyGenerator<ConcurrentLinkedQueue<BodyChunk>> {
20-
private final Queue<BodyChunk> queue = new ConcurrentLinkedQueue<>();
18+
public final class UnboundedQueueFeedableBodyGenerator extends QueueBasedFeedableBodyGenerator<ConcurrentLinkedQueue<BodyChunk>> {
2119

22-
@Override
23-
protected boolean offer(BodyChunk chunk) throws Exception {
24-
return queue.offer(chunk);
20+
public UnboundedQueueFeedableBodyGenerator() {
21+
super(new ConcurrentLinkedQueue<>());
2522
}
2623

2724
@Override
28-
protected Queue<org.asynchttpclient.request.body.generator.BodyChunk> queue() {
29-
return queue;
25+
protected boolean offer(BodyChunk chunk) throws Exception {
26+
return queue.offer(chunk);
3027
}
3128
}

client/src/test/java/org/asynchttpclient/request/body/ChunkingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.asynchttpclient.Response;
3333
import org.asynchttpclient.request.body.generator.FeedableBodyGenerator;
3434
import org.asynchttpclient.request.body.generator.InputStreamBodyGenerator;
35-
import org.asynchttpclient.request.body.generator.UnboundedFeedableBodyGenerator;
35+
import org.asynchttpclient.request.body.generator.UnboundedQueueFeedableBodyGenerator;
3636
import org.testng.annotations.Test;
3737

3838
public class ChunkingTest extends AbstractBasicTest {
@@ -74,7 +74,7 @@ public void doTestWithInputStreamBodyGenerator(InputStream is) throws Throwable
7474
public void doTestWithFeedableBodyGenerator(InputStream is) throws Throwable {
7575
try (AsyncHttpClient c = asyncHttpClient(httpClientBuilder())) {
7676

77-
final FeedableBodyGenerator feedableBodyGenerator = new UnboundedFeedableBodyGenerator();
77+
final FeedableBodyGenerator feedableBodyGenerator = new UnboundedQueueFeedableBodyGenerator();
7878
Request r = post(getTargetUrl()).setBody(feedableBodyGenerator).build();
7979

8080
ListenableFuture<Response> responseFuture = c.executeRequest(r);

client/src/test/java/org/asynchttpclient/request/body/generator/FeedableBodyGeneratorTest.java

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

2929
public class FeedableBodyGeneratorTest {
3030

31-
private UnboundedFeedableBodyGenerator feedableBodyGenerator;
31+
private UnboundedQueueFeedableBodyGenerator feedableBodyGenerator;
3232
private TestFeedListener listener;
3333

3434
@BeforeMethod
3535
public void setUp() throws Exception {
36-
feedableBodyGenerator = new UnboundedFeedableBodyGenerator();
36+
feedableBodyGenerator = new UnboundedQueueFeedableBodyGenerator();
3737
listener = new TestFeedListener();
3838
feedableBodyGenerator.setListener(listener);
3939
}

0 commit comments

Comments
 (0)