diff --git a/buffer/src/main/java/io/netty/buffer/AbstractDerivedByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractDerivedByteBuf.java index 6160e67adc..378e7b1f6b 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractDerivedByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractDerivedByteBuf.java @@ -28,10 +28,14 @@ public abstract class AbstractDerivedByteBuf extends AbstractByteBuf { } @Override - public final void retain() { } + public final ByteBuf retain() { + return this; + } @Override - public final void retain(int increment) { } + public final ByteBuf retain(int increment) { + return this; + } @Override public final boolean release() { diff --git a/buffer/src/main/java/io/netty/buffer/AbstractMessageBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractMessageBuf.java index 04322a5bca..766f8cab7a 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractMessageBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractMessageBuf.java @@ -42,7 +42,7 @@ public abstract class AbstractMessageBuf extends AbstractQueue implements } @Override - public final void retain() { + public final MessageBuf retain() { int refCnt = this.refCnt; if (refCnt <= 0) { throw new IllegalBufferAccessException(); @@ -53,10 +53,11 @@ public abstract class AbstractMessageBuf extends AbstractQueue implements } this.refCnt = refCnt + 1; + return this; } @Override - public final void retain(int increment) { + public final MessageBuf retain(int increment) { if (increment <= 0) { throw new IllegalArgumentException("increment: " + increment + " (expected: > 0)"); } @@ -71,6 +72,7 @@ public abstract class AbstractMessageBuf extends AbstractQueue implements } this.refCnt = refCnt + 1; + return this; } @Override diff --git a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCounted.java b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCounted.java index 411802fe77..81b108c50b 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCounted.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCounted.java @@ -31,7 +31,7 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted { } @Override - public final void retain() { + public ReferenceCounted retain() { for (;;) { int refCnt = this.refCnt; if (refCnt == 0) { @@ -44,10 +44,11 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted { break; } } + return this; } @Override - public final void retain(int increment) { + public ReferenceCounted retain(int increment) { if (increment <= 0) { throw new IllegalArgumentException("increment: " + increment + " (expected: > 0)"); } @@ -64,6 +65,7 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted { break; } } + return this; } @Override diff --git a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java index 8321795e56..1cd86ddaeb 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java @@ -36,7 +36,7 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf { } @Override - public final void retain() { + public ByteBuf retain() { for (;;) { int refCnt = this.refCnt; if (refCnt == 0) { @@ -49,10 +49,11 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf { break; } } + return this; } @Override - public final void retain(int increment) { + public ByteBuf retain(int increment) { if (increment <= 0) { throw new IllegalArgumentException("increment: " + increment + " (expected: > 0)"); } @@ -69,6 +70,7 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf { break; } } + return this; } @Override diff --git a/buffer/src/main/java/io/netty/buffer/Buf.java b/buffer/src/main/java/io/netty/buffer/Buf.java index b57e2e5e35..5cf36606e7 100644 --- a/buffer/src/main/java/io/netty/buffer/Buf.java +++ b/buffer/src/main/java/io/netty/buffer/Buf.java @@ -49,4 +49,10 @@ public interface Buf extends ReferenceCounted { * elements. */ boolean isWritable(int size); + + @Override + Buf retain(); + + @Override + Buf retain(int increment); } diff --git a/buffer/src/main/java/io/netty/buffer/ByteBuf.java b/buffer/src/main/java/io/netty/buffer/ByteBuf.java index 2ac22297cf..5e7636ce14 100644 --- a/buffer/src/main/java/io/netty/buffer/ByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/ByteBuf.java @@ -1915,4 +1915,10 @@ public interface ByteBuf extends Buf, Comparable { */ @Override String toString(); + + @Override + ByteBuf retain(int increment); + + @Override + ByteBuf retain(); } diff --git a/buffer/src/main/java/io/netty/buffer/ByteBufHolder.java b/buffer/src/main/java/io/netty/buffer/ByteBufHolder.java index 3e2820f8c2..040a84b152 100644 --- a/buffer/src/main/java/io/netty/buffer/ByteBufHolder.java +++ b/buffer/src/main/java/io/netty/buffer/ByteBufHolder.java @@ -30,4 +30,10 @@ public interface ByteBufHolder extends ReferenceCounted { * Create a deep copy of this {@link ByteBufHolder}. */ ByteBufHolder copy(); + + @Override + ByteBufHolder retain(); + + @Override + ByteBufHolder retain(int increment); } diff --git a/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java index 86a04df097..00fa387ead 100644 --- a/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java @@ -374,4 +374,10 @@ public interface CompositeByteBuf extends ByteBuf, Iterable { @Override CompositeByteBuf resumeIntermediaryDeallocations(); + + @Override + CompositeByteBuf retain(int increment); + + @Override + CompositeByteBuf retain(); } diff --git a/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java b/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java index 658e817879..81acbee1f7 100644 --- a/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java +++ b/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java @@ -53,13 +53,15 @@ public class DefaultByteBufHolder implements ByteBufHolder { } @Override - public void retain() { + public ByteBufHolder retain() { data.retain(); + return this; } @Override - public void retain(int increment) { + public ByteBufHolder retain(int increment) { data.retain(increment); + return this; } @Override diff --git a/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java index 29265ea0ae..631d01dc8a 100644 --- a/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java @@ -40,7 +40,8 @@ import java.util.Queue; * is recommended to use {@link Unpooled#wrappedBuffer(ByteBuf...)} * instead of calling the constructor explicitly. */ -public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf implements CompositeByteBuf { +public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf + implements CompositeByteBuf { private static final ByteBuffer[] EMPTY_NIOBUFFERS = new ByteBuffer[0]; @@ -1514,6 +1515,16 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf imp return (CompositeByteBuf) super.writeZero(length); } + @Override + public CompositeByteBuf retain(int increment) { + return (CompositeByteBuf) super.retain(increment); + } + + @Override + public CompositeByteBuf retain() { + return (CompositeByteBuf) super.retain(); + } + @Override public ByteBuffer[] nioBuffers() { return nioBuffers(readerIndex(), readableBytes()); diff --git a/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java b/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java index ef1f45123f..3d0190ee6c 100644 --- a/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java @@ -809,10 +809,14 @@ public final class EmptyByteBuf implements ByteBuf { } @Override - public void retain() { } + public ByteBuf retain() { + return this; + } @Override - public void retain(int increment) { } + public ByteBuf retain(int increment) { + return this; + } @Override public boolean release() { diff --git a/buffer/src/main/java/io/netty/buffer/FilteredMessageBuf.java b/buffer/src/main/java/io/netty/buffer/FilteredMessageBuf.java index 6284ff9931..cef27554bf 100644 --- a/buffer/src/main/java/io/netty/buffer/FilteredMessageBuf.java +++ b/buffer/src/main/java/io/netty/buffer/FilteredMessageBuf.java @@ -205,13 +205,15 @@ public abstract class FilteredMessageBuf implements MessageBuf { } @Override - public void retain() { + public MessageBuf retain() { buf.retain(); + return this; } @Override - public void retain(int increment) { + public MessageBuf retain(int increment) { buf.retain(increment); + return this; } @Override diff --git a/buffer/src/main/java/io/netty/buffer/MessageBuf.java b/buffer/src/main/java/io/netty/buffer/MessageBuf.java index 4fa89c1dbf..e571d7befb 100644 --- a/buffer/src/main/java/io/netty/buffer/MessageBuf.java +++ b/buffer/src/main/java/io/netty/buffer/MessageBuf.java @@ -54,4 +54,10 @@ public interface MessageBuf extends Buf, Queue { * @return number the number of objects which was transfered */ int drainTo(Collection c, int maxElements); + + @Override + MessageBuf retain(int increment); + + @Override + MessageBuf retain(); } diff --git a/buffer/src/main/java/io/netty/buffer/ReferenceCounted.java b/buffer/src/main/java/io/netty/buffer/ReferenceCounted.java index 7e58700568..d04b155111 100644 --- a/buffer/src/main/java/io/netty/buffer/ReferenceCounted.java +++ b/buffer/src/main/java/io/netty/buffer/ReferenceCounted.java @@ -37,12 +37,12 @@ public interface ReferenceCounted { /** * Increases the reference count by {@code 1}. */ - void retain(); + ReferenceCounted retain(); /** * Increases the reference count by the specified {@code increment}. */ - void retain(int increment); + ReferenceCounted retain(int increment); /** * Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at diff --git a/buffer/src/main/java/io/netty/buffer/SwappedByteBuf.java b/buffer/src/main/java/io/netty/buffer/SwappedByteBuf.java index 601a748a2a..220f8130dc 100644 --- a/buffer/src/main/java/io/netty/buffer/SwappedByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/SwappedByteBuf.java @@ -821,13 +821,15 @@ public final class SwappedByteBuf implements ByteBuf { } @Override - public void retain() { + public ByteBuf retain() { buf.retain(); + return this; } @Override - public void retain(int increment) { + public ByteBuf retain(int increment) { buf.retain(increment); + return this; } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpRequest.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpRequest.java index 6d1904d7d9..3745e03598 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpRequest.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpRequest.java @@ -53,13 +53,15 @@ public class DefaultFullHttpRequest extends DefaultHttpRequest implements FullHt } @Override - public void retain() { + public FullHttpRequest retain() { content.retain(); + return this; } @Override - public void retain(int increment) { + public FullHttpRequest retain(int increment) { content.retain(increment); + return this; } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpResponse.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpResponse.java index 42565acb19..bf9baddc10 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpResponse.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpResponse.java @@ -55,13 +55,15 @@ public class DefaultFullHttpResponse extends DefaultHttpResponse implements Full } @Override - public void retain() { + public FullHttpResponse retain() { content.retain(); + return this; } @Override - public void retain(int increment) { + public FullHttpResponse retain(int increment) { content.retain(increment); + return this; } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java index ba1bf77172..2fd248a8da 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java @@ -50,13 +50,15 @@ public class DefaultHttpContent extends DefaultHttpObject implements HttpContent } @Override - public void retain() { + public HttpContent retain() { content.retain(); + return this; } @Override - public void retain(int increment) { + public HttpContent retain(int increment) { content.retain(increment); + return this; } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultLastHttpContent.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultLastHttpContent.java index 260512b2ac..1ce8999779 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultLastHttpContent.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultLastHttpContent.java @@ -54,6 +54,18 @@ public class DefaultLastHttpContent extends DefaultHttpContent implements LastHt return copy; } + @Override + public LastHttpContent retain(int increment) { + super.retain(increment); + return this; + } + + @Override + public LastHttpContent retain() { + super.retain(); + return this; + } + @Override public HttpHeaders trailingHeaders() { return trailingHeaders; diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java b/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java index 7872c8db2f..1280df3336 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java @@ -23,4 +23,9 @@ public interface FullHttpMessage extends HttpMessage, LastHttpContent { @Override FullHttpMessage copy(); + @Override + FullHttpMessage retain(int increment); + + @Override + FullHttpMessage retain(); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpRequest.java b/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpRequest.java index 3b0ab23ee2..615bdc88ea 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpRequest.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpRequest.java @@ -23,6 +23,12 @@ public interface FullHttpRequest extends HttpRequest, FullHttpMessage { @Override FullHttpRequest copy(); + @Override + FullHttpRequest retain(int increment); + + @Override + FullHttpRequest retain(); + @Override FullHttpRequest setProtocolVersion(HttpVersion version); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpResponse.java b/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpResponse.java index 51b4b03516..756916c454 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpResponse.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpResponse.java @@ -23,6 +23,12 @@ public interface FullHttpResponse extends HttpResponse, FullHttpMessage { @Override FullHttpResponse copy(); + @Override + FullHttpResponse retain(int increment); + + @Override + FullHttpResponse retain(); + @Override FullHttpResponse setProtocolVersion(HttpVersion version); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContent.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContent.java index 7f43752c17..c7c868cba3 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContent.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContent.java @@ -30,4 +30,10 @@ import io.netty.channel.ChannelPipeline; public interface HttpContent extends HttpObject, ByteBufHolder { @Override HttpContent copy(); + + @Override + HttpContent retain(); + + @Override + HttpContent retain(int increment); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentEncoder.java index f52f6ca7e7..c1f6ac1061 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentEncoder.java @@ -129,12 +129,10 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec