I noticed that ctx differs from a handler in a handler, even these handlers are in the same pipeline, for example
p.addLast("myHandler1", new MyHandler1()); p.addLast("myHandler2", new MyHandler2());
at 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); }
in MyHandler2
@Override protected void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { System.err.println("My 2 ctx: " + ctx + " channel: " + ctx.channel()); }
and conclusion:
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]
I noticed that ctx is different, but the channel is the same
So, is there a difference between invoke ctx.write () and ctx.channel (). write ()?
java netty
Alexis
source share