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 f90783be66..1ea168c543 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 @@ -45,9 +45,9 @@ class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapt } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof FullHttpResponse)) { - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); return; } 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 3de70e8800..c5bdde5c92 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 @@ -15,7 +15,6 @@ */ package io.netty.handler.codec.http.websocketx; -import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; @@ -31,6 +30,8 @@ import io.netty.util.AttributeKey; import java.util.List; +import static io.netty.handler.codec.http.HttpVersion.*; + /** * This handler does all the heavy lifting for you to run a websocket server. * @@ -123,13 +124,13 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler { static ChannelHandler forbiddenHttpRequestResponder() { return new ChannelInboundHandlerAdapter() { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof FullHttpRequest) { FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN); ctx.channel().write(response).flush(); } else { - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } } }; diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java index 9ca7a81054..041d6fba2a 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java @@ -50,7 +50,7 @@ class WebSocketServerProtocolHandshakeHandler } @Override - public void messageReceived(final ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { FullHttpRequest req = (FullHttpRequest) msg; if (req.getMethod() != GET) { sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN)); 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 9cfc57a899..e92f390238 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 @@ -60,13 +60,13 @@ public abstract class SpdyOrHttpChooser extends ChannelInboundHandlerAdapter { protected abstract SelectedProtocol getProtocol(SSLEngine engine); @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (initPipeline(ctx)) { // When we reached here we can remove this handler as its now clear what protocol we want to use // from this point on. ctx.pipeline().remove(this); - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java index 0de5c6dec1..49b15b933e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java @@ -102,7 +102,7 @@ final class SpdySession { } /* - * hasReceivedReply and receivedReply are only called from messageReceived + * hasReceivedReply and receivedReply are only called from channelRead() * no need to synchronize access to the StreamState */ boolean hasReceivedReply(int streamID) { 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 f9cceeca90..ec86192def 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 @@ -84,7 +84,7 @@ public class SpdySessionHandler } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof SpdyDataFrame) { /* @@ -378,7 +378,7 @@ public class SpdySessionHandler } } - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } @Override @@ -658,13 +658,13 @@ public class SpdySessionHandler * Note: this is only called by the worker thread */ private void issueStreamError(ChannelHandlerContext ctx, int streamId, SpdyStreamStatus status) { - boolean fireMessageReceived = !spdySession.isRemoteSideClosed(streamId); + boolean fireChannelRead = !spdySession.isRemoteSideClosed(streamId); removeStream(ctx, streamId); SpdyRstStreamFrame spdyRstStreamFrame = new DefaultSpdyRstStreamFrame(streamId, status); ctx.write(spdyRstStreamFrame).flush(); - if (fireMessageReceived) { - ctx.fireMessageReceived(spdyRstStreamFrame); + if (fireChannelRead) { + ctx.fireChannelRead(spdyRstStreamFrame); } } @@ -800,7 +800,7 @@ public class SpdySessionHandler halfCloseStream(streamId, false); } - ctx.fireMessageReceived(spdyDataFrame); + ctx.fireChannelRead(spdyDataFrame); } else { // We can send a partial frame spdySession.updateSendWindowSize(streamId, -1 * newWindowSize); @@ -826,7 +826,7 @@ public class SpdySessionHandler // } //}); - ctx.fireMessageReceived(partialDataFrame); + ctx.fireChannelRead(partialDataFrame); newWindowSize = 0; } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java index d6f8fb4676..9120c228a5 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java @@ -46,7 +46,7 @@ public class HttpObjectAggregatorTest { assertFalse(embedder.writeInbound(chunk1)); assertFalse(embedder.writeInbound(chunk2)); - // this should trigger a messageReceived event so return true + // this should trigger a channelRead event so return true assertTrue(embedder.writeInbound(chunk3)); assertTrue(embedder.finish()); DefaultFullHttpRequest aggratedMessage = (DefaultFullHttpRequest) embedder.readInbound(); @@ -87,7 +87,7 @@ public class HttpObjectAggregatorTest { assertFalse(embedder.writeInbound(chunk1)); assertFalse(embedder.writeInbound(chunk2)); - // this should trigger a messageReceived event so return true + // this should trigger a channelRead event so return true assertTrue(embedder.writeInbound(trailer)); assertTrue(embedder.finish()); DefaultFullHttpRequest aggratedMessage = (DefaultFullHttpRequest) embedder.readInbound(); @@ -172,7 +172,7 @@ public class HttpObjectAggregatorTest { assertFalse(embedder.writeInbound(chunk1)); assertFalse(embedder.writeInbound(chunk2)); - // this should trigger a messageReceived event so return true + // this should trigger a channelRead event so return true assertTrue(embedder.writeInbound(chunk3)); assertTrue(embedder.finish()); FullHttpRequest aggratedMessage = (FullHttpRequest) embedder.readInbound(); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java index 11bd2ff56a..704c6f0981 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java @@ -160,7 +160,7 @@ public class WebSocketServerProtocolHandlerTest { private String content; @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { assertNull(content); content = "processed: " + ((TextWebSocketFrame) msg).text(); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java index 3d16c57217..33e10049dd 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java @@ -131,7 +131,7 @@ public class SpdyFrameDecoderTest { public volatile Object message; @Override - public void messageReceived(ChannelHandlerContext ctx, Object m) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object m) throws Exception { message = m; } diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java index 0b9bc82297..15f0e9dcbd 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java @@ -303,7 +303,7 @@ public class SpdySessionHandlerTest { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof SpdySynStreamFrame) { SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg; diff --git a/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java b/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java index 9d066118a7..637a319a7a 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java @@ -78,8 +78,8 @@ public abstract class ByteToMessageCodec extends ChannelDuplexHandler { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { - decoder.messageReceived(ctx, msg); + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + decoder.channelRead(ctx, msg); } @Override 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 eaca15e068..d3415e7481 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java @@ -56,7 +56,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter } /** - * If set then only one message is decoded on each {@link #messageReceived(ChannelHandlerContext, Object)} + * If set then only one message is decoded on each {@link #channelRead(ChannelHandlerContext, Object)} * call. This may be useful if you need to do some protocol upgrade and want to make sure nothing is mixed up. * * Default is {@code false} as this has performance impacts. @@ -67,7 +67,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter /** * If {@code true} then only one message is decoded on each - * {@link #messageReceived(ChannelHandlerContext, Object)} call. + * {@link #channelRead(ChannelHandlerContext, Object)} call. * * Default is {@code false} as this has performance impacts. */ @@ -102,9 +102,9 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception { ByteBuf buf = internalBuffer(); if (buf.isReadable()) { - ctx.fireMessageReceived(buf); + ctx.fireChannelRead(buf); } - ctx.fireMessageReceivedLast(); + ctx.fireChannelReadComplete(); handlerRemoved0(ctx); } @@ -115,7 +115,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { CodecOutput out = CodecOutput.newInstance(); try { if (msg instanceof ByteBuf) { @@ -163,7 +163,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter } for (int i = 0; i < out.size(); i ++) { - ctx.fireMessageReceived(out.get(i)); + ctx.fireChannelRead(out.get(i)); } out.recycle(); @@ -171,14 +171,14 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter } @Override - public void channelReadSuspended(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { if (decodeWasNull) { decodeWasNull = false; if (!ctx.channel().config().isAutoRead()) { ctx.read(); } } - super.channelReadSuspended(ctx); + ctx.fireChannelReadComplete(); } @Override @@ -202,7 +202,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter } for (int i = 0; i < out.size(); i ++) { - ctx.fireMessageReceived(out.get(i)); + ctx.fireChannelRead(out.get(i)); } ctx.fireChannelInactive(); } @@ -256,7 +256,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter * Is called one last time when the {@link ChannelHandlerContext} goes in-active. Which means the * {@link #channelInactive(ChannelHandlerContext)} was triggered. * - * By default this will just call {@link #decode(ChannelHandlerContext, ByteBuf, CodecOutput)} but sub-classes may + * By default this will just call {@link #decode(ChannelHandlerContext, ByteBuf, List)} but sub-classes may * override this for some special cleanup operation. */ protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java index 36e3518b5d..5b796fe28e 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java @@ -96,8 +96,8 @@ public abstract class MessageToMessageCodec extends Cha } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { - decoder.messageReceived(ctx, msg); + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + decoder.channelRead(ctx, msg); } @Override @@ -124,13 +124,13 @@ public abstract class MessageToMessageCodec extends Cha } /** - * @see MessageToMessageEncoder#encode(ChannelHandlerContext, Object, CodecOutput) + * @see MessageToMessageEncoder#encode(ChannelHandlerContext, Object, List) */ protected abstract void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, List out) throws Exception; /** - * @see MessageToMessageDecoder#decode(ChannelHandlerContext, Object, CodecOutput) + * @see MessageToMessageDecoder#decode(ChannelHandlerContext, Object, List) */ protected abstract void decode(ChannelHandlerContext ctx, INBOUND_IN msg, List out) throws Exception; 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 2a7af14a9e..b5953581d2 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java @@ -64,7 +64,7 @@ public abstract class MessageToMessageDecoder extends ChannelInboundHandlerAd } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { CodecOutput out = CodecOutput.newInstance(); try { if (acceptInboundMessage(msg)) { @@ -84,7 +84,7 @@ public abstract class MessageToMessageDecoder extends ChannelInboundHandlerAd throw new DecoderException(e); } finally { for (int i = 0; i < out.size(); i ++) { - ctx.fireMessageReceived(out.get(i)); + ctx.fireChannelRead(out.get(i)); } out.recycle(); } 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 fa68e9c3a2..3d92d695ff 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java @@ -338,7 +338,7 @@ public abstract class ReplayingDecoder extends ByteToMessageDecoder { } for (int i = 0; i < out.size(); i ++) { - ctx.fireMessageReceived(out.get(i)); + ctx.fireChannelRead(out.get(i)); } ctx.fireChannelInactive(); } diff --git a/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayDecoder.java b/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayDecoder.java index 4edc5889c9..4574fbfbe1 100644 --- a/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayDecoder.java @@ -43,7 +43,7 @@ import java.util.List; * and then you can use an array of bytes instead of a {@link ByteBuf} * as a message: *
- * void messageReceived({@link ChannelHandlerContext} ctx, byte[] bytes) {
+ * void channelRead({@link ChannelHandlerContext} ctx, byte[] bytes) {
  *     ...
  * }
  * 
diff --git a/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java b/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java index 04f12ac9d4..da8df2799c 100644 --- a/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java @@ -45,7 +45,7 @@ import java.util.List; * and then you can use an array of bytes instead of a {@link ByteBuf} * as a message: *
- * void messageReceived({@link ChannelHandlerContext} ctx, byte[] bytes) {
+ * void channelRead({@link ChannelHandlerContext} ctx, byte[] bytes) {
  *     ...
  * }
  * 
diff --git a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufDecoder.java b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufDecoder.java index c13b59bbf6..ee91191bb4 100644 --- a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufDecoder.java @@ -15,6 +15,9 @@ */ package io.netty.handler.codec.protobuf; +import com.google.protobuf.ExtensionRegistry; +import com.google.protobuf.Message; +import com.google.protobuf.MessageLite; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; @@ -26,10 +29,6 @@ import io.netty.handler.codec.MessageToMessageDecoder; import java.util.List; -import com.google.protobuf.ExtensionRegistry; -import com.google.protobuf.Message; -import com.google.protobuf.MessageLite; - /** * Decodes a received {@link ByteBuf} into a * Google Protocol Buffers @@ -53,7 +52,7 @@ import com.google.protobuf.MessageLite; * and then you can use a {@code MyMessage} instead of a {@link ByteBuf} * as a message: *
- * void messageReceived({@link ChannelHandlerContext} ctx, MyMessage req) {
+ * void channelRead({@link ChannelHandlerContext} ctx, MyMessage req) {
  *     MyMessage res = MyMessage.newBuilder().setText(
  *                               "Did you say '" + req.getText() + "'?").build();
  *     ch.write(res);
diff --git a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufEncoder.java b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufEncoder.java
index fe1229903a..a7e56c26bc 100644
--- a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufEncoder.java
+++ b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufEncoder.java
@@ -15,7 +15,9 @@
  */
 package io.netty.handler.codec.protobuf;
 
-import static io.netty.buffer.Unpooled.wrappedBuffer;
+import com.google.protobuf.Message;
+import com.google.protobuf.MessageLite;
+import com.google.protobuf.MessageLiteOrBuilder;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandler.Sharable;
 import io.netty.channel.ChannelHandlerContext;
@@ -26,9 +28,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
 
 import java.util.List;
 
-import com.google.protobuf.Message;
-import com.google.protobuf.MessageLite;
-import com.google.protobuf.MessageLiteOrBuilder;
+import static io.netty.buffer.Unpooled.*;
 
 /**
  * Encodes the requested Google
@@ -50,7 +50,7 @@ import com.google.protobuf.MessageLiteOrBuilder;
  * and then you can use a {@code MyMessage} instead of a {@link ByteBuf}
  * as a message:
  * 
- * void messageReceived({@link ChannelHandlerContext} ctx, MyMessage req) {
+ * void channelRead({@link ChannelHandlerContext} ctx, MyMessage req) {
  *     MyMessage res = MyMessage.newBuilder().setText(
  *                               "Did you say '" + req.getText() + "'?").build();
  *     ch.write(res);
diff --git a/codec/src/main/java/io/netty/handler/codec/string/StringDecoder.java b/codec/src/main/java/io/netty/handler/codec/string/StringDecoder.java
index f3183113ff..0f219ae41b 100644
--- a/codec/src/main/java/io/netty/handler/codec/string/StringDecoder.java
+++ b/codec/src/main/java/io/netty/handler/codec/string/StringDecoder.java
@@ -46,7 +46,7 @@ import java.util.List;
  * and then you can use a {@link String} instead of a {@link ByteBuf}
  * as a message:
  * 
- * void messageReceived({@link ChannelHandlerContext} ctx, {@link String} msg) {
+ * void channelRead({@link ChannelHandlerContext} ctx, {@link String} msg) {
  *     ch.write("Did you say '" + msg + "'?\n");
  * }
  * 
diff --git a/codec/src/main/java/io/netty/handler/codec/string/StringEncoder.java b/codec/src/main/java/io/netty/handler/codec/string/StringEncoder.java index 3c2059fe66..cffbcdc44b 100644 --- a/codec/src/main/java/io/netty/handler/codec/string/StringEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/string/StringEncoder.java @@ -41,7 +41,7 @@ import java.nio.charset.Charset; * and then you can use a {@link String} instead of a {@link ByteBuf} * as a message: *
- * void messageReceived({@link ChannelHandlerContext} ctx, {@link String} msg) {
+ * void channelRead({@link ChannelHandlerContext} ctx, {@link String} msg) {
  *     ch.write("Did you say '" + msg + "'?\n");
  * }
  * 
diff --git a/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java b/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java index 8caf5f3937..108f4c6490 100644 --- a/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java +++ b/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java @@ -15,17 +15,16 @@ */ package io.netty.handler.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.embedded.EmbeddedChannel; +import org.junit.Test; import java.util.List; -import org.junit.Test; +import static org.junit.Assert.*; public class ReplayingDecoderTest { @@ -82,9 +81,9 @@ public class ReplayingDecoderTest { private static final class BloatedLineDecoder extends ChannelInboundHandlerAdapter { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.pipeline().replace(this, "less-bloated", new LineDecoder()); - ctx.pipeline().fireMessageReceived(msg); + ctx.pipeline().fireChannelRead(msg); } } diff --git a/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java b/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java index aaffa34d1d..77aa671cca 100644 --- a/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java +++ b/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java @@ -75,7 +75,7 @@ public class AppletDiscardServer extends JApplet { private static final class DiscardServerHandler extends SimpleChannelInboundHandler { @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { System.out.println("Received: " + msg.toString(CharsetUtil.UTF_8)); } diff --git a/example/src/main/java/io/netty/example/discard/DiscardClientHandler.java b/example/src/main/java/io/netty/example/discard/DiscardClientHandler.java index 031ae874ed..e4ed4b3b05 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardClientHandler.java +++ b/example/src/main/java/io/netty/example/discard/DiscardClientHandler.java @@ -62,7 +62,7 @@ public class DiscardClientHandler extends SimpleChannelInboundHandler { } @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // Server is supposed to send nothing, but if it sends something, discard it. } diff --git a/example/src/main/java/io/netty/example/discard/DiscardServerHandler.java b/example/src/main/java/io/netty/example/discard/DiscardServerHandler.java index dee7c8e987..a9ab5ee08d 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardServerHandler.java +++ b/example/src/main/java/io/netty/example/discard/DiscardServerHandler.java @@ -30,7 +30,7 @@ public class DiscardServerHandler extends SimpleChannelInboundHandler { DiscardServerHandler.class.getName()); @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // discard } diff --git a/example/src/main/java/io/netty/example/echo/EchoClientHandler.java b/example/src/main/java/io/netty/example/echo/EchoClientHandler.java index 847f178e07..a6d18784cd 100644 --- a/example/src/main/java/io/netty/example/echo/EchoClientHandler.java +++ b/example/src/main/java/io/netty/example/echo/EchoClientHandler.java @@ -54,12 +54,12 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/echo/EchoServerHandler.java b/example/src/main/java/io/netty/example/echo/EchoServerHandler.java index 1a7ce7294b..a68b7637b0 100644 --- a/example/src/main/java/io/netty/example/echo/EchoServerHandler.java +++ b/example/src/main/java/io/netty/example/echo/EchoServerHandler.java @@ -32,12 +32,12 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter { EchoServerHandler.class.getName()); @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/factorial/FactorialClientHandler.java b/example/src/main/java/io/netty/example/factorial/FactorialClientHandler.java index 6d1429f7f1..244041984c 100644 --- a/example/src/main/java/io/netty/example/factorial/FactorialClientHandler.java +++ b/example/src/main/java/io/netty/example/factorial/FactorialClientHandler.java @@ -39,7 +39,6 @@ public class FactorialClientHandler extends SimpleChannelInboundHandler answer = new LinkedBlockingQueue(); @@ -70,7 +69,7 @@ public class FactorialClientHandler extends SimpleChannelInboundHandler { @Override - public void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { File file = new File(msg); if (file.exists()) { if (!file.isFile()) { diff --git a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java index c15590ef0a..8c985f06e2 100644 --- a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java +++ b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java @@ -104,7 +104,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler { @Override - public void messageReceived0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { if (msg instanceof HttpResponse) { HttpResponse response = (HttpResponse) msg; diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java index 3c5d518fae..c61edd4f62 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java @@ -50,12 +50,12 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler private final StringBuilder buf = new StringBuilder(); @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } @Override - protected void messageReceived0(ChannelHandlerContext ctx, Object msg) { + protected void channelRead0(ChannelHandlerContext ctx, Object msg) { if (msg instanceof HttpRequest) { HttpRequest request = this.request = (HttpRequest) msg; diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java index 463afd686d..c920afb7f5 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadClientHandler.java @@ -36,7 +36,7 @@ public class HttpUploadClientHandler extends SimpleChannelInboundHandler } @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); diff --git a/example/src/main/java/io/netty/example/http/websocketx/html5/CustomTextFrameHandler.java b/example/src/main/java/io/netty/example/http/websocketx/html5/CustomTextFrameHandler.java index 0259062b5d..68bc9f22c7 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/html5/CustomTextFrameHandler.java +++ b/example/src/main/java/io/netty/example/http/websocketx/html5/CustomTextFrameHandler.java @@ -21,7 +21,7 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; public class CustomTextFrameHandler extends SimpleChannelInboundHandler { @Override - protected void messageReceived0(ChannelHandlerContext ctx, TextWebSocketFrame frame) throws Exception { + protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame frame) throws Exception { String request = frame.text(); ctx.channel().write(new TextWebSocketFrame(request.toUpperCase())); } diff --git a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java index a825cace6c..1b5f71e1b6 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java +++ b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerHandler.java @@ -53,7 +53,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler private WebSocketServerHandshaker handshaker; @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof FullHttpRequest) { handleHttpRequest(ctx, (FullHttpRequest) msg); } else if (msg instanceof WebSocketFrame) { diff --git a/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java b/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java index b51c0ab99b..d79cfda853 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java +++ b/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java @@ -54,7 +54,7 @@ public class WebSocketSslServerHandler extends SimpleChannelInboundHandler { @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // Print as received System.out.println(msg); } diff --git a/example/src/main/java/io/netty/example/localecho/LocalEchoServerHandler.java b/example/src/main/java/io/netty/example/localecho/LocalEchoServerHandler.java index 1e2c17199e..86e327ac48 100644 --- a/example/src/main/java/io/netty/example/localecho/LocalEchoServerHandler.java +++ b/example/src/main/java/io/netty/example/localecho/LocalEchoServerHandler.java @@ -22,13 +22,13 @@ import io.netty.channel.ChannelInboundHandlerAdapter; public class LocalEchoServerHandler extends ChannelInboundHandlerAdapter { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // Write back as received ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java index 679609823e..2834f80ccd 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClientHandler.java @@ -56,13 +56,13 @@ public class ObjectEchoClientHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // Echo back the received object to the server. ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServerHandler.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServerHandler.java index 60676ee4fc..001193f1c8 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServerHandler.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServerHandler.java @@ -31,14 +31,14 @@ public class ObjectEchoServerHandler extends ChannelInboundHandlerAdapter { ObjectEchoServerHandler.class.getName()); @Override - public void messageReceived( + public void channelRead( ChannelHandlerContext ctx, Object msg) throws Exception { // Echo back the received object to the client. ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/proxy/HexDumpProxyBackendHandler.java b/example/src/main/java/io/netty/example/proxy/HexDumpProxyBackendHandler.java index 18743b6a4d..a5b57fa255 100644 --- a/example/src/main/java/io/netty/example/proxy/HexDumpProxyBackendHandler.java +++ b/example/src/main/java/io/netty/example/proxy/HexDumpProxyBackendHandler.java @@ -37,7 +37,7 @@ public class HexDumpProxyBackendHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(final ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { inboundChannel.write(msg).flush().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { diff --git a/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java b/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java index 8b4f25434c..8cdefc2960 100644 --- a/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java +++ b/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java @@ -63,7 +63,7 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(final ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { if (outboundChannel.isActive()) { outboundChannel.write(msg).flush().addListener(new ChannelFutureListener() { @Override diff --git a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClientHandler.java b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClientHandler.java index 2bfea4c45b..eaab48d678 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClientHandler.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClientHandler.java @@ -23,7 +23,7 @@ import io.netty.util.CharsetUtil; public class QuoteOfTheMomentClientHandler extends SimpleChannelInboundHandler { @Override - public void messageReceived0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { String response = msg.content().toString(CharsetUtil.UTF_8); if (response.startsWith("QOTM: ")) { System.out.println("Quote of the Moment: " + response.substring(6)); diff --git a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServerHandler.java b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServerHandler.java index c19aa17781..ea7c0944de 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServerHandler.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServerHandler.java @@ -44,7 +44,7 @@ public class QuoteOfTheMomentServerHandler extends SimpleChannelInboundHandler { } @Override - public void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { if ("OK".equals(msg)) { System.out.println("Serial port responded to AT"); } else { diff --git a/example/src/main/java/io/netty/example/sctp/SctpEchoClientHandler.java b/example/src/main/java/io/netty/example/sctp/SctpEchoClientHandler.java index 47d0ef73e8..86e2aec649 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpEchoClientHandler.java +++ b/example/src/main/java/io/netty/example/sctp/SctpEchoClientHandler.java @@ -55,12 +55,12 @@ public class SctpEchoClientHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/sctp/SctpEchoServerHandler.java b/example/src/main/java/io/netty/example/sctp/SctpEchoServerHandler.java index 04595ddc63..9681fc439a 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpEchoServerHandler.java +++ b/example/src/main/java/io/netty/example/sctp/SctpEchoServerHandler.java @@ -39,12 +39,12 @@ public class SctpEchoServerHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } } diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatClientHandler.java b/example/src/main/java/io/netty/example/securechat/SecureChatClientHandler.java index 5dc5e6da51..5b4c9abbb1 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatClientHandler.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatClientHandler.java @@ -30,7 +30,7 @@ public class SecureChatClientHandler extends SimpleChannelInboundHandler SecureChatClientHandler.class.getName()); @Override - public void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { System.err.println(msg); } diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java b/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java index 5c9c3b704e..5421956af3 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java @@ -61,7 +61,7 @@ public class SecureChatServerHandler extends SimpleChannelInboundHandler } @Override - public void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { // Send the received message to all channels but the current one. for (Channel c: channels) { if (c != ctx.channel()) { diff --git a/example/src/main/java/io/netty/example/socksproxy/RelayHandler.java b/example/src/main/java/io/netty/example/socksproxy/RelayHandler.java index 6611964969..f388eaa03b 100644 --- a/example/src/main/java/io/netty/example/socksproxy/RelayHandler.java +++ b/example/src/main/java/io/netty/example/socksproxy/RelayHandler.java @@ -41,7 +41,7 @@ public final class RelayHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (relayChannel.isActive()) { relayChannel.write(msg).flush(); } else { diff --git a/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java b/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java index d4f751f376..18f1ef6c37 100644 --- a/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java +++ b/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java @@ -39,7 +39,7 @@ public final class SocksServerConnectHandler extends SimpleChannelInboundHandler private final Bootstrap b = new Bootstrap(); @Override - public void messageReceived0(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception { + public void channelRead0(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception { CallbackNotifier cb = new CallbackNotifier() { @Override public void onSuccess(final ChannelHandlerContext outboundCtx) { diff --git a/example/src/main/java/io/netty/example/socksproxy/SocksServerHandler.java b/example/src/main/java/io/netty/example/socksproxy/SocksServerHandler.java index 3fb10fd8b3..93e79ec2a5 100644 --- a/example/src/main/java/io/netty/example/socksproxy/SocksServerHandler.java +++ b/example/src/main/java/io/netty/example/socksproxy/SocksServerHandler.java @@ -37,7 +37,7 @@ public final class SocksServerHandler extends SimpleChannelInboundHandler { private static final Logger logger = Logger.getLogger(TelnetClientHandler.class.getName()); @Override - protected void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { System.err.println(msg); } diff --git a/example/src/main/java/io/netty/example/telnet/TelnetServerHandler.java b/example/src/main/java/io/netty/example/telnet/TelnetServerHandler.java index 889e7ad8ca..840059314d 100644 --- a/example/src/main/java/io/netty/example/telnet/TelnetServerHandler.java +++ b/example/src/main/java/io/netty/example/telnet/TelnetServerHandler.java @@ -43,7 +43,7 @@ public class TelnetServerHandler extends SimpleChannelInboundHandler { } @Override - public void messageReceived0(ChannelHandlerContext ctx, String request) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String request) throws Exception { // Generate and write a response. String response; diff --git a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClientHandler.java b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClientHandler.java index e2e26813c6..bc092e68e4 100644 --- a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClientHandler.java +++ b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClientHandler.java @@ -58,14 +58,14 @@ public class ByteEchoClientHandler extends SimpleChannelInboundHandler } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { meter.mark(msg.readableBytes()); ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServerHandler.java b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServerHandler.java index 31c387678b..9dac3cf4ec 100644 --- a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServerHandler.java +++ b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServerHandler.java @@ -32,12 +32,12 @@ public class ByteEchoServerHandler extends ChannelInboundHandlerAdapter { private static final Logger log = Logger.getLogger(ByteEchoServerHandler.class.getName()); @Override - public void messageReceived(final ChannelHandlerContext ctx, Object msg) { + public void channelRead(final ChannelHandlerContext ctx, Object msg) { ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClientHandler.java b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClientHandler.java index 4207a4bc5b..009c5a6963 100644 --- a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClientHandler.java +++ b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClientHandler.java @@ -65,14 +65,14 @@ public class MsgEchoClientHandler extends SimpleChannelInboundHandler { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf buf) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Exception { meter.mark(buf.readableBytes()); ctx.write(buf); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } } diff --git a/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java b/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java index e55246b7be..88444ac7cc 100644 --- a/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java +++ b/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java @@ -49,7 +49,7 @@ public class UptimeClientHandler extends SimpleChannelInboundHandler { } @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // Discard received data } diff --git a/example/src/main/java/io/netty/example/worldclock/WorldClockClientHandler.java b/example/src/main/java/io/netty/example/worldclock/WorldClockClientHandler.java index 391e4a85ef..cf1836f8d8 100644 --- a/example/src/main/java/io/netty/example/worldclock/WorldClockClientHandler.java +++ b/example/src/main/java/io/netty/example/worldclock/WorldClockClientHandler.java @@ -99,7 +99,7 @@ public class WorldClockClientHandler extends SimpleChannelInboundHandler messageList = new ArrayList(); decode(ctx, internalBuffer(), messageList); for (int i = 0; i < messageList.size(); i++) { - ctx.fireMessageReceived(messageList.get(i)); + ctx.fireChannelRead(messageList.get(i)); } } @@ -808,6 +808,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH return packetLength; } + @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws SSLException { int packetLength = this.packetLength; if (packetLength == 0) { diff --git a/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java b/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java index 4bb9a47384..2b3c349f99 100644 --- a/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java +++ b/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java @@ -247,10 +247,10 @@ public class IdleStateHandler extends ChannelDuplexHandler { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { lastReadTime = System.currentTimeMillis(); firstReaderIdleEvent = firstAllIdleEvent = true; - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } @Override diff --git a/handler/src/main/java/io/netty/handler/timeout/ReadTimeoutHandler.java b/handler/src/main/java/io/netty/handler/timeout/ReadTimeoutHandler.java index 151c6ff47e..39fe3f5488 100644 --- a/handler/src/main/java/io/netty/handler/timeout/ReadTimeoutHandler.java +++ b/handler/src/main/java/io/netty/handler/timeout/ReadTimeoutHandler.java @@ -144,9 +144,9 @@ public class ReadTimeoutHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { lastReadTime = System.currentTimeMillis(); - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } private void initialize(ChannelHandlerContext ctx) { diff --git a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java index 2da0645748..1ced7bf111 100644 --- a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java +++ b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java @@ -208,7 +208,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler } @Override - public void messageReceived(final ChannelHandlerContext ctx, final Object msg) throws Exception { + public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; long size = buf.readableBytes(); long curtime = System.currentTimeMillis(); @@ -217,7 +217,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler trafficCounter.bytesRecvFlowControl(size); if (readLimit == 0) { // no action - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); return; } @@ -248,7 +248,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler Runnable bufferUpdateTask = new Runnable() { @Override public void run() { - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } }; ctx.executor().schedule(bufferUpdateTask, wait, TimeUnit.MILLISECONDS); @@ -256,7 +256,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler } } } - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } @Override diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java index 5667d75a3c..f140b4e5fb 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java @@ -149,7 +149,7 @@ public class SctpEchoTest extends AbstractSctpTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { byte[] actual = new byte[in.readableBytes()]; in.readBytes(actual); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java index 05be78ed3b..de67fcec99 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java @@ -45,7 +45,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest { sb.handler(new SimpleChannelInboundHandler() { @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // Nothing will be sent. } }); @@ -97,7 +97,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest { private volatile boolean fail; @Override - protected void messageReceived0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { + protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { if (done) { fail = true; } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java index 7626c61c3e..9161f99470 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java @@ -40,7 +40,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest { sb.handler(new SimpleChannelInboundHandler() { @Override - public void messageReceived0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { assertEquals(1, msg.content().readInt()); latch.countDown(); } @@ -48,7 +48,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest { cb.handler(new SimpleChannelInboundHandler() { @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msgs) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msgs) throws Exception { // Nothing will be sent. } }); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketBufReleaseTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketBufReleaseTest.java index 5e335f759a..194a2419b9 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketBufReleaseTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketBufReleaseTest.java @@ -95,7 +95,7 @@ public class SocketBufReleaseTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // discard } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java index ff2ab39b7c..44059e121e 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java @@ -199,7 +199,7 @@ public class SocketEchoTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { byte[] actual = new byte[in.readableBytes()]; in.readBytes(actual); @@ -216,7 +216,7 @@ public class SocketEchoTest extends AbstractSocketTest { } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java index fb28af7f46..9ab063a286 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java @@ -72,7 +72,7 @@ public class SocketFileRegionTest extends AbstractSocketTest { ChannelInboundHandler ch = new SimpleChannelInboundHandler() { @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { } @Override @@ -131,7 +131,7 @@ public class SocketFileRegionTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { byte[] actual = new byte[in.readableBytes()]; in.readBytes(actual); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java index fb304bfe69..ed1e74a150 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java @@ -134,7 +134,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { assertEquals(1024, msg.readableBytes()); byte[] actual = new byte[msg.readableBytes()]; @@ -153,7 +153,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest { } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java index 29d86ef620..f3a1cbc433 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java @@ -132,7 +132,7 @@ public class SocketGatheringWriteTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { counter += in.readableBytes(); received.writeBytes(in); } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java index 2e9388821b..aad49240c2 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java @@ -31,7 +31,7 @@ import java.io.IOException; import java.util.Random; import java.util.concurrent.atomic.AtomicReference; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; public class SocketObjectEchoTest extends AbstractSocketTest { @@ -145,7 +145,7 @@ public class SocketObjectEchoTest extends AbstractSocketTest { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { assertEquals(data[counter], msg); if (channel.parent() != null) { @@ -156,7 +156,7 @@ public class SocketObjectEchoTest extends AbstractSocketTest { } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputByPeerTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputByPeerTest.java index 0a5969e92a..3ad0d95a30 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputByPeerTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputByPeerTest.java @@ -127,7 +127,7 @@ public class SocketShutdownOutputByPeerTest extends AbstractServerSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { queue.offer(msg.readByte()); } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java index 254bf4ceed..ea90ebe397 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java @@ -86,7 +86,7 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { queue.offer(msg.readByte()); } } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java index ddfd7eeae1..c6023e5b0e 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java @@ -233,12 +233,12 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { final AtomicReference exception = new AtomicReference(); @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.write(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } @@ -260,7 +260,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { byte[] actual = new byte[in.readableBytes()]; in.readBytes(actual); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java index 4066017abe..c0677656ee 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java @@ -180,7 +180,7 @@ public class SocketSslEchoTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { byte[] actual = new byte[in.readableBytes()]; in.readBytes(actual); @@ -197,7 +197,7 @@ public class SocketSslEchoTest extends AbstractSocketTest { } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java index f683ce37c3..b42a49fd64 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java @@ -159,7 +159,7 @@ public class SocketStartTlsTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { if ("StartTlsResponse".equals(msg)) { ctx.pipeline().addAfter("logger", "ssl", sslHandler); handshakeFuture = sslHandler.handshakeFuture(); @@ -201,7 +201,7 @@ public class SocketStartTlsTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { if ("StartTlsRequest".equals(msg)) { ctx.pipeline().addAfter("logger", "ssl", sslHandler); ctx.writeAndFlush("StartTlsResponse\n"); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java index d02bbc9860..8b329a62c0 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java @@ -146,7 +146,7 @@ public class SocketStringEchoTest extends AbstractSocketTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, String msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { assertEquals(data[counter], msg); if (channel.parent() != null) { @@ -158,7 +158,7 @@ public class SocketStringEchoTest extends AbstractSocketTest { } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java index dc508d899e..75697d7d20 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java @@ -167,7 +167,7 @@ public class UDTClientServerConnectionTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { log.info("Client received: " + msg); } } @@ -320,7 +320,7 @@ public class UDTClientServerConnectionTest { } @Override - public void messageReceived0(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { log.info("Server received: " + msg); } } diff --git a/transport-udt/src/test/java/io/netty/test/udt/util/EchoByteHandler.java b/transport-udt/src/test/java/io/netty/test/udt/util/EchoByteHandler.java index 2b7486a9db..2f96bf851a 100644 --- a/transport-udt/src/test/java/io/netty/test/udt/util/EchoByteHandler.java +++ b/transport-udt/src/test/java/io/netty/test/udt/util/EchoByteHandler.java @@ -62,7 +62,7 @@ public class EchoByteHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; if (meter != null) { meter.mark(buf.readableBytes()); diff --git a/transport-udt/src/test/java/io/netty/test/udt/util/EchoMessageHandler.java b/transport-udt/src/test/java/io/netty/test/udt/util/EchoMessageHandler.java index b229dd2b88..9d3107302d 100644 --- a/transport-udt/src/test/java/io/netty/test/udt/util/EchoMessageHandler.java +++ b/transport-udt/src/test/java/io/netty/test/udt/util/EchoMessageHandler.java @@ -67,7 +67,7 @@ public class EchoMessageHandler extends ChannelInboundHandlerAdapter { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { UdtMessage udtMsg = (UdtMessage) msg; if (meter != null) { meter.mark(udtMsg.content().readableBytes()); diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java index 1ac971f796..d4ac7f54bc 100644 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -226,7 +226,7 @@ public final class ServerBootstrap extends AbstractBootstrap messages = outboundBuffer.currentMessages; + MessageList messages = outboundBuffer.currentMessages; // Make sure the message list is not empty. if (messages == null) { diff --git a/transport/src/main/java/io/netty/channel/ChannelConfig.java b/transport/src/main/java/io/netty/channel/ChannelConfig.java index df16c620dc..83133fc289 100644 --- a/transport/src/main/java/io/netty/channel/ChannelConfig.java +++ b/transport/src/main/java/io/netty/channel/ChannelConfig.java @@ -120,7 +120,7 @@ public interface ChannelConfig { /** * Returns the maximum number of messages in a {@link MessageList} of - * a {@link ChannelInboundHandler#messageReceived(ChannelHandlerContext, MessageList) messageReceived()} event. + * a {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) channelRead()} event. * If this value is greater than 1, an event loop might attempt to read multiple times to fill multiple messages * into the {@link MessageList}. */ @@ -128,7 +128,7 @@ public interface ChannelConfig { /** * Sets the maximum number of messages in a {@link MessageList} of - * a {@link ChannelInboundHandler#messageReceived(ChannelHandlerContext, MessageList) messageReceived()} event. + * a {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) channelRead()} event. * If this value is greater than 1, an event loop might attempt to read multiple times to fill multiple messages * into the {@link MessageList}. */ diff --git a/transport/src/main/java/io/netty/channel/ChannelFuture.java b/transport/src/main/java/io/netty/channel/ChannelFuture.java index bb29e297fe..c5b671ec48 100644 --- a/transport/src/main/java/io/netty/channel/ChannelFuture.java +++ b/transport/src/main/java/io/netty/channel/ChannelFuture.java @@ -95,7 +95,7 @@ import java.util.concurrent.TimeUnit; *
  * // BAD - NEVER DO THIS
  * {@code @Override}
- * public void messageReceived({@link ChannelHandlerContext} ctx, GoodByeMessage msg) {
+ * public void channelRead({@link ChannelHandlerContext} ctx, GoodByeMessage msg) {
  *     {@link ChannelFuture} future = ctx.channel().close();
  *     future.awaitUninterruptibly();
  *     // Perform post-closure operation
@@ -104,7 +104,7 @@ import java.util.concurrent.TimeUnit;
  *
  * // GOOD
  * {@code @Override}
- * public void messageReceived({@link ChannelHandlerContext} ctx,  GoodByeMessage msg) {
+ * public void channelRead({@link ChannelHandlerContext} ctx,  GoodByeMessage msg) {
  *     {@link ChannelFuture} future = ctx.channel().close();
  *     future.addListener(new {@link ChannelFutureListener}() {
  *         public void operationComplete({@link ChannelFuture} future) {
diff --git a/transport/src/main/java/io/netty/channel/ChannelHandler.java b/transport/src/main/java/io/netty/channel/ChannelHandler.java
index 072d3401d8..2384292037 100644
--- a/transport/src/main/java/io/netty/channel/ChannelHandler.java
+++ b/transport/src/main/java/io/netty/channel/ChannelHandler.java
@@ -69,7 +69,7 @@ import java.lang.annotation.Target;
  *     private boolean loggedIn;
  *
  *     {@code @Override}
- *     public void messageReceived({@link ChannelHandlerContext} ctx, Message message) {
+ *     public void channelRead({@link ChannelHandlerContext} ctx, Message message) {
  *         {@link Channel} ch = e.getChannel();
  *         if (message instanceof LoginMessage) {
  *             authenticate((LoginMessage) message);
@@ -120,11 +120,11 @@ import java.lang.annotation.Target;
  *   // This handler will receive a sequence of increasing integers starting
  *   // from 1.
  *   {@code @Override}
- *   public void messageReceived({@link ChannelHandlerContext} ctx, {@link Integer} integer) {
+ *   public void channelRead({@link ChannelHandlerContext} ctx, {@link Integer} integer) {
  *     {@link Attribute}<{@link Boolean}> attr = ctx.getAttr(auth);
  *
  *     {@code @Override}
- *     public void messageReceived({@link ChannelHandlerContext} ctx, Message message) {
+ *     public void channelRead({@link ChannelHandlerContext} ctx, Message message) {
  *         {@link Channel} ch = ctx.channel();
  *         if (message instanceof LoginMessage) {
  *             authenticate((LoginMessage) o);
diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/ChannelHandlerContext.java
index 4974eccde5..fe1a83a5df 100755
--- a/transport/src/main/java/io/netty/channel/ChannelHandlerContext.java
+++ b/transport/src/main/java/io/netty/channel/ChannelHandlerContext.java
@@ -88,7 +88,7 @@ import java.nio.channels.Channels;
  *   // This handler will receive a sequence of increasing integers starting
  *   // from 1.
  *   {@code @Override}
- *   public void messageReceived({@link ChannelHandlerContext} ctx, {@link Integer} integer) {
+ *   public void channelRead({@link ChannelHandlerContext} ctx, {@link Integer} integer) {
  *     {@link Attribute}<{@link Integer}> attr = ctx.getAttr(counter);
  *     Integer a = ctx.getAttr(counter).get();
  *
@@ -176,13 +176,10 @@ public interface ChannelHandlerContext
     ChannelHandlerContext fireUserEventTriggered(Object event);
 
     @Override
-    ChannelHandlerContext fireMessageReceived(Object msg);
+    ChannelHandlerContext fireChannelRead(Object msg);
 
     @Override
-    ChannelHandlerContext fireMessageReceivedLast();
-
-    @Override
-    ChannelHandlerContext fireChannelReadSuspended();
+    ChannelHandlerContext fireChannelReadComplete();
 
     @Override
     ChannelHandlerContext fireChannelWritabilityChanged();
diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundHandler.java b/transport/src/main/java/io/netty/channel/ChannelInboundHandler.java
index dee5646b3a..ca81c87f78 100755
--- a/transport/src/main/java/io/netty/channel/ChannelInboundHandler.java
+++ b/transport/src/main/java/io/netty/channel/ChannelInboundHandler.java
@@ -43,20 +43,17 @@ public interface ChannelInboundHandler extends ChannelHandler {
     void channelInactive(ChannelHandlerContext ctx) throws Exception;
 
     /**
-     * Invoked when a {@link ChannelHandlerContext#read()} is finished and the inbound buffer of this handler will not
-     * be updated until another {@link ChannelHandlerContext#read()} request is issued.
+     * Invoked when the current {@link Channel} has read a message from the peer.
      */
-    void channelReadSuspended(ChannelHandlerContext ctx) throws Exception;
+    void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception;
 
     /**
-     * The inbound buffer of the {@link ChannelHandlerContext} was updated with new data.
-     * This means something may be ready to get processed by the actual {@link ChannelInboundHandler}
-     * implementation. It's up to the implementation to consume it or keep it in the buffer
-     * to wait for more data and consume it later.
+     * Invoked when the last message read by the current read operation has been consumed by
+     * {@link #channelRead(ChannelHandlerContext, Object)}.  If {@link ChannelOption#AUTO_READ} is off, no further
+     * attempt to read an inbound data from the current {@link Channel} will be made until
+     * {@link ChannelHandlerContext#read()} is called.
      */
-    void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception;
-
-    void messageReceivedLast(ChannelHandlerContext ctx) throws Exception;
+    void channelReadComplete(ChannelHandlerContext ctx) throws Exception;
 
     /**
      * Gets called if an user event was triggered.
diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelInboundHandlerAdapter.java
index 69e57f7a85..9824b204f2 100644
--- a/transport/src/main/java/io/netty/channel/ChannelInboundHandlerAdapter.java
+++ b/transport/src/main/java/io/netty/channel/ChannelInboundHandlerAdapter.java
@@ -24,7 +24,7 @@ package io.netty.channel;
  * {@link ChannelPipeline}. Sub-classes may override a method implementation to change this.
  * 

*

- * Be aware that messages are not released after the {@link #messageReceived(ChannelHandlerContext, Object)} + * Be aware that messages are not released after the {@link #channelRead(ChannelHandlerContext, Object)} * method returns automatically. If you are looking for a {@link ChannelInboundHandler} implementation that * releases the received messages automatically, please see {@link SimpleChannelInboundHandler}. *

@@ -74,31 +74,21 @@ public class ChannelInboundHandlerAdapter extends ChannelHandlerAdapter implemen public void channelInactive(ChannelHandlerContext ctx) throws Exception { ctx.fireChannelInactive(); } + /** - * Calls {@link ChannelHandlerContext#fireChannelReadSuspended()} to forward + * Calls {@link ChannelHandlerContext#fireChannelRead(Object)} to forward * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}. * * Sub-classes may override this method to change behavior. */ @Override - public void channelReadSuspended(ChannelHandlerContext ctx) throws Exception { - ctx.fireChannelReadSuspended(); - } - - /** - * Calls {@link ChannelHandlerContext#fireMessageReceived(Object)} to forward - * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}. - * - * Sub-classes may override this method to change behavior. - */ - @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { - ctx.fireMessageReceived(msg); + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + ctx.fireChannelRead(msg); } @Override - public void messageReceivedLast(ChannelHandlerContext ctx) throws Exception { - ctx.fireMessageReceivedLast(); + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + ctx.fireChannelReadComplete(); } /** diff --git a/transport/src/main/java/io/netty/channel/ChannelInboundInvoker.java b/transport/src/main/java/io/netty/channel/ChannelInboundInvoker.java index d4c48e9968..1d87314725 100644 --- a/transport/src/main/java/io/netty/channel/ChannelInboundInvoker.java +++ b/transport/src/main/java/io/netty/channel/ChannelInboundInvoker.java @@ -76,21 +76,15 @@ interface ChannelInboundInvoker { ChannelInboundInvoker fireUserEventTriggered(Object event); /** - * A {@link Channel} received bytes which are now ready to read from its inbound buffer. + * A {@link Channel} received a message. * - * This will result in having the {@link ChannelInboundHandler#messageReceived(ChannelHandlerContext, Object)} + * This will result in having the {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} * method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * {@link Channel}. */ - ChannelInboundInvoker fireMessageReceived(Object msg); + ChannelInboundInvoker fireChannelRead(Object msg); - ChannelInboundInvoker fireMessageReceivedLast(); - - /** - * Triggers an {@link ChannelInboundHandler#channelReadSuspended(ChannelHandlerContext) channelReadSuspended} - * event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}. - */ - ChannelInboundInvoker fireChannelReadSuspended(); + ChannelInboundInvoker fireChannelReadComplete(); /** * Triggers an {@link ChannelInboundHandler#channelWritabilityChanged(ChannelHandlerContext)} diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java index fa92a153a2..4a8df4f6ff 100644 --- a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java +++ b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java @@ -32,12 +32,12 @@ final class ChannelOutboundBuffer { private static final int MIN_INITIAL_CAPACITY = 8; ChannelPromise currentPromise; - MessageList currentMessages; + MessageList currentMessages; int currentMessageIndex; private long currentMessageListSize; private ChannelPromise[] promises; - private MessageList[] messages; + private MessageList[] messages; private long[] messageListSizes; private int head; @@ -87,7 +87,7 @@ final class ChannelOutboundBuffer { void addMessage(Object msg) { int tail = this.tail; - MessageList msgs = messages[tail]; + MessageList msgs = messages[tail]; if (msgs == null) { messages[tail] = msgs = MessageList.newInstance(); } @@ -154,7 +154,7 @@ final class ChannelOutboundBuffer { promises = a1; @SuppressWarnings("unchecked") - MessageList[] a2 = new MessageList[newCapacity]; + MessageList[] a2 = new MessageList[newCapacity]; System.arraycopy(messages, p, a2, 0, r); System.arraycopy(messages, 0, a2, r, p); messages = a2; @@ -249,9 +249,11 @@ final class ChannelOutboundBuffer { if (currentMessages != null) { // Release all failed messages. + Object[] array = currentMessages.array(); + final int size = currentMessages.size(); try { - for (int i = currentMessageIndex; i < currentMessages.size(); i++) { - Object msg = currentMessages.get(i); + for (int i = currentMessageIndex; i < size; i++) { + Object msg = array[i]; ReferenceCountUtil.release(msg); } } finally { diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundInvoker.java b/transport/src/main/java/io/netty/channel/ChannelOutboundInvoker.java index 497d27f735..eb9029be59 100644 --- a/transport/src/main/java/io/netty/channel/ChannelOutboundInvoker.java +++ b/transport/src/main/java/io/netty/channel/ChannelOutboundInvoker.java @@ -190,9 +190,9 @@ interface ChannelOutboundInvoker { /** * Request to Read data from the {@link Channel} into the first inbound buffer, triggers an - * {@link ChannelInboundHandler#messageReceived(ChannelHandlerContext, Object)} event if data was - * read, and triggers an - * {@link ChannelInboundHandler#channelReadSuspended(ChannelHandlerContext) channelReadSuspended} event so the + * {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was + * read, and triggers a + * {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the * handler can decide to continue reading. If there's a pending read operation already, this method does nothing. *

* This will result in having the diff --git a/transport/src/main/java/io/netty/channel/ChannelPipeline.java b/transport/src/main/java/io/netty/channel/ChannelPipeline.java index 2c791769b7..9aabd90a3c 100644 --- a/transport/src/main/java/io/netty/channel/ChannelPipeline.java +++ b/transport/src/main/java/io/netty/channel/ChannelPipeline.java @@ -44,7 +44,7 @@ import java.util.NoSuchElementException; * The following diagram describes how I/O events are processed by {@link ChannelHandler}s in a {@link ChannelPipeline} * typically. An I/O event is handled by either a {@link ChannelInboundHandler} or a {@link ChannelOutboundHandler} * and be forwarded to its closest handler by calling the event propagation methods defined in - * {@link ChannelHandlerContext}, such as {@link ChannelHandlerContext#fireMessageReceived(Object)} and + * {@link ChannelHandlerContext}, such as {@link ChannelHandlerContext#fireChannelRead(Object)} and * {@link ChannelHandlerContext#write(Object)}. * *

@@ -132,11 +132,10 @@ import java.util.NoSuchElementException;
  *     
    *
  • {@link ChannelHandlerContext#fireChannelRegistered()}
  • *
  • {@link ChannelHandlerContext#fireChannelActive()}
  • - *
  • {@link ChannelHandlerContext#fireMessageReceived(Object)}
  • - *
  • {@link ChannelHandlerContext#fireMessageReceivedLast()}
  • + *
  • {@link ChannelHandlerContext#fireChannelRead(Object)}
  • + *
  • {@link ChannelHandlerContext#fireChannelReadComplete()}
  • *
  • {@link ChannelHandlerContext#fireExceptionCaught(Throwable)}
  • *
  • {@link ChannelHandlerContext#fireUserEventTriggered(Object)}
  • - *
  • {@link ChannelHandlerContext#fireChannelReadSuspended()}
  • *
  • {@link ChannelHandlerContext#fireChannelWritabilityChanged()}
  • *
  • {@link ChannelHandlerContext#fireChannelInactive()}
  • *
  • {@link ChannelHandlerContext#fireChannelUnregistered()}
  • @@ -614,13 +613,10 @@ public interface ChannelPipeline ChannelPipeline fireUserEventTriggered(Object event); @Override - ChannelPipeline fireMessageReceived(Object msg); + ChannelPipeline fireChannelRead(Object msg); @Override - ChannelPipeline fireMessageReceivedLast(); - - @Override - ChannelPipeline fireChannelReadSuspended(); + ChannelPipeline fireChannelReadComplete(); @Override ChannelPipeline fireChannelWritabilityChanged(); diff --git a/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java b/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java index eed89522d6..d604bd4dc9 100644 --- a/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java +++ b/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java @@ -144,13 +144,13 @@ public class CombinedChannelDuplexHandlerRecycling a {@link MessageList} - *

    - * A {@link MessageList} is internally managed by a thread-local object pool to keep the GC pressure minimal. - * To return the {@link MessageList} to the pool, you must call one of the following methods: {@link #recycle()}, - * {@link #releaseAllAndRecycle()}, or {@link #releaseAllAndRecycle(int)}. If the list is returned to the pool (i.e. - * recycled), it will be reused when you attempts to get a {@link MessageList} via {@link #newInstance()}. - *

    - * If you don't think recycling a {@link MessageList} isn't worth, it is also fine not to recycle it. Because of this - * relaxed contract, you can also decide not to wrap your code with a {@code try-finally} block only to recycle a - * list. However, if you decided to recycle it, you must keep in mind that: - *

      - *
    • you must make sure you do not access the list once it has been recycled.
    • - *
    • If you are given with a {@link MessageList} as a parameter of your handler, it means it is your handler's - * responsibility to release the messages in it and to recycle it.
    • - *
    - *

    - * - *

    Consuming the messages from a {@link MessageList} efficiently yet safely

    - *

    - * The following example shows how to iterate over the list which contains {@code ReferenceCounted} messages safely - * (i.e. without leaking them) while consuming the messages. - *

    - *
    - * public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageList}<Object> msgs) {
    - *     final int size = msgs.size();
    - *     final Object[] in = msgs.array();
    - *     boolean success = false;
    - *     try {
    - *         for (int i = 0; i < size; i ++) {
    - *             Object m = in[i];
    - *
    - *             // Handle the message.
    - *             doSomethingWithMessage(m);
    - *
    - *             // Release the handled message.
    - *             {@link ReferenceCountUtil#release(Object) ReferenceCountUtil.release(m)};
    - *
    - *             // To prevent {@link #releaseAllAndRecycle()} from releasing the message again,
    - *             // replace the message with a dummy object.
    - *             in[i] = MessageList.NONE;
    - *         }
    - *
    - *         success = true;
    - *     } finally {
    - *         if (success) {
    - *             {@link #recycle() msgs.recycle()};
    - *         } else {
    - *             {@link #releaseAllAndRecycle() msgs.releaseAllAndRecycle()};
    - *         }
    - *     }
    - * }
    - * 
    - * - * @param the type of the contained messages */ -final class MessageList implements Iterable { +final class MessageList { private static final int DEFAULT_INITIAL_CAPACITY = 8; private static final int MIN_INITIAL_CAPACITY = 4; - private static final Recycler> RECYCLER = new Recycler>() { + private static final Recycler RECYCLER = new Recycler() { @Override - protected MessageList newObject(Handle handle) { - return new MessageList(handle); + protected MessageList newObject(Handle handle) { + return new MessageList(handle); } }; /** - * Create a new empty {@link MessageList} instance + * Create a new empty {@link MessageList} instance. */ - public static MessageList newInstance() { - return newInstance(DEFAULT_INITIAL_CAPACITY); - } - - /** - * Create a new empty {@link MessageList} instance with the given capacity. - */ - @SuppressWarnings("unchecked") - public static MessageList newInstance(int minCapacity) { - MessageList ret = (MessageList) RECYCLER.get(); - ret.ensureCapacity(minCapacity); - ret.modifications = 0; + static MessageList newInstance() { + MessageList ret = RECYCLER.get(); return ret; } - /** - * Create a new {@link MessageList} instance which holds the given value - */ - public static MessageList newInstance(T value) { - MessageList ret = newInstance(MIN_INITIAL_CAPACITY); - ret.add(value); - return ret; - } - - /** - * Call {@link ReferenceCountUtil#retain(Object)} on all messages in this {@link MessageList} and return itself. - */ - public MessageList retainAll() { - int size = this.size; - for (int i = 0; i < size; i ++) { - ReferenceCountUtil.retain(elements[i]); - } - return this; - } - - /** - * Call {@link ReferenceCountUtil#retain(Object), int} on all messages in this {@link MessageList} and return - * itself. - */ - public MessageList retainAll(int increment) { - int size = this.size; - for (int i = 0; i < size; i ++) { - ReferenceCountUtil.retain(elements[i], increment); - } - return this; - } - - /** - * Call {@link ReferenceCountUtil#release(Object)} on all messages in this {@link MessageList} and return - * {@code true} if all messages were released. - */ - public boolean releaseAll() { - boolean releasedAll = true; - int size = this.size; - for (int i = 0; i < size; i ++) { - releasedAll &= ReferenceCountUtil.release(elements[i]); - } - return releasedAll; - } - - /** - * Call {@link ReferenceCountUtil#release(Object, int)} on all messages in this {@link MessageList} and return - * {@code true} if all messages were released. - */ - public boolean releaseAll(int decrement) { - boolean releasedAll = true; - int size = this.size; - for (int i = 0; i < size; i ++) { - releasedAll &= ReferenceCountUtil.release(elements[i], decrement); - } - return releasedAll; - } - - /** - * Short-cut for calling {@link #releaseAll()} and {@link #recycle()}. Returns {@code true} if both return - * {@code true}. - */ - public boolean releaseAllAndRecycle() { - return releaseAll() && recycle(); - } - - /** - * Short-cut for calling {@link #releaseAll(int)} and {@link #recycle()}. Returns {@code true} if both return - * {@code true}. - */ - public boolean releaseAllAndRecycle(int decrement) { - return releaseAll(decrement) && recycle(); - } - - /** - * Clear and recycle this instance. - */ - public boolean recycle() { - clear(); - return RECYCLER.recycle(this, handle); - } - private final Handle handle; - private T[] elements; + private Object[] elements; private int size; - private int modifications; - private boolean byteBufsOnly = true; MessageList(Handle handle) { this(handle, DEFAULT_INITIAL_CAPACITY); @@ -210,357 +55,52 @@ final class MessageList implements Iterable { MessageList(Handle handle, int initialCapacity) { this.handle = handle; initialCapacity = normalizeCapacity(initialCapacity); - elements = newArray(initialCapacity); - } - - private MessageList(Handle handle, T[] elements, int size) { - this.handle = handle; - this.elements = elements; - this.size = size; + elements = new Object[initialCapacity]; } /** * Return the current size of this {@link MessageList} and so how many messages it holds. */ - public int size() { + int size() { return size; } /** * Return {@code true} if this {@link MessageList} is empty and so contains no messages. */ - public boolean isEmpty() { + boolean isEmpty() { return size == 0; } - /** - * Return the message on the given index. This method will throw an {@link IndexOutOfBoundsException} if there is - * no message stored in the given index. - */ - public T get(int index) { - checkIndex(index); - return elements[index]; - } - - /** - * Returns the first message in this list. - * - * @throws NoSuchElementException if this list is empty - */ - public T first() { - if (size != 0) { - return elements[0]; - } else { - throw new NoSuchElementException(); - } - } - - /** - * Returns the last message in this list. - * - * @throws NoSuchElementException if this list is empty - */ - public T last() { - if (size != 0) { - return elements[size - 1]; - } else { - throw new NoSuchElementException(); - } - } - - /** - * Sets the message on the given index. - */ - public MessageList set(int index, T value) { - checkIndex(index); - if (value == null) { - throw new NullPointerException("value"); - } - - elements[index] = value; - - if (byteBufsOnly && !(value instanceof ByteBuf)) { - byteBufsOnly = false; - } - - return this; - } - /** * Add the message to this {@link MessageList} and return itself. */ - public MessageList add(T value) { + MessageList add(Object value) { if (value == null) { throw new NullPointerException("value"); } - modifications ++; int oldSize = size; int newSize = oldSize + 1; ensureCapacity(newSize); elements[oldSize] = value; size = newSize; - if (byteBufsOnly && !(value instanceof ByteBuf)) { - byteBufsOnly = false; - } return this; } /** - * Add the messages contained in the array to this {@link MessageList} and return itself. + * Returns the backing array of this list. */ - public MessageList add(T[] src) { - if (src == null) { - throw new NullPointerException("src"); - } - return add(src, 0, src.length); - } - - /** - * Add the messages contained in the array, using the given src index and src length, to this {@link MessageList} - * and return itself. - */ - public MessageList add(T[] src, int srcIdx, int srcLen) { - if (src == null) { - throw new NullPointerException("src"); - } - - modifications ++; - - int dstIdx = size; - final int newSize = dstIdx + srcLen; - ensureCapacity(newSize); - - final int srcEndIdx = srcIdx + srcLen; - int i = srcIdx; - try { - if (byteBufsOnly) { - while (i < srcEndIdx) { - T m = src[i]; - if (m == null) { - throw new NullPointerException("src[" + srcIdx + ']'); - } - - elements[dstIdx ++] = m; - i ++; - - if (!(m instanceof ByteBuf)) { - byteBufsOnly = false; - break; - } - } - } - - for (; i < srcEndIdx; i ++) { - T m = src[i]; - if (m == null) { - throw new NullPointerException("src[" + srcIdx + ']'); - } - - elements[dstIdx ++] = m; - } - } finally { - if (dstIdx != newSize) { - // Could not finish iteration. - Arrays.fill(elements, size, dstIdx, null); - } - } - - assert dstIdx == newSize : String.format("dstIdx(%d) != newSize(%d)", dstIdx, newSize); - size = newSize; - - return this; - } - - /** - * Add the messages contained in the given {@link MessageList} to this {@link MessageList} and return itself. - */ - public MessageList add(MessageList src) { - return add(src, 0, src.size()); - } - - /** - * Add the messages contained in the given {@link MessageList}, using the given src index and src length, to this - * {@link MessageList} and return itself. - */ - public MessageList add(MessageList src, int srcIdx, int srcLen) { - if (src == null) { - throw new NullPointerException("src"); - } - - if (srcIdx > src.size - srcLen) { - throw new IndexOutOfBoundsException(String.format( - "srcIdx(%d) + srcLen(%d) > src.size(%d)", srcIdx, srcLen, src.size)); - } - - modifications ++; - - final int dstIdx = size; - final int newSize = dstIdx + srcLen; - ensureCapacity(newSize); - - byteBufsOnly &= src.byteBufsOnly; - System.arraycopy(src.elements, srcIdx, elements, dstIdx, srcLen); - - size = newSize; - return this; - } - - /** - * Clear all messages and return itself. - */ - public MessageList clear() { - modifications ++; - Arrays.fill(elements, 0, size, null); - byteBufsOnly = true; - size = 0; - return this; - } - - /** - * Create a new copy all messages of this {@link MessageList} and return it. - */ - public MessageList copy() { - return new MessageList(handle, elements.clone(), size); - } - - /** - * Create a new copy all messages of this {@link MessageList}, starting at the given index and using the given len, - * and return it. - */ - public MessageList copy(int index, int length) { - checkRange(index, length); - MessageList copy = new MessageList(handle, length); - System.arraycopy(elements, index, copy.elements, 0, length); - copy.size = length; - return copy; - } - - /** - * Casts the type parameter of this list to a different type parameter. This method is often useful when you have - * to deal with multiple messages and do not want to down-cast the messages every time you access the list. - * - *
    -     * public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) {
    -     *     MessageList<MyMessage> cast = msgs.cast();
    -     *     for (MyMessage m: cast) { // or: for (MyMessage m: msgs.<MyMessage>cast())
    -     *         ...
    -     *     }
    -     * }
    -     * 
    - */ - @SuppressWarnings("unchecked") - public MessageList cast() { - return (MessageList) this; - } - - /** - * Iterates over the messages in this list with the specified {@code processor}. - * - * @return {@code -1} if the processor iterated to or beyond the end of the readable bytes. - * The last-visited index If the {@link MessageListProcessor#process(Object)} returned {@code false}. - */ - public int forEach(MessageListProcessor proc) { - if (proc == null) { - throw new NullPointerException("proc"); - } - - final int size = this.size; - if (size == 0) { - return -1; - } - - @SuppressWarnings("unchecked") - MessageListProcessor p = (MessageListProcessor) proc; - - int i = 0; - try { - do { - if (p.process(elements[i])) { - i ++; - } else { - return i; - } - } while (i < size); - } catch (Exception e) { - PlatformDependent.throwException(e); - } - - return -1; - } - - /** - * Iterates over the messages in this list with the specified {@code processor}. - * - * @return {@code -1} if the processor iterated to or beyond the end of the specified area. - * The last-visited index If the {@link MessageListProcessor#process(Object)} returned {@code false}. - */ - public int forEach(int index, int length, MessageListProcessor proc) { - checkRange(index, length); - if (proc == null) { - throw new NullPointerException("proc"); - } - - if (size == 0) { - return -1; - } - - @SuppressWarnings("unchecked") - MessageListProcessor p = (MessageListProcessor) proc; - - final int end = index + length; - - int i = index; - try { - do { - if (p.process(elements[i])) { - i ++; - } else { - return i; - } - } while (i < end); - } catch (Exception e) { - PlatformDependent.throwException(e); - } - - return -1; - } - - @Override - public Iterator iterator() { - return new MessageListIterator(); - } - - /** - * Returns the backing array of this list. Use this array when you want to iterate over the list fast: - *
    -     * {@link MessageList} list = ...;
    -     * for (Object m: list.array()) {
    -     *     if (m == null) {
    -     *         break;
    -     *     }
    -     *
    -     *     handleMessage(m);
    -     * }
    -     * 
    - */ - public T[] array() { + Object[] array() { return elements; } /** - * Returns {@code true} if all messages contained in this {@link MessageList} are assignment-compatible with the - * object represented by this {@link Class}. + * Clear and recycle this instance. */ - public boolean containsOnly(Class clazz) { - if (clazz == ByteBuf.class) { - return byteBufsOnly; - } - for (int i = 0; i < size; i++) { - if (!clazz.isInstance(elements[i])) { - return false; - } - } - return true; + boolean recycle() { + Arrays.fill(elements, 0, size, null); + size = 0; + return RECYCLER.recycle(this, handle); } private void ensureCapacity(int capacity) { @@ -568,7 +108,7 @@ final class MessageList implements Iterable { return; } - T[] newElements = newArray(normalizeCapacity(capacity)); + Object[] newElements = new Object[normalizeCapacity(capacity)]; System.arraycopy(elements, 0, newElements, 0, size); elements = newElements; } @@ -590,55 +130,4 @@ final class MessageList implements Iterable { } return initialCapacity; } - - @SuppressWarnings({ "unchecked", "SuspiciousArrayCast" }) - private T[] newArray(int initialCapacity) { - return (T[]) new Object[initialCapacity]; - } - - private void checkIndex(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); - } - } - - private final class MessageListIterator implements Iterator { - - private final int expectedModifications = modifications; - private int index; - - private void checkConcurrentModifications() { - if (expectedModifications != modifications) { - throw new ConcurrentModificationException(); - } - if (index > size) { - throw new ConcurrentModificationException(); - } - } - - @Override - public boolean hasNext() { - return index < size; - } - - @Override - public T next() { - checkConcurrentModifications(); - if (hasNext()) { - return elements[index ++]; - } - throw new NoSuchElementException(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - } } diff --git a/transport/src/main/java/io/netty/channel/MessageListProcessor.java b/transport/src/main/java/io/netty/channel/MessageListProcessor.java deleted file mode 100644 index bfcdb91f7b..0000000000 --- a/transport/src/main/java/io/netty/channel/MessageListProcessor.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2013 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.netty.channel; - -public interface MessageListProcessor { - - /** - * @return {@code true} if the processor wants to continue the loop and handle the next message in the list. - * {@code false} if the processor wants to stop handling messages and abort the loop. - */ - boolean process(T value) throws Exception; -} diff --git a/transport/src/main/java/io/netty/channel/SimpleChannelInboundHandler.java b/transport/src/main/java/io/netty/channel/SimpleChannelInboundHandler.java index 6808243861..23c2ad8eb4 100644 --- a/transport/src/main/java/io/netty/channel/SimpleChannelInboundHandler.java +++ b/transport/src/main/java/io/netty/channel/SimpleChannelInboundHandler.java @@ -64,15 +64,16 @@ public abstract class SimpleChannelInboundHandler extends ChannelInboundHandl } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { boolean release = true; try { if (acceptInboundMessage(msg)) { + @SuppressWarnings("unchecked") I imsg = (I) msg; - messageReceived0(ctx, imsg); + channelRead0(ctx, imsg); } else { release = false; - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } } finally { if (autoRelease && release) { @@ -89,5 +90,5 @@ public abstract class SimpleChannelInboundHandler extends ChannelInboundHandl * @param msg the message to handle * @throws Exception is thrown if an error accour */ - protected abstract void messageReceived0(ChannelHandlerContext ctx, I msg) throws Exception; + protected abstract void channelRead0(ChannelHandlerContext ctx, I msg) throws Exception; } diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java index de1c77e5f8..1f4def07be 100755 --- a/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java +++ b/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java @@ -147,9 +147,9 @@ public class EmbeddedChannel extends AbstractChannel { ChannelPipeline p = pipeline(); for (Object m: msgs) { - p.fireMessageReceived(m); + p.fireChannelRead(m); } - p.fireMessageReceivedLast(); + p.fireChannelReadComplete(); runPendingTasks(); checkException(); return !lastInboundBuffer.isEmpty(); @@ -311,7 +311,7 @@ public class EmbeddedChannel extends AbstractChannel { private final class LastInboundHandler extends ChannelInboundHandlerAdapter { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { lastInboundBuffer.add(msg); } diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannel.java b/transport/src/main/java/io/netty/channel/local/LocalChannel.java index 87b44cdee6..13d690c824 100755 --- a/transport/src/main/java/io/netty/channel/local/LocalChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannel.java @@ -61,10 +61,9 @@ public class LocalChannel extends AbstractChannel { if (m == null) { break; } - pipeline.fireMessageReceived(m); + pipeline.fireChannelRead(m); } - pipeline.fireMessageReceivedLast(); - pipeline.fireChannelReadSuspended(); + pipeline.fireChannelReadComplete(); } }; @@ -254,10 +253,9 @@ public class LocalChannel extends AbstractChannel { if (received == null) { break; } - pipeline.fireMessageReceived(received); + pipeline.fireChannelRead(received); } - pipeline.fireMessageReceivedLast(); - pipeline.fireChannelReadSuspended(); + pipeline.fireChannelReadComplete(); } finally { READER_STACK_DEPTH.set(stackDepth); } @@ -311,10 +309,9 @@ public class LocalChannel extends AbstractChannel { if (received == null) { break; } - peerPipeline.fireMessageReceived(received); + peerPipeline.fireChannelRead(received); } - peerPipeline.fireMessageReceivedLast(); - peerPipeline.fireChannelReadSuspended(); + peerPipeline.fireChannelReadComplete(); } } diff --git a/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java b/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java index 26aa4ce258..7f279cf440 100755 --- a/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java @@ -135,10 +135,9 @@ public class LocalServerChannel extends AbstractServerChannel { if (m == null) { break; } - pipeline.fireMessageReceived(m); + pipeline.fireChannelRead(m); } - pipeline.fireMessageReceivedLast(); - pipeline.fireChannelReadSuspended(); + pipeline.fireChannelReadComplete(); } LocalChannel serve(final LocalChannel peer) { @@ -158,10 +157,9 @@ public class LocalServerChannel extends AbstractServerChannel { if (m == null) { break; } - pipeline.fireMessageReceived(m); + pipeline.fireChannelRead(m); } - pipeline.fireMessageReceivedLast(); - pipeline.fireChannelReadSuspended(); + pipeline.fireChannelReadComplete(); } } else { eventLoop().execute(new Runnable() { diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java index 5f9abfc163..88711953cb 100755 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java @@ -96,7 +96,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { break; } - pipeline.fireMessageReceived(byteBuf); + pipeline.fireChannelRead(byteBuf); allocHandle.record(localReadAmount); byteBuf = null; if (++ messages == maxMessagesPerRead) { @@ -108,15 +108,13 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { } finally { if (byteBuf != null) { if (byteBuf.isReadable()) { - pipeline.fireMessageReceived(byteBuf); + pipeline.fireChannelRead(byteBuf); } else { byteBuf.release(); } } - if (messages != 0) { - pipeline.fireMessageReceivedLast(); - } + pipeline.fireChannelReadComplete(); if (exception != null) { if (exception instanceof IOException) { @@ -136,8 +134,6 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { close(voidPromise()); } } - } else { - pipeline.fireChannelReadSuspended(); } } } diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java index 9ff6837828..c26ad72e8c 100755 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java @@ -84,10 +84,10 @@ public abstract class AbstractNioMessageChannel extends AbstractNioChannel { } for (int i = 0; i < readBuf.size(); i ++) { - pipeline.fireMessageReceived(readBuf.get(i)); + pipeline.fireChannelRead(readBuf.get(i)); } readBuf.clear(); - pipeline.fireMessageReceivedLast(); + pipeline.fireChannelReadComplete(); if (exception != null) { if (exception instanceof IOException) { @@ -101,8 +101,6 @@ public abstract class AbstractNioMessageChannel extends AbstractNioChannel { if (isOpen()) { close(voidPromise()); } - } else { - pipeline.fireChannelReadSuspended(); } } } @@ -126,10 +124,8 @@ public abstract class AbstractNioMessageChannel extends AbstractNioChannel { /** * Write messages to the underlying {@link java.nio.channels.Channel}. - * @param msg Object to write * @param lastSpin {@code true} if this is the last write try - * @return written the amount of written messages - * @throws Exception thrown if an error accour + * @return the number of written messages */ protected abstract int doWriteMessages( Object[] msgs, int msgLength, int startIndex, boolean lastSpin) throws Exception; diff --git a/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java b/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java index e29e9b40ba..185b1ebcb5 100755 --- a/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java @@ -78,15 +78,12 @@ public abstract class AbstractOioByteChannel extends AbstractOioChannel { ByteBuf byteBuf = alloc().buffer(); boolean closed = false; boolean read = false; - boolean firedInboundBufferSuspeneded = false; Throwable exception = null; - boolean readMessage = false; try { for (;;) { int localReadAmount = doReadBytes(byteBuf); if (localReadAmount > 0) { read = true; - readMessage = true; } else if (localReadAmount < 0) { closed = true; } @@ -102,7 +99,7 @@ public abstract class AbstractOioByteChannel extends AbstractOioChannel { if (capacity == maxCapacity) { if (read) { read = false; - pipeline.fireMessageReceived(byteBuf); + pipeline.fireChannelRead(byteBuf); byteBuf = alloc().buffer(); } } else { @@ -124,21 +121,18 @@ public abstract class AbstractOioByteChannel extends AbstractOioChannel { exception = t; } finally { if (read) { - pipeline.fireMessageReceived(byteBuf); + pipeline.fireChannelRead(byteBuf); } else { // nothing read into the buffer so release it byteBuf.release(); } - if (readMessage) { - pipeline.fireMessageReceivedLast(); - } + + pipeline.fireChannelReadComplete(); if (exception != null) { if (exception instanceof IOException) { closed = true; pipeline().fireExceptionCaught(exception); } else { - firedInboundBufferSuspeneded = true; - pipeline.fireChannelReadSuspended(); pipeline.fireExceptionCaught(exception); unsafe().close(voidPromise()); } @@ -153,8 +147,6 @@ public abstract class AbstractOioByteChannel extends AbstractOioChannel { unsafe().close(unsafe().voidPromise()); } } - } else if (!firedInboundBufferSuspeneded) { - pipeline.fireChannelReadSuspended(); } } } diff --git a/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java b/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java index 9bef3d7a58..9e1337d187 100755 --- a/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java +++ b/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java @@ -48,10 +48,10 @@ public abstract class AbstractOioMessageChannel extends AbstractOioChannel { } for (int i = 0; i < readBuf.size(); i ++) { - pipeline.fireMessageReceived(readBuf.get(i)); + pipeline.fireChannelRead(readBuf.get(i)); } readBuf.clear(); - pipeline.fireMessageReceivedLast(); + pipeline.fireChannelReadComplete(); if (exception != null) { if (exception instanceof IOException) { @@ -65,8 +65,6 @@ public abstract class AbstractOioMessageChannel extends AbstractOioChannel { if (isOpen()) { unsafe().close(unsafe().voidPromise()); } - } else { - pipeline.fireChannelReadSuspended(); } } diff --git a/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java b/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java index 8e29ea176d..e87934e0e3 100644 --- a/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java +++ b/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java @@ -64,7 +64,7 @@ public abstract class AbstractEventLoopTest { private static final class TestChannelHandler2 extends ChannelDuplexHandler { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { } + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { } } protected abstract EventLoopGroup newEventLoopGroup(); diff --git a/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java b/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java index db464f7e33..a9bae244df 100644 --- a/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java +++ b/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java @@ -29,9 +29,11 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Test; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -61,7 +63,7 @@ public class DefaultChannelPipelineTest { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ReferenceCountUtil.release(msg); } }); @@ -145,10 +147,10 @@ public class DefaultChannelPipelineTest { boolean called; @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { called = true; if (!(msg instanceof String)) { - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } } } @@ -332,11 +334,11 @@ public class DefaultChannelPipelineTest { public void run() { ChannelPipeline p = self.pipeline(); handler1.inboundBuffer.add(8); - assertEquals(8, handler1.inboundBuffer.first()); + assertEquals(8, handler1.inboundBuffer.peek()); assertTrue(handler2.inboundBuffer.isEmpty()); p.remove(handler1); assertEquals(1, handler2.inboundBuffer.size()); - assertEquals(8, handler2.inboundBuffer.first()); + assertEquals(8, handler2.inboundBuffer.peek()); } }).sync(); } @@ -353,11 +355,11 @@ public class DefaultChannelPipelineTest { public void run() { ChannelPipeline p = self.pipeline(); handler2.outboundBuffer.add(8); - assertEquals(8, handler2.outboundBuffer.first()); + assertEquals(8, handler2.outboundBuffer.peek()); assertTrue(handler1.outboundBuffer.isEmpty()); p.remove(handler2); assertEquals(1, handler1.outboundBuffer.size()); - assertEquals(8, handler1.outboundBuffer.first()); + assertEquals(8, handler1.outboundBuffer.peek()); } }).sync(); } @@ -374,10 +376,10 @@ public class DefaultChannelPipelineTest { public void run() { ChannelPipeline p = self.pipeline(); handler1.outboundBuffer.add(8); - assertEquals(8, handler1.outboundBuffer.first()); + assertEquals(8, handler1.outboundBuffer.peek()); assertTrue(handler2.outboundBuffer.isEmpty()); p.replace(handler1, "handler2", handler2); - assertEquals(8, handler2.outboundBuffer.first()); + assertEquals(8, handler2.outboundBuffer.peek()); } }).sync(); } @@ -396,14 +398,14 @@ public class DefaultChannelPipelineTest { handler1.inboundBuffer.add(8); handler1.outboundBuffer.add(8); - assertEquals(8, handler1.inboundBuffer.first()); - assertEquals(8, handler1.outboundBuffer.first()); + assertEquals(8, handler1.inboundBuffer.peek()); + assertEquals(8, handler1.outboundBuffer.peek()); assertTrue(handler2.inboundBuffer.isEmpty()); assertTrue(handler2.outboundBuffer.isEmpty()); p.replace(handler1, "handler2", handler2); - assertEquals(8, handler2.outboundBuffer.first()); - assertEquals(8, handler2.inboundBuffer.first()); + assertEquals(8, handler2.outboundBuffer.peek()); + assertEquals(8, handler2.inboundBuffer.peek()); } }).sync(); } @@ -423,15 +425,15 @@ public class DefaultChannelPipelineTest { handler2.inboundBuffer.add(8); handler2.outboundBuffer.add(8); - assertEquals(8, handler2.inboundBuffer.first()); - assertEquals(8, handler2.outboundBuffer.first()); + assertEquals(8, handler2.inboundBuffer.peek()); + assertEquals(8, handler2.outboundBuffer.peek()); assertEquals(0, handler1.outboundBuffer.size()); assertEquals(0, handler3.inboundBuffer.size()); p.remove(handler2); - assertEquals(8, handler3.inboundBuffer.first()); - assertEquals(8, handler1.outboundBuffer.first()); + assertEquals(8, handler3.inboundBuffer.peek()); + assertEquals(8, handler1.outboundBuffer.peek()); } }).sync(); } @@ -482,8 +484,8 @@ public class DefaultChannelPipelineTest { private static class TestHandler extends ChannelDuplexHandler { } private static class BufferedTestHandler extends ChannelDuplexHandler { - final MessageList inboundBuffer = MessageList.newInstance(); - final MessageList outboundBuffer = MessageList.newInstance(); + final Queue inboundBuffer = new ArrayDeque(); + final Queue outboundBuffer = new ArrayDeque(); @Override public void write(ChannelHandlerContext ctx, Object msg) throws Exception { @@ -491,7 +493,7 @@ public class DefaultChannelPipelineTest { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { inboundBuffer.add(msg); } @@ -499,10 +501,9 @@ public class DefaultChannelPipelineTest { public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { if (!inboundBuffer.isEmpty()) { for (Object o: inboundBuffer) { - ctx.fireMessageReceived(o); + ctx.fireChannelRead(o); } - ctx.fireMessageReceivedLast(); - inboundBuffer.recycle(); + ctx.fireChannelReadComplete(); } if (!outboundBuffer.isEmpty()) { for (Object o: outboundBuffer) { diff --git a/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java b/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java index 4f3d1c69a0..c6206255dc 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java +++ b/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java @@ -15,11 +15,6 @@ */ package io.netty.channel.local; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.AbstractChannel; @@ -30,11 +25,13 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; +import org.junit.Test; import java.nio.channels.ClosedChannelException; import java.util.concurrent.CountDownLatch; -import org.junit.Test; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; public class LocalChannelTest { @@ -74,7 +71,7 @@ public class LocalChannelTest { @Override public void run() { // Send a message event up the pipeline. - cc.pipeline().fireMessageReceived("Hello, World"); + cc.pipeline().fireChannelRead("Hello, World"); latch.countDown(); } }); @@ -145,7 +142,7 @@ public class LocalChannelTest { static class TestHandler extends ChannelInboundHandlerAdapter { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { logger.info(String.format("Received mesage: %s", msg)); } } diff --git a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java index 317761356a..bdae50917e 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java +++ b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java @@ -27,6 +27,11 @@ import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.EventExecutorGroup; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; import java.util.HashSet; import java.util.Queue; @@ -34,12 +39,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicReference; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - public class LocalTransportThreadModelTest { private static EventLoopGroup group; @@ -57,7 +56,7 @@ public class LocalTransportThreadModelTest { public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) { + public void channelRead(ChannelHandlerContext ctx, Object msg) { // Discard ReferenceCountUtil.release(msg); } @@ -101,10 +100,10 @@ public class LocalTransportThreadModelTest { l.register(ch).sync().channel().connect(localAddr).sync(); // Fire inbound events from all possible starting points. - ch.pipeline().fireMessageReceived("1"); - ch.pipeline().context(h1).fireMessageReceived("2"); - ch.pipeline().context(h2).fireMessageReceived("3"); - ch.pipeline().context(h3).fireMessageReceived("4"); + ch.pipeline().fireChannelRead("1"); + ch.pipeline().context(h1).fireChannelRead("2"); + ch.pipeline().context(h2).fireChannelRead("3"); + ch.pipeline().context(h3).fireChannelRead("4"); // Fire outbound events from all possible starting points. ch.pipeline().write("5"); ch.pipeline().context(h3).write("6"); @@ -266,7 +265,7 @@ public class LocalTransportThreadModelTest { @Override public void run() { for (int j = start; j < end; j ++) { - ch.pipeline().fireMessageReceived(Integer.valueOf(j)); + ch.pipeline().fireChannelRead(Integer.valueOf(j)); } } }); @@ -366,9 +365,9 @@ public class LocalTransportThreadModelTest { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { inboundThreadNames.add(Thread.currentThread().getName()); - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } @Override @@ -397,7 +396,7 @@ public class LocalTransportThreadModelTest { private volatile Thread t; @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Thread t = this.t; if (t == null) { this.t = Thread.currentThread(); @@ -411,7 +410,7 @@ public class LocalTransportThreadModelTest { Assert.assertEquals(expected, m); out.writeInt(m); - ctx.fireMessageReceived(out); + ctx.fireChannelRead(out); } @Override @@ -454,7 +453,7 @@ public class LocalTransportThreadModelTest { private volatile Thread t; @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Thread t = this.t; if (t == null) { this.t = Thread.currentThread(); @@ -468,7 +467,7 @@ public class LocalTransportThreadModelTest { int actual = m.readInt(); int expected = inCnt ++; Assert.assertEquals(expected, actual); - ctx.fireMessageReceived(actual); + ctx.fireChannelRead(actual); } m.release(); } @@ -506,7 +505,7 @@ public class LocalTransportThreadModelTest { private volatile Thread t; @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Thread t = this.t; if (t == null) { this.t = Thread.currentThread(); @@ -518,7 +517,7 @@ public class LocalTransportThreadModelTest { int expected = inCnt ++; Assert.assertEquals(expected, actual); - ctx.fireMessageReceived(msg); + ctx.fireChannelRead(msg); } @Override @@ -552,7 +551,7 @@ public class LocalTransportThreadModelTest { private volatile Thread t; @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Thread t = this.t; if (t == null) { this.t = Thread.currentThread(); diff --git a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java index dd38925418..95c447c677 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java +++ b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java @@ -15,7 +15,6 @@ */ package io.netty.channel.local; -import static org.junit.Assert.assertEquals; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; @@ -24,10 +23,11 @@ import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; +import org.junit.Test; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; +import static org.junit.Assert.*; public class LocalTransportThreadModelTest2 { @@ -113,7 +113,7 @@ public class LocalTransportThreadModelTest2 { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { count.incrementAndGet(); ReferenceCountUtil.release(msg); } diff --git a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest3.java b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest3.java index 540dbe9801..68024a82a7 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest3.java +++ b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest3.java @@ -27,6 +27,11 @@ import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.EventExecutorGroup; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; import java.util.Deque; import java.util.LinkedList; @@ -35,18 +40,12 @@ import java.util.Random; import java.util.UUID; import java.util.concurrent.ConcurrentLinkedDeque; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - public class LocalTransportThreadModelTest3 { enum EventType { EXCEPTION_CAUGHT, USER_EVENT, - READ_SUSPEND, + MESSAGE_RECEIVED_LAST, INACTIVE, ACTIVE, UNREGISTERED, @@ -71,7 +70,7 @@ public class LocalTransportThreadModelTest3 { public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) { + public void channelRead(ChannelHandlerContext ctx, Object msg) { // Discard ReferenceCountUtil.release(msg); } @@ -179,10 +178,10 @@ public class LocalTransportThreadModelTest3 { ch.pipeline().fireExceptionCaught(cause); break; case MESSAGE_RECEIVED: - ch.pipeline().fireMessageReceived(""); + ch.pipeline().fireChannelRead(""); break; - case READ_SUSPEND: - ch.pipeline().fireChannelReadSuspended(); + case MESSAGE_RECEIVED_LAST: + ch.pipeline().fireChannelReadComplete(); break; case USER_EVENT: ch.pipeline().fireUserEventTriggered(""); @@ -236,7 +235,7 @@ public class LocalTransportThreadModelTest3 { EventType[] events; if (inbound) { events = new EventType[] { - EventType.USER_EVENT, EventType.MESSAGE_RECEIVED, EventType.READ_SUSPEND, + EventType.USER_EVENT, EventType.MESSAGE_RECEIVED, EventType.MESSAGE_RECEIVED_LAST, EventType.EXCEPTION_CAUGHT}; } else { events = new EventType[] { @@ -276,9 +275,9 @@ public class LocalTransportThreadModelTest3 { } @Override - public void channelReadSuspended(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { if (inbound) { - events.add(EventType.READ_SUSPEND); + events.add(EventType.MESSAGE_RECEIVED_LAST); } } @@ -303,7 +302,7 @@ public class LocalTransportThreadModelTest3 { } @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (inbound) { events.add(EventType.MESSAGE_RECEIVED); } diff --git a/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java b/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java index fd1e4ef226..343bd1920e 100644 --- a/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java +++ b/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java @@ -24,12 +24,11 @@ import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.GlobalEventExecutor; - -import java.net.InetSocketAddress; - import org.junit.Assert; import org.junit.Test; +import java.net.InetSocketAddress; + public class NioDatagramChannelTest { @@ -47,7 +46,7 @@ public class NioDatagramChannelTest { .option(ChannelOption.SO_BROADCAST, true) .handler(new ChannelInboundHandlerAdapter() { @Override - public void messageReceived(ChannelHandlerContext ctx, Object msg) { + public void channelRead(ChannelHandlerContext ctx, Object msg) { // Discard ReferenceCountUtil.release(msg); }