Rename SimpleChannelInboundHandler.channelRead0() to messageReceived()

- Related: #1590
This commit is contained in:
Trustin Lee 2013-11-02 19:59:21 +09:00
parent 81243c1524
commit 9d611a182f
48 changed files with 64 additions and 58 deletions

View File

@ -75,7 +75,7 @@ public class AppletDiscardServer extends JApplet {
private static final class DiscardServerHandler extends SimpleChannelInboundHandler<ByteBuf> {
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
System.out.println("Received: " + msg.toString(CharsetUtil.UTF_8));
}

View File

@ -62,7 +62,7 @@ public class DiscardClientHandler extends SimpleChannelInboundHandler<Object> {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
// Server is supposed to send nothing, but if it sends something, discard it.
}

View File

@ -30,7 +30,7 @@ public class DiscardServerHandler extends SimpleChannelInboundHandler<Object> {
DiscardServerHandler.class.getName());
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
// discard
}

View File

@ -70,7 +70,7 @@ public class FactorialClientHandler extends SimpleChannelInboundHandler<BigInteg
}
@Override
public void channelRead0(ChannelHandlerContext ctx, final BigInteger msg) {
public void messageReceived(ChannelHandlerContext ctx, final BigInteger msg) {
receivedMessages ++;
if (receivedMessages == count) {
// Offer the answer after closing the connection.

View File

@ -39,7 +39,7 @@ public class FactorialServerHandler extends SimpleChannelInboundHandler<BigInteg
private BigInteger factorial = new BigInteger("1");
@Override
public void channelRead0(ChannelHandlerContext ctx, BigInteger msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, BigInteger msg) throws Exception {
// Calculate the cumulative factorial and send it to the client.
lastMultiplier = msg;
factorial = factorial.multiply(msg);

View File

@ -93,7 +93,7 @@ public class FileServer {
private static final class FileHandler extends SimpleChannelInboundHandler<String> {
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
File file = new File(msg);
if (file.exists()) {
if (!file.isFile()) {

View File

@ -114,7 +114,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
}
@Override
public void channelRead0(
public void messageReceived(
ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
if (!request.getDecoderResult().isSuccess()) {
sendError(ctx, BAD_REQUEST);

View File

@ -27,7 +27,7 @@ import io.netty.util.CharsetUtil;
public class HttpSnoopClientHandler extends SimpleChannelInboundHandler<HttpObject> {
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;

View File

@ -55,7 +55,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
protected void messageReceived(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpRequest) {
HttpRequest request = this.request = (HttpRequest) msg;

View File

@ -36,7 +36,7 @@ public class HttpUploadClientHandler extends SimpleChannelInboundHandler<HttpObj
private boolean readingChunks;
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;

View File

@ -95,7 +95,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
}
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpRequest) {
HttpRequest request = this.request = (HttpRequest) msg;
URI uri = new URI(request.getUri());

View File

@ -79,7 +79,7 @@ public class WebSocketClientHandler extends SimpleChannelInboundHandler<Object>
}
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);

View File

@ -21,7 +21,7 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
public class CustomTextFrameHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame frame) throws Exception {
protected void messageReceived(ChannelHandlerContext ctx, TextWebSocketFrame frame) throws Exception {
String request = frame.text();
ctx.channel().writeAndFlush(new TextWebSocketFrame(request.toUpperCase()));
}

View File

@ -53,7 +53,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
private WebSocketServerHandshaker handshaker;
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof FullHttpRequest) {
handleHttpRequest(ctx, (FullHttpRequest) msg);
} else if (msg instanceof WebSocketFrame) {

View File

@ -54,7 +54,7 @@ public class WebSocketSslServerHandler extends SimpleChannelInboundHandler<Objec
private WebSocketServerHandshaker handshaker;
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof FullHttpRequest) {
handleHttpRequest(ctx, (FullHttpRequest) msg);
} else if (msg instanceof WebSocketFrame) {

View File

@ -21,7 +21,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
public class LocalEchoClientHandler extends SimpleChannelInboundHandler<Object> {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
// Print as received
System.out.println(msg);
}

View File

@ -23,7 +23,7 @@ import io.netty.util.CharsetUtil;
public class QuoteOfTheMomentClientHandler extends SimpleChannelInboundHandler<DatagramPacket> {
@Override
public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
public void messageReceived(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));

View File

@ -44,7 +44,7 @@ public class QuoteOfTheMomentServerHandler extends SimpleChannelInboundHandler<D
}
@Override
public void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
System.err.println(packet);
if ("QOTM?".equals(packet.content().toString(CharsetUtil.UTF_8))) {
ctx.write(new DatagramPacket(

View File

@ -26,7 +26,7 @@ public class RxtxClientHandler extends SimpleChannelInboundHandler<String> {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
if ("OK".equals(msg)) {
System.out.println("Serial port responded to AT");
} else {

View File

@ -30,7 +30,7 @@ public class SecureChatClientHandler extends SimpleChannelInboundHandler<String>
SecureChatClientHandler.class.getName());
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
System.err.println(msg);
}

View File

@ -61,7 +61,7 @@ public class SecureChatServerHandler extends SimpleChannelInboundHandler<String>
}
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
public void messageReceived(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()) {

View File

@ -42,8 +42,8 @@ public final class SocksServerConnectHandler extends SimpleChannelInboundHandler
private final Bootstrap b = new Bootstrap();
@Override
public void channelRead0(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception {
Promise promise = ctx.executor().newPromise();
public void messageReceived(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception {
Promise<Channel> promise = ctx.executor().newPromise();
promise.addListener(
new GenericFutureListener<Future<Channel>>() {
@Override

View File

@ -37,7 +37,7 @@ public final class SocksServerHandler extends SimpleChannelInboundHandler<SocksR
}
@Override
public void channelRead0(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
switch (socksRequest.requestType()) {
case INIT: {
// auth support example

View File

@ -31,7 +31,7 @@ public class TelnetClientHandler extends SimpleChannelInboundHandler<String> {
private static final Logger logger = Logger.getLogger(TelnetClientHandler.class.getName());
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
protected void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
System.err.println(msg);
}

View File

@ -44,7 +44,7 @@ public class TelnetServerHandler extends SimpleChannelInboundHandler<String> {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, String request) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, String request) throws Exception {
// Generate and write a response.
String response;

View File

@ -58,7 +58,7 @@ public class ByteEchoClientHandler extends SimpleChannelInboundHandler<ByteBuf>
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
meter.mark(msg.readableBytes());
ctx.write(msg);

View File

@ -65,7 +65,7 @@ public class MsgEchoClientHandler extends SimpleChannelInboundHandler<UdtMessage
}
@Override
public void channelRead0(ChannelHandlerContext ctx, UdtMessage msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, UdtMessage msg) throws Exception {
meter.mark(msg.content().readableBytes());
ctx.write(msg);

View File

@ -66,7 +66,7 @@ public class MsgEchoPeerHandler extends
}
@Override
public void channelRead0(ChannelHandlerContext ctx, UdtMessage message) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, UdtMessage message) throws Exception {
meter.mark(message.content().readableBytes());
ctx.write(message);

View File

@ -60,7 +60,7 @@ public class ByteEchoPeerHandler extends SimpleChannelInboundHandler<ByteBuf> {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
meter.mark(buf.readableBytes());
ctx.write(buf);

View File

@ -49,7 +49,7 @@ public class UptimeClientHandler extends SimpleChannelInboundHandler<Object> {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
// Discard received data
}

View File

@ -99,7 +99,7 @@ public class WorldClockClientHandler extends SimpleChannelInboundHandler<LocalTi
}
@Override
public void channelRead0(ChannelHandlerContext ctx, LocalTimes times) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, LocalTimes times) throws Exception {
answer.add(times);
}

View File

@ -37,7 +37,7 @@ public class WorldClockServerHandler extends SimpleChannelInboundHandler<Locatio
WorldClockServerHandler.class.getName());
@Override
public void channelRead0(ChannelHandlerContext ctx, Locations locations) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Locations locations) throws Exception {
long currentTime = System.currentTimeMillis();
LocalTimes.Builder builder = LocalTimes.newBuilder();

View File

@ -149,7 +149,7 @@ public class SctpEchoTest extends AbstractSctpTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
byte[] actual = new byte[in.readableBytes()];
in.readBytes(actual);

View File

@ -45,7 +45,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
sb.handler(new SimpleChannelInboundHandler<Object>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(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 channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
protected void messageReceived(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
if (done) {
fail = true;
}

View File

@ -41,7 +41,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
sb.handler(new SimpleChannelInboundHandler<DatagramPacket>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
assertEquals(1, msg.content().readInt());
latch.countDown();
}
@ -49,7 +49,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
cb.handler(new SimpleChannelInboundHandler<Object>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msgs) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msgs) throws Exception {
// Nothing will be sent.
}
});
@ -69,12 +69,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
run();
}
@SuppressWarnings("deprecation")
public void testSimpleSendWithoutBind(Bootstrap sb, Bootstrap cb) throws Throwable {
final CountDownLatch latch = new CountDownLatch(1);
sb.handler(new SimpleChannelInboundHandler<DatagramPacket>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
assertEquals(1, msg.content().readInt());
latch.countDown();
}
@ -82,7 +83,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
cb.handler(new SimpleChannelInboundHandler<Object>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msgs) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msgs) throws Exception {
// Nothing will be sent.
}
});

View File

@ -96,7 +96,7 @@ public class SocketBufReleaseTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
// discard
}

View File

@ -199,7 +199,7 @@ public class SocketEchoTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
byte[] actual = new byte[in.readableBytes()];
in.readBytes(actual);

View File

@ -72,7 +72,7 @@ public class SocketFileRegionTest extends AbstractSocketTest {
ChannelInboundHandler ch = new SimpleChannelInboundHandler<Object>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
}
@Override
@ -131,7 +131,7 @@ public class SocketFileRegionTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
byte[] actual = new byte[in.readableBytes()];
in.readBytes(actual);

View File

@ -134,7 +134,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
assertEquals(1024, msg.readableBytes());
byte[] actual = new byte[msg.readableBytes()];

View File

@ -132,7 +132,7 @@ public class SocketGatheringWriteTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
counter += in.readableBytes();
received.writeBytes(in);
}

View File

@ -127,7 +127,7 @@ public class SocketShutdownOutputByPeerTest extends AbstractServerSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
queue.offer(msg.readByte());
}

View File

@ -86,7 +86,7 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
queue.offer(msg.readByte());
}
}

View File

@ -251,7 +251,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
byte[] actual = new byte[in.readableBytes()];
in.readBytes(actual);

View File

@ -205,7 +205,7 @@ public class SocketSslEchoTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
byte[] actual = new byte[in.readableBytes()];
in.readBytes(actual);

View File

@ -159,7 +159,7 @@ public class SocketStartTlsTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
public void messageReceived(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 channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
if ("StartTlsRequest".equals(msg)) {
ctx.pipeline().addAfter("logger", "ssl", sslHandler);
ctx.writeAndFlush("StartTlsResponse\n");

View File

@ -146,7 +146,7 @@ public class SocketStringEchoTest extends AbstractSocketTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
assertEquals(data[counter], msg);
if (channel.parent() != null) {

View File

@ -167,7 +167,7 @@ public class UDTClientServerConnectionTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
log.info("Client received: " + msg);
}
}
@ -320,7 +320,7 @@ public class UDTClientServerConnectionTest {
}
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
log.info("Server received: " + msg);
}
}

View File

@ -28,7 +28,7 @@ import io.netty.util.internal.TypeParameterMatcher;
* {@link SimpleChannelInboundHandler}&lt;{@link String}&gt; {
*
* {@code @Override}
* protected void channelRead0({@link ChannelHandlerContext} ctx, {@link String} message)
* protected void messageReceived({@link ChannelHandlerContext} ctx, {@link String} message)
* throws {@link Exception} {
* System.out.println(message);
* }
@ -37,6 +37,11 @@ import io.netty.util.internal.TypeParameterMatcher;
*
* Be aware that depending of the constructor parameters it will release all handled messages.
*
* <h3>Backward compatibility consideration</h3>
* <p>
* Since 5.0, {@code channelRead0(ChannelHandlerContext, I)} has been renamed to
* {@link #messageReceived(ChannelHandlerContext, Object)}.
* </p>
*/
public abstract class SimpleChannelInboundHandler<I> extends ChannelInboundHandlerAdapter {
@ -95,7 +100,7 @@ public abstract class SimpleChannelInboundHandler<I> extends ChannelInboundHandl
if (acceptInboundMessage(msg)) {
@SuppressWarnings("unchecked")
I imsg = (I) msg;
channelRead0(ctx, imsg);
messageReceived(ctx, imsg);
} else {
release = false;
ctx.fireChannelRead(msg);
@ -115,5 +120,5 @@ public abstract class SimpleChannelInboundHandler<I> extends ChannelInboundHandl
* @param msg the message to handle
* @throws Exception is thrown if an error occurred
*/
protected abstract void channelRead0(ChannelHandlerContext ctx, I msg) throws Exception;
protected abstract void messageReceived(ChannelHandlerContext ctx, I msg) throws Exception;
}