¿Alguna diferencia entre ctx.write () y ctx.channel (). Write () en netty?
Me di cuenta de que el ctx es diferente de un controlador a otro, incluso estos controladores están en la misma tubería, por ejemplo
p.addLast("myHandler1", new MyHandler1());
p.addLast("myHandler2", new MyHandler2());
en MyHander1
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
System.err.println("My 1 ctx: " + ctx + " channel: " + ctx.channel());
super.channelRead(ctx, msg);
}
en MyHandler2
@Override
protected void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
System.err.println("My 2 ctx: " + ctx + " channel: " + ctx.channel());
}
y la salida:
My 1 ctx: io.netty.channel.DefaultChannelHandlerContext@ba9340 channel: [id: 0xdfad3a16, /127.0.0.1:60887 => /127.0.0.1:8090]
My 2 ctx: io.netty.channel.DefaultChannelHandlerContext@1551d7f channel: [id: 0xdfad3a16, /127.0.0.1:60887 => /127.0.0.1:8090]
Noté que el ctx es diferente pero el canal es el mismo.
Entonces, ¿hay alguna diferencia entre invocar ctx.write () y ctx.channel (). Write ()?