什么时候将 ChannelHandlerContext 传递给 ChannelHandler 而不是 ChannelHandler 自己的上下文?
When is a ChannelHandlerContext handed to a ChannelHandler not that ChannelHandler's own context?
这是一个(永久性的)link 一个关于我有疑问的问题的例子,来自 Netty 自己的例子。所讨论的示例本身并不重要,只是它显示了我想知道的模式这一事实:
我摘录如下:
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
ChannelPipeline pipeline = ctx.pipeline();
ChannelHandlerContext thisCtx = pipeline.context(this);
/* ... */
这里我们有一个 ChannelInboundAdapter
传递了一个 ChannelHandlerContext
。很好。
不过,我在这里摘录的方法的前两行跳过了一些圈套以获得 "the right" ChannelHandlerContext
,暗示(无论如何对我来说)ChannelHandlerContext
提供给此方法的方法在某种程度上不是 "belongs to" 此 ChannelHandler
.
什么情况下需要这种跳铁环?
感谢您提出这个问题...这实际上是示例中的 "a bug",完全没有必要。只需使用 ctx :)
对示例的建议修复:
这是一个(永久性的)link 一个关于我有疑问的问题的例子,来自 Netty 自己的例子。所讨论的示例本身并不重要,只是它显示了我想知道的模式这一事实:
我摘录如下:
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
ChannelPipeline pipeline = ctx.pipeline();
ChannelHandlerContext thisCtx = pipeline.context(this);
/* ... */
这里我们有一个 ChannelInboundAdapter
传递了一个 ChannelHandlerContext
。很好。
不过,我在这里摘录的方法的前两行跳过了一些圈套以获得 "the right" ChannelHandlerContext
,暗示(无论如何对我来说)ChannelHandlerContext
提供给此方法的方法在某种程度上不是 "belongs to" 此 ChannelHandler
.
什么情况下需要这种跳铁环?
感谢您提出这个问题...这实际上是示例中的 "a bug",完全没有必要。只需使用 ctx :)
对示例的建议修复: