Change ReferenceCounted.retain* to return itself and so allow method chaining
This commit is contained in:
parent
53c27ef5ae
commit
5370573400
@ -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() {
|
||||
|
@ -42,7 +42,7 @@ public abstract class AbstractMessageBuf<T> extends AbstractQueue<T> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void retain() {
|
||||
public final MessageBuf<T> retain() {
|
||||
int refCnt = this.refCnt;
|
||||
if (refCnt <= 0) {
|
||||
throw new IllegalBufferAccessException();
|
||||
@ -53,10 +53,11 @@ public abstract class AbstractMessageBuf<T> extends AbstractQueue<T> implements
|
||||
}
|
||||
|
||||
this.refCnt = refCnt + 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void retain(int increment) {
|
||||
public final MessageBuf<T> retain(int increment) {
|
||||
if (increment <= 0) {
|
||||
throw new IllegalArgumentException("increment: " + increment + " (expected: > 0)");
|
||||
}
|
||||
@ -71,6 +72,7 @@ public abstract class AbstractMessageBuf<T> extends AbstractQueue<T> implements
|
||||
}
|
||||
|
||||
this.refCnt = refCnt + 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -49,4 +49,10 @@ public interface Buf extends ReferenceCounted {
|
||||
* elements.
|
||||
*/
|
||||
boolean isWritable(int size);
|
||||
|
||||
@Override
|
||||
Buf retain();
|
||||
|
||||
@Override
|
||||
Buf retain(int increment);
|
||||
}
|
||||
|
@ -1915,4 +1915,10 @@ public interface ByteBuf extends Buf, Comparable<ByteBuf> {
|
||||
*/
|
||||
@Override
|
||||
String toString();
|
||||
|
||||
@Override
|
||||
ByteBuf retain(int increment);
|
||||
|
||||
@Override
|
||||
ByteBuf retain();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -374,4 +374,10 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
|
||||
|
||||
@Override
|
||||
CompositeByteBuf resumeIntermediaryDeallocations();
|
||||
|
||||
@Override
|
||||
CompositeByteBuf retain(int increment);
|
||||
|
||||
@Override
|
||||
CompositeByteBuf retain();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
|
@ -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() {
|
||||
|
@ -205,13 +205,15 @@ public abstract class FilteredMessageBuf implements MessageBuf<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
public MessageBuf<Object> retain() {
|
||||
buf.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain(int increment) {
|
||||
public MessageBuf<Object> retain(int increment) {
|
||||
buf.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,4 +54,10 @@ public interface MessageBuf<T> extends Buf, Queue<T> {
|
||||
* @return number the number of objects which was transfered
|
||||
*/
|
||||
int drainTo(Collection<? super T> c, int maxElements);
|
||||
|
||||
@Override
|
||||
MessageBuf<T> retain(int increment);
|
||||
|
||||
@Override
|
||||
MessageBuf<T> retain();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -23,4 +23,9 @@ public interface FullHttpMessage extends HttpMessage, LastHttpContent {
|
||||
@Override
|
||||
FullHttpMessage copy();
|
||||
|
||||
@Override
|
||||
FullHttpMessage retain(int increment);
|
||||
|
||||
@Override
|
||||
FullHttpMessage retain();
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -129,12 +129,10 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
||||
Result result = beginEncode(message, c, acceptEncoding);
|
||||
|
||||
if (result == null) {
|
||||
ByteBuf data = c.data();
|
||||
data.retain();
|
||||
if (c instanceof LastHttpContent) {
|
||||
return new Object[] { message, new DefaultLastHttpContent(data) };
|
||||
return new Object[] { message, new DefaultLastHttpContent(c.data().retain()) };
|
||||
} else {
|
||||
return new Object[] { message, new DefaultHttpContent(data) };
|
||||
return new Object[] { message, new DefaultHttpContent(c.data().retain()) };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,10 +60,14 @@ public interface LastHttpContent extends HttpContent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() { }
|
||||
public LastHttpContent retain() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain(int increment) { }
|
||||
public LastHttpContent retain(int increment) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean release() {
|
||||
@ -80,4 +84,10 @@ public interface LastHttpContent extends HttpContent {
|
||||
|
||||
@Override
|
||||
LastHttpContent copy();
|
||||
|
||||
@Override
|
||||
LastHttpContent retain(int increment);
|
||||
|
||||
@Override
|
||||
LastHttpContent retain();
|
||||
}
|
||||
|
@ -114,4 +114,16 @@ public abstract class AbstractHttpData extends AbstractReferenceCounted implemen
|
||||
protected void deallocate() {
|
||||
delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpData retain() {
|
||||
super.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpData retain(int increment) {
|
||||
super.retain(increment);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,10 @@ public interface Attribute extends HttpData {
|
||||
|
||||
@Override
|
||||
Attribute copy();
|
||||
|
||||
@Override
|
||||
Attribute retain();
|
||||
|
||||
@Override
|
||||
Attribute retain(int increment);
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskAttribute copy() {
|
||||
public Attribute copy() {
|
||||
DiskAttribute attr = new DiskAttribute(getName());
|
||||
attr.setCharset(getCharset());
|
||||
ByteBuf content = data();
|
||||
@ -154,4 +154,16 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute retain(int increment) {
|
||||
super.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute retain() {
|
||||
super.retain();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskFileUpload copy() {
|
||||
public FileUpload copy() {
|
||||
DiskFileUpload upload = new DiskFileUpload(getName(),
|
||||
getFilename(), getContentType(), getContentTransferEncoding(), getCharset(), size);
|
||||
ByteBuf buf = data();
|
||||
@ -177,4 +177,16 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
|
||||
}
|
||||
return upload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUpload retain(int increment) {
|
||||
super.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUpload retain() {
|
||||
super.retain();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -58,4 +58,10 @@ public interface FileUpload extends HttpData {
|
||||
|
||||
@Override
|
||||
FileUpload copy();
|
||||
|
||||
@Override
|
||||
FileUpload retain();
|
||||
|
||||
@Override
|
||||
FileUpload retain(int increment);
|
||||
}
|
||||
|
@ -179,4 +179,10 @@ public interface HttpData extends InterfaceHttpData, ByteBufHolder {
|
||||
|
||||
@Override
|
||||
HttpData copy();
|
||||
|
||||
@Override
|
||||
HttpData retain();
|
||||
|
||||
@Override
|
||||
HttpData retain(int increment);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class MemoryAttribute extends AbstractMemoryHttpData implements Attribute
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryAttribute copy() {
|
||||
public Attribute copy() {
|
||||
MemoryAttribute attr = new MemoryAttribute(getName());
|
||||
attr.setCharset(getCharset());
|
||||
ByteBuf content = data();
|
||||
@ -115,4 +115,16 @@ public class MemoryAttribute extends AbstractMemoryHttpData implements Attribute
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute retain() {
|
||||
super.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute retain(int increment) {
|
||||
super.retain(increment);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryFileUpload copy() {
|
||||
public FileUpload copy() {
|
||||
MemoryFileUpload upload = new MemoryFileUpload(getName(), getFilename(), getContentType(),
|
||||
getContentTransferEncoding(), getCharset(), size);
|
||||
ByteBuf buf = data();
|
||||
@ -144,4 +144,16 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
|
||||
}
|
||||
return upload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUpload retain() {
|
||||
super.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileUpload retain(int increment) {
|
||||
super.retain(increment);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -215,13 +215,15 @@ public class MixedAttribute implements Attribute {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
public Attribute retain() {
|
||||
attribute.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain(int increment) {
|
||||
public Attribute retain(int increment) {
|
||||
attribute.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -241,13 +241,15 @@ public class MixedFileUpload implements FileUpload {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
public FileUpload retain() {
|
||||
fileUpload.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain(int increment) {
|
||||
public FileUpload retain(int increment) {
|
||||
fileUpload.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,6 +89,18 @@ public class DefaultSpdyDataFrame extends DefaultByteBufHolder implements SpdyDa
|
||||
return frame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpdyDataFrame retain() {
|
||||
super.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpdyDataFrame retain(int increment) {
|
||||
super.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
@ -41,4 +41,10 @@ public interface SpdyDataFrame extends ByteBufHolder, SpdyStreamFrame, SpdyDataO
|
||||
|
||||
@Override
|
||||
SpdyDataFrame copy();
|
||||
|
||||
@Override
|
||||
SpdyDataFrame retain();
|
||||
|
||||
@Override
|
||||
SpdyDataFrame retain(int increment);
|
||||
}
|
||||
|
@ -884,12 +884,12 @@ final class ReplayingDecoderBuffer implements ByteBuf {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
public ByteBuf retain() {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain(int increment) {
|
||||
public ByteBuf retain(int increment) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
|
@ -128,13 +128,15 @@ public class DefaultChannelPipelineTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
public ReferenceCounted retain() {
|
||||
fail();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain(int increment) {
|
||||
public ReferenceCounted retain(int increment) {
|
||||
fail();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user