Revert "[#1812] Rework ByteToMessageDecoder.channelRead(..) method to allow for inlining"

This reverts commit b7262ab3da.
This commit is contained in:
Norman Maurer 2013-10-23 21:13:03 +02:00
parent b7262ab3da
commit 3de7a0bf76

View File

@ -121,24 +121,30 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof ByteBuf) {
RecyclableArrayList out = RecyclableArrayList.newInstance();
try {
if (msg instanceof ByteBuf) {
ByteBuf data = (ByteBuf) msg;
if (cumulation == null) {
cumulation = data;
try {
callDecode(ctx, cumulation, out);
} finally {
if (cumulation != null && !cumulation.isReadable()) {
cumulation.release();
cumulation = null;
}
}
} else {
try {
if (cumulation.writerIndex() > cumulation.maxCapacity() - data.readableBytes()) {
expandCumulation(ctx, data.readableBytes());
ByteBuf oldCumulation = cumulation;
cumulation = ctx.alloc().buffer(oldCumulation.readableBytes() + data.readableBytes());
cumulation.writeBytes(oldCumulation);
oldCumulation.release();
}
cumulation.writeBytes(data);
data.release();
}
callDecode(ctx, cumulation, out);
} catch (DecoderException e) {
throw e;
} catch (Throwable t) {
throw new DecoderException(t);
} finally {
if (cumulation != null) {
if (!cumulation.isReadable()) {
@ -148,6 +154,17 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
cumulation.discardSomeReadBytes();
}
}
data.release();
}
}
} else {
out.add(msg);
}
} catch (DecoderException e) {
throw e;
} catch (Throwable t) {
throw new DecoderException(t);
} finally {
int size = out.size();
if (size == 0) {
decodeWasNull = true;
@ -158,16 +175,6 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
}
out.recycle();
}
} else {
ctx.fireChannelRead(msg);
}
}
private void expandCumulation(ChannelHandlerContext ctx, int readable) {
ByteBuf oldCumulation = cumulation;
cumulation = ctx.alloc().buffer(oldCumulation.readableBytes() + readable);
cumulation.writeBytes(oldCumulation);
oldCumulation.release();
}
@Override