2013-10-25 64 views
0

我正在阅读Netty 4.0.10.Final的源代码。 在AbstractChannel.AbstractUnsafe类阅读netty的问题源代码

private void invokeLater(Runnable task) { 
     // This method is used by outbound operation implementations to trigger an inbound event later. 
     // They do not trigger an inbound event immediately because an outbound operation might have been 
     // triggered by another inbound event handler method. If fired immediately, the call stack 
     // will look like this for example: 
     // 
     // handlerA.inboundBufferUpdated() - (1) an inbound handler method closes a connection. 
     // -> handlerA.ctx.close() 
     //  -> channel.unsafe.close() 
     //   -> handlerA.channelInactive() - (2) another inbound handler method called while in (1) yet 
     // 
     // which means the execution of two inbound handler methods of the same handler overlap undesirably. 
     eventLoop().execute(task); 
    } 

有意见我迷惑不解。 为什么出站事件立即触发入站事件。有人可以为我解释细节吗?谢谢!

+0

是否有netty开发者邮件列表?这可能是一个更好的问题。 – Bill

+0

你明白了:https://groups.google.com/forum/#!forum/netty – Nicholas

回答

0

(我已经回答了这个问题,但我再回答,使该条目完成)。

什么评论说,基本上我们要确保在相同的处理的处理方法的执行没有按重叠。没有invokeLater()handlerA.channelInactive()即使在handlerA.inboundBufferUpdated()返回之前也会被调用。