Change AggregatedFullHttpMessage to contain a content ByteBuf

Motivation:

Other implementations of FullHttpMessage allow .toString to be called after the Message has been released
This brings AggregatedFullHttpMessage into line with those impls.

Modifications:

- Changed AggregatedFullHttpMessage to no longer be a sub-class of DefaultByteBufHolder
- Changes AggregatedFullHttpMessage to implement ByteBufHolder
- Hold the content buffer internally to AggregatedFullHttpMessage
- Implement the required content() and release() methods that were missing
- Do not check refcnt when accessing content() (similar to DefaultFullHttpMessage)

Result:

A released AggregatedFullHttpMessage can have .toString called without throwing an exception
This commit is contained in:
Derek Troy-West 2015-04-16 21:45:32 +10:00 committed by Norman Maurer
parent 970529e1a8
commit 854859ba69

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
@ -188,13 +188,14 @@ public class HttpObjectAggregator
} }
} }
private abstract static class AggregatedFullHttpMessage extends DefaultByteBufHolder implements FullHttpMessage { private abstract static class AggregatedFullHttpMessage implements ByteBufHolder, FullHttpMessage {
protected final HttpMessage message; protected final HttpMessage message;
private final ByteBuf content;
private HttpHeaders trailingHeaders; private HttpHeaders trailingHeaders;
AggregatedFullHttpMessage(HttpMessage message, ByteBuf content, HttpHeaders trailingHeaders) { AggregatedFullHttpMessage(HttpMessage message, ByteBuf content, HttpHeaders trailingHeaders) {
super(content);
this.message = message; this.message = message;
this.content = content;
this.trailingHeaders = trailingHeaders; this.trailingHeaders = trailingHeaders;
} }
@ -249,29 +250,49 @@ public class HttpObjectAggregator
} }
@Override @Override
public FullHttpMessage retain(int increment) { public ByteBuf content() {
super.retain(increment); return content;
return this; }
@Override
public int refCnt() {
return content.refCnt();
} }
@Override @Override
public FullHttpMessage retain() { public FullHttpMessage retain() {
super.retain(); content.retain();
return this;
}
@Override
public FullHttpMessage retain(int increment) {
content.retain(increment);
return this; return this;
} }
@Override @Override
public FullHttpMessage touch(Object hint) { public FullHttpMessage touch(Object hint) {
super.touch(hint); content.touch(hint);
return this; return this;
} }
@Override @Override
public FullHttpMessage touch() { public FullHttpMessage touch() {
super.touch(); content.touch();
return this; return this;
} }
@Override
public boolean release() {
return content.release();
}
@Override
public boolean release(int decrement) {
return content.release(decrement);
}
@Override @Override
public abstract FullHttpMessage copy(); public abstract FullHttpMessage copy();