Skip to content

Commit c83340c

Browse files
committed
Work on porting to netty 4
1 parent f9086ab commit c83340c

16 files changed

+374
-358
lines changed

providers/netty-4/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
<version>1.8.0-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
10-
<artifactId>async-http-client-netty-provider</artifactId>
11-
<name>Asynchronous Http Client Netty Provider</name>
10+
<artifactId>async-http-client-netty-4-provider</artifactId>
11+
<name>Asynchronous Http Client Netty 4 Provider</name>
1212
<description>
13-
The Async Http Client Netty Provider.
13+
The Async Http Client Netty 4 Provider.
1414
</description>
1515

1616
<dependencies>
1717
<dependency>
1818
<groupId>io.netty</groupId>
19-
<artifactId>netty</artifactId>
20-
<version>3.6.3.Final</version>
19+
<artifactId>netty-all</artifactId>
20+
<version>4.0.0.Beta3</version>
2121
</dependency>
2222
</dependencies>
2323

providers/netty-4/src/main/java/com/ning/http/client/providers/netty_4/BodyChunkedInput.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
package com.ning.http.client.providers.netty_4;
1414

1515
import com.ning.http.client.Body;
16-
import org.jboss.netty.buffer.ChannelBuffers;
17-
import org.jboss.netty.handler.stream.ChunkedInput;
16+
import io.netty.buffer.ByteBuf;
17+
import io.netty.buffer.Unpooled;
18+
import io.netty.handler.stream.ChunkedInput;
1819

1920
import java.io.IOException;
2021
import java.nio.ByteBuffer;
@@ -23,7 +24,7 @@
2324
* Adapts a {@link Body} to Netty's {@link ChunkedInput}.
2425
*/
2526
class BodyChunkedInput
26-
implements ChunkedInput {
27+
implements ChunkedInput<ByteBuf> {
2728

2829
private final Body body;
2930

@@ -72,14 +73,16 @@ public boolean hasNextChunk() throws Exception {
7273
return peekNextChunk() != null;
7374
}
7475

75-
public Object nextChunk() throws Exception {
76+
@Override
77+
public boolean readChunk(ByteBuf b) throws Exception {
7678
ByteBuffer buffer = peekNextChunk();
7779
if (buffer == null || buffer == EOF) {
78-
return null;
80+
return false;
7981
}
8082
nextChunk = null;
8183

82-
return ChannelBuffers.wrappedBuffer(buffer);
84+
b.writeBytes(buffer);
85+
return true;
8386
}
8487

8588
public boolean isEndOfInput() throws Exception {

providers/netty-4/src/main/java/com/ning/http/client/providers/netty_4/BodyFileRegion.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
package com.ning.http.client.providers.netty_4;
1414

1515
import com.ning.http.client.RandomAccessBody;
16-
import org.jboss.netty.channel.FileRegion;
16+
import io.netty.buffer.AbstractReferenceCounted;
17+
import io.netty.buffer.ReferenceCounted;
18+
import io.netty.channel.FileRegion;
1719

1820
import java.io.IOException;
1921
import java.nio.channels.WritableByteChannel;
@@ -22,6 +24,7 @@
2224
* Adapts a {@link RandomAccessBody} to Netty's {@link FileRegion}.
2325
*/
2426
class BodyFileRegion
27+
extends AbstractReferenceCounted
2528
implements FileRegion {
2629

2730
private final RandomAccessBody body;
@@ -33,11 +36,11 @@ public BodyFileRegion(RandomAccessBody body) {
3336
this.body = body;
3437
}
3538

36-
public long getPosition() {
39+
public long position() {
3740
return 0;
3841
}
3942

40-
public long getCount() {
43+
public long count() {
4144
return body.getContentLength();
4245
}
4346

@@ -46,12 +49,11 @@ public long transferTo(WritableByteChannel target, long position)
4649
return body.transferTo(position, Long.MAX_VALUE, target);
4750
}
4851

49-
public void releaseExternalResources() {
52+
public void deallocate() {
5053
try {
5154
body.close();
5255
} catch (IOException e) {
5356
// we tried
5457
}
5558
}
56-
5759
}

0 commit comments

Comments
 (0)