2013-10-25 65 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()返回之前也會被調用。