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

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

View File

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