diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java index 56c3b62967..82c39dca66 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java @@ -18,11 +18,10 @@ package io.netty.handler.codec.http.websocketx; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.channel.MessageList; +import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.FullHttpResponse; -class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapter { +class WebSocketClientProtocolHandshakeHandler extends SimpleChannelInboundHandler { private final WebSocketClientHandshaker handshaker; public WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) { @@ -46,10 +45,10 @@ class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapt } @Override - public void messageReceived(ChannelHandlerContext ctx, MessageList messages) throws Exception { + protected void messageReceived(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception { if (!handshaker.isHandshakeComplete()) { - handshaker.finishHandshake(ctx.channel(), (FullHttpResponse) messages.get(0)); - messages.remove(0); + handshaker.finishHandshake(ctx.channel(), msg); + msg.release(); ctx.fireUserEventTriggered( WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.pipeline().remove(this); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java index 449444cc37..ab3ec95dac 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java @@ -23,6 +23,7 @@ import io.netty.channel.ChannelInboundHandler; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelPipeline; import io.netty.channel.MessageList; +import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; @@ -121,19 +122,13 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler { } static ChannelHandler forbiddenHttpRequestResponder() { - return new ChannelInboundHandlerAdapter() { + return new SimpleChannelInboundHandler() { @Override - public void messageReceived(final ChannelHandlerContext ctx, MessageList msgs) throws Exception { - for (int i = 0; i < msgs.size(); i++) { - Object msg = msgs.get(i); - if (msg instanceof FullHttpRequest) { - FullHttpResponse response = - new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN); - ctx.channel().write(response); - msgs.remove(i--); - } - } - ctx.fireMessageReceived(msgs); + protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception { + msg.release(); + FullHttpResponse response = + new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN); + ctx.channel().write(response); } }; } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java index 3a6ebc67e0..4a4272548c 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java @@ -684,10 +684,8 @@ public class SpdySessionHandler ctx.write(spdyRstStreamFrame); if (fireMessageReceived) { in.add(spdyRstStreamFrame); - ctx.fireMessageReceived(in); - while (!in.isEmpty()) { - in.remove(0); - } + ctx.fireMessageReceived(in.copy()); + in.clear(); } } diff --git a/transport/src/main/java/io/netty/channel/MessageList.java b/transport/src/main/java/io/netty/channel/MessageList.java index 50023b2546..440fc93677 100644 --- a/transport/src/main/java/io/netty/channel/MessageList.java +++ b/transport/src/main/java/io/netty/channel/MessageList.java @@ -137,111 +137,6 @@ public final class MessageList { return elements[index]; } - public MessageList set(int index, T value) { - checkExclusive(index); - if (value == null) { - throw new NullPointerException("value"); - } - elements[index] = value; - return this; - } - - public MessageList set(int index, T[] src) { - if (src == null) { - throw new NullPointerException("src"); - } - set(index, src, 0, src.length); - return this; - } - - public MessageList set(int index, T[] src, int srcIdx, int srcLen) { - checkElements(src, srcIdx, srcLen); - - if (srcLen == 0) { - return remove(index); - } - - if (srcLen == 1) { - return set(index, src[srcIdx]); - } - - checkExclusive(index); - - int oldSize = size; - int newSize = oldSize + srcLen - 1; - ensureCapacity(newSize); - System.arraycopy(elements, index + 1, elements, index + srcLen, oldSize - (index + 1)); - System.arraycopy(src, srcIdx, elements, index, srcLen); - size = newSize; - return this; - } - - public MessageList set(int index, int length, T value) { - if (length == 0) { - return add(index, value); - } - - if (length == 1) { - return set(index, value); - } - - checkRange(index, length); - if (value == null) { - throw new NullPointerException("value"); - } - - elements[index] = value; - int nextElemIdx = index + length; - int oldSize = size; - int newSize = oldSize - length + 1; - System.arraycopy(elements, nextElemIdx, elements, index + 1, oldSize - nextElemIdx); - Arrays.fill(elements, newSize, oldSize, null); - size = newSize; - return this; - } - - public MessageList set(int index, int length, T[] src) { - if (src == null) { - throw new NullPointerException("src"); - } - return set(index, length, src, 0, src.length); - } - - public MessageList set(int index, int length, T[] src, int srcIdx, int srcLen) { - if (length == 0) { - return add(index, src, srcIdx, srcLen); - } - - if (length == 1) { - return set(index, src, srcIdx, srcLen); - } - - checkRange(index, length); - checkElements(src, srcIdx, srcLen); - - if (srcLen == length) { - System.arraycopy(src, srcIdx, elements, index, length); - } else if (srcLen < length) { - int remainderIdx = index + length; - int oldSize = size; - int newSize = oldSize - (length - srcLen); - System.arraycopy(src, srcIdx, elements, index, srcLen); - System.arraycopy(elements, remainderIdx, elements, index + srcLen, oldSize - remainderIdx); - Arrays.fill(elements, newSize, oldSize, null); - size = newSize; - } else { - int remainderIdx = index + length; - int oldSize = size; - int newSize = oldSize + srcLen - length; - ensureCapacity(newSize); - // 0 [1 2] 3 4 5 -> 0 [1 2 3] 3 4 5 - System.arraycopy(elements, remainderIdx, elements, index + srcLen, oldSize - remainderIdx); - System.arraycopy(src, srcIdx, elements, index, srcLen); - size = newSize; - } - return this; - } - public MessageList add(T value) { if (value == null) { throw new NullPointerException("value"); @@ -272,70 +167,6 @@ public final class MessageList { return this; } - public MessageList add(int index, T value) { - checkInclusive(index); - - if (value == null) { - throw new NullPointerException("value"); - } - - int oldSize = size; - int newSize = oldSize + 1; - ensureCapacity(newSize); - System.arraycopy(elements, index, elements, index + 1, oldSize - index); - elements[index] = value; - size = newSize; - return this; - } - - public MessageList add(int index, T[] src) { - if (src == null) { - throw new NullPointerException("src"); - } - return add(index, src, 0, src.length); - } - - public MessageList add(int index, T[] src, int srcIdx, int srcLen) { - checkInclusive(index); - checkElements(src, srcIdx, srcLen); - - if (srcLen == 0) { - return this; - } - - int oldSize = size; - int newSize = oldSize + srcLen; - ensureCapacity(newSize); - System.arraycopy(elements, index, elements, index + srcLen, oldSize - index); - System.arraycopy(src, srcIdx, elements, index, srcLen); - size = newSize; - return this; - } - - public MessageList remove(int index) { - checkExclusive(index); - int oldSize = size; - int newSize = oldSize - 1; - System.arraycopy(elements, index + 1, elements, index, newSize - index); - elements[newSize] = null; - size = newSize; - return this; - } - - public MessageList remove(int index, int length) { - checkRange(index, length); - if (length == 0) { - return this; - } - - int oldSize = size; - int newSize = oldSize - length; - System.arraycopy(elements, index + length, elements, index, newSize - index); - Arrays.fill(elements, newSize, oldSize, null); - size = newSize; - return this; - } - public MessageList clear() { Arrays.fill(elements, 0, size, null); size = 0; @@ -449,12 +280,6 @@ public final class MessageList { } } - private void checkInclusive(int index) { - if (index > size) { - throw new IndexOutOfBoundsException(String.valueOf(index)); - } - } - private void checkRange(int index, int length) { if (index + length > size) { throw new IndexOutOfBoundsException("index: " + index + ", length: " + length + ", size: " + size);