通過前面的源碼系列文章中的netty reactor線程三部曲,我們已經知道,netty的reactor線程就像是一個發(fā)動機,驅動著整個netty框架的運行,而服務端的綁定和...
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new StringDecoder())
.addLast(new StringEncoder())
// TODO 這里對 01 和 02 進行分別測試可查看結果是否執(zhí)行了 10 中的代碼 打印 encoder invoked
// .addLast(new NettyServer001WorkerHandler01())
.addLast(new NettyServer001WorkerHandler02())
// TODO 這里是出站處理器
.addLast(new NettyServer001WorkerHandler10());
static class NettyServer001WorkerHandler10 extends MessageToByteEncoder {
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
System.out.println("encoder invoked" + msg);
}
}
static class NettyServer001WorkerHandler01 extends SimpleChannelInboundHandler<String> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
System.out.println("01 ---> " + msg);
// TODO 這里是 ctx.channel().writeAndFlush()
ctx.channel().writeAndFlush("001");
}
}
static class NettyServer001WorkerHandler02 extends SimpleChannelInboundHandler<String> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
System.out.println("02 ---> " + msg);
// TODO 這里是 ctx.writeAndFlush()
ctx.writeAndFlush("002");
}
}
netty源碼分析之pipeline(一)通過前面的源碼系列文章中的netty reactor線程三部曲,我們已經知道,netty的reactor線程就像是一個發(fā)動機,驅動著整個netty框架的運行,而服務端的綁定和...
看調用方法 ctx.writeAndFlush() 是會從 當前 channel.pre 開始執(zhí)行 handler,這里就不會調用 Encoder;如果是 ctx.channel().writeAndFlush()是從tail.pre開始執(zhí)行 handler ,也就是會調用到 Encoder了
netty源碼分析之pipeline(一)通過前面的源碼系列文章中的netty reactor線程三部曲,我們已經知道,netty的reactor線程就像是一個發(fā)動機,驅動著整個netty框架的運行,而服務端的綁定和...