Netty_EventLoop_EventLoopGroup

All IO operations in Netty are performed asynchronously. app


Future和ChannelFuture

So when you connect to a host for example,  this  is  done  asynchronously(異步的)  by  default.  The  same  is  true when  you  write/send  a message.  This  means  the operation  may  not  be  performed  directly  but picked up  later  for execution. Because of this you can t know if an operation was successful or not after it returns, but need to be able to check later for success or have some kind of ways to register a listener which is notified. To rectify(糾正) this, Netty uses Futures and ChannelFutures. This future can be used  to  register  a  listener,  which  will  be  notified  when  an  operation  has  either  failed  or completed successfully. 異步


Netty EventLoop和EventLoopGroup

The  relationship  between  an  EventLoop and  an EventLoopGroup may  not  be immediately(當即立刻)  intuitive(直觀的),  because  we have  said  that  an EventLoopGroup contains  one or  more EventLoop but  this  diagram  shows  that  in  fact,  an  EventLoop passes  the   is-a EventLoopGroup test,  i.e.  an EventLoop is  an EventLoopGroup.   This means  wherever you can pass in an EventLoopGroup you can also just use a specific(具體的) EventLoop. async


figure  3.1  shows  why  the  design  Netty  uses  to  ensure  no  synchronization(同步)  is required on your part to process Netty events. oop

EventLoop Thread relationship ui

The EventLoop is always bound to a single Thread that never changed during it s life time. this

When a channel is registered, Netty binds that channel to a single EventLoop(and so to a single thread) for the life time of that Channel. This is why your application doesn t need to synchronize  on  Netty  IO  operations  because  all  IO  for  a  given Channel will  always  be performed by the same thread. spa

all  IO  for  a  given Channel will  always  be performed by the same thread. orm

=====END=====ip

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息