diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java index 8f1c817939..fdc036ce7e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java @@ -20,7 +20,7 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundByteHandler; -import io.netty.channel.ChannelInboundHandler; +import io.netty.channel.ChannelInboundMessageHandler; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpRequestDecoder; @@ -143,21 +143,21 @@ public abstract class SpdyOrHttpChooser extends ChannelHandlerAdapter implements } /** - * Create the {@link ChannelInboundHandler} that is responsible for handling the http requests + * Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http requests * when the {@link SelectedProtocol} was {@link SelectedProtocol#HttpVersion1_0} or * {@link SelectedProtocol#HttpVersion1_1} */ - protected abstract ChannelInboundHandler createHttpRequestHandlerForHttp(); + protected abstract ChannelInboundMessageHandler createHttpRequestHandlerForHttp(); /** - * Create the {@link ChannelInboundHandler} that is responsible for handling the http responses + * Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http responses * when the {@link SelectedProtocol} was {@link SelectedProtocol#SpdyVersion2} or * {@link SelectedProtocol#SpdyVersion3}. * * Bye default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but * sub-classes may override this to change the behaviour. */ - protected ChannelInboundHandler createHttpRequestHandlerForSpdy() { + protected ChannelInboundMessageHandler createHttpRequestHandlerForSpdy() { return createHttpRequestHandlerForHttp(); } } diff --git a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java index eb2cb42965..322ad22743 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java @@ -16,11 +16,10 @@ package io.netty.handler.codec; import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerUtil; import io.netty.channel.ChannelInboundByteHandler; -import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.ChannelInboundByteHandlerAdapter; /** * {@link ChannelInboundByteHandler} which decodes bytes in a stream-like fashion from one {@link ByteBuf} to an other @@ -40,7 +39,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter; * */ public abstract class ByteToMessageDecoder - extends ChannelInboundHandlerAdapter implements ChannelInboundByteHandler { + extends ChannelInboundByteHandlerAdapter { private volatile boolean singleDecode; private boolean decodeWasNull; @@ -64,19 +63,10 @@ public abstract class ByteToMessageDecoder public boolean isSingleDecode() { return singleDecode; } - @Override - public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { - return ctx.alloc().buffer(); - } @Override - public void discardInboundReadBytes(ChannelHandlerContext ctx) throws Exception { - ctx.inboundByteBuffer().discardSomeReadBytes(); - } - - @Override - public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception { - callDecode(ctx); + public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + callDecode(ctx, in); } @Override @@ -94,7 +84,7 @@ public abstract class ByteToMessageDecoder public void channelInactive(ChannelHandlerContext ctx) throws Exception { ByteBuf in = ctx.inboundByteBuffer(); if (in.readable()) { - callDecode(ctx); + callDecode(ctx, in); } try { @@ -112,11 +102,9 @@ public abstract class ByteToMessageDecoder ctx.fireChannelInactive(); } - protected void callDecode(ChannelHandlerContext ctx) { + protected void callDecode(ChannelHandlerContext ctx, ByteBuf in) { boolean wasNull = false; - ByteBuf in = ctx.inboundByteBuffer(); - boolean decoded = false; while (in.readable()) { try { diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java index c70eb8c167..30cb8269d5 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java @@ -19,9 +19,9 @@ import io.netty.buffer.MessageBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerUtil; -import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.ChannelStateHandlerAdapter; /** * {@link ChannelInboundMessageHandler} which decodes from one message to an other message @@ -46,7 +46,7 @@ import io.netty.channel.ChannelPipeline; * */ public abstract class MessageToMessageDecoder - extends ChannelInboundHandlerAdapter implements ChannelInboundMessageHandler { + extends ChannelStateHandlerAdapter implements ChannelInboundMessageHandler { private final Class[] acceptedMsgTypes; @@ -141,4 +141,9 @@ public abstract class MessageToMessageDecoder protected void freeInboundMessage(I msg) throws Exception { ChannelHandlerUtil.freeMessage(msg); } + + @Override + public void freeInboundBuffer(ChannelHandlerContext ctx) throws Exception { + ctx.inboundMessageBuffer().free(); + } } diff --git a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java index 7e7c8d37d7..1f0f2d09f3 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java @@ -363,7 +363,7 @@ public abstract class ReplayingDecoder extends ByteToMessageDecoder { replayable.terminate(); ByteBuf in = cumulation; if (in.readable()) { - callDecode(ctx); + callDecode(ctx, in); } try { @@ -385,7 +385,7 @@ public abstract class ReplayingDecoder extends ByteToMessageDecoder { } @Override - protected void callDecode(ChannelHandlerContext ctx) { + protected void callDecode(ChannelHandlerContext ctx, ByteBuf buf) { boolean wasNull = false; ByteBuf in = cumulation; diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java index 035b0695b2..68e8838ba2 100644 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -22,11 +22,11 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandler; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; +import io.netty.channel.ChannelStateHandlerAdapter; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.socket.SocketChannel; @@ -225,7 +225,7 @@ public final class ServerBootstrap extends AbstractBootstrap { + extends ChannelStateHandlerAdapter implements ChannelInboundMessageHandler { private final EventLoopGroup childGroup; private final ChannelHandler childHandler; @@ -281,6 +281,11 @@ public final class ServerBootstrap extends AbstractBootstrap extends AbstractChannel { break; } nHandlers ++; - p.addLast(h); - if (h instanceof ChannelInboundHandler || h instanceof ChannelOutboundHandler) { + ChannelHandlerContext ctx = p.addLast(h).context(h); + + if (ctx.hasInboundByteBuffer() || ctx.hasOutboundByteBuffer() + || ctx.hasInboundMessageBuffer() || ctx.hasOutboundMessageBuffer()) { hasBuffer = true; } } @@ -324,9 +326,10 @@ public abstract class AbstractEmbeddedChannel extends AbstractChannel { } } - private final class LastInboundMessageHandler extends ChannelInboundHandlerAdapter { + private final class LastInboundMessageHandler extends ChannelStateHandlerAdapter + implements ChannelInboundMessageHandler { @Override - public Buf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { + public MessageBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { return lastInboundMessageBuffer; } @@ -347,12 +350,18 @@ public abstract class AbstractEmbeddedChannel extends AbstractChannel { } } - private final class LastInboundByteHandler extends ChannelInboundHandlerAdapter { + private final class LastInboundByteHandler extends ChannelStateHandlerAdapter + implements ChannelInboundByteHandler { @Override - public Buf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { + public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { return lastInboundByteBuffer; } + @Override + public void discardInboundReadBytes(ChannelHandlerContext ctx) throws Exception { + // nothing + } + @Override public void freeInboundBuffer(ChannelHandlerContext ctx) throws Exception { // Do NOT free the buffer.