Netty explain the process in simple terms --54.Reactor

Reactor previous chapter we analyzed the five components in-depth analysis, we will now conduct a systematic analysis of the five components of running processes.

First Initiation Dispatcher will register all the Initiation Dispatcher Event Handler inside, when the registration of specified events of interest. And when the events of interest identified in accordance with Handler. The Handler is owned by the Event Handler. NIO interest in the event is interestKey. When the event of interest generated in the Handle Event Handler owned by, the Initiation Dispatcher to notify registered to the Event Handler concrete Concrete Event Handler. After the completion of preparations, Initiation Dispatcher will enter into an infinite loop, and then he the event will be waiting to be sent through the Synchronous event Demultiplexer call to select ().

When an event is generated on the handle, then the Synchronous Event emultiplexer will get to the collection of events generated and returned to the Initiation Dispatcher, then Initiation Dispatcher calls the select (handlers) to get all the processor corresponding to the current event. Then traverse the event handler, according to the event type to call registered to the Event Handler on which to invoke Concrete Event Handler through the inside of the handler_event (type) method.

Described two reactor design pattern is the same.

mainReactor 和 subReactor与上一张图里面的 Initiation Dispatcher是同一个,只是在scalable io in java 中将使用两个 Initiation Dispatcher来完成连接,mainReactor只负责客户端的连接,连接完成之后通过acceptor将后续的任务交给了subReactor进行处理。

Acceptor分析:在服务器绑定到端口号上的时候,首先mainReactor会创建一系列的初始化组件,然后绑定到相应的端口号,在这个过程中会向bossGroup增加一个handler(ChannelInitialize也就是一个inboundHandler),在这个handler里面会new出Acceptor这个对象。简单来说Acceptor是由netty内置的一个组件来完成的(我们在开发的时候是接触不到的)。当服务器绑定到特定的地址的时候,就自动创建好了这个实例,并且把它加到ChannelPipeline当中。而且在加入到时候会将它加载channelPipeline的最后面的初始化处理器上。它收到客户端发过来的这个数据之后,它会在chennelRead这个方法中,将当前的channel绑定到subReactor当中。

 

 

 

Guess you like

Origin blog.csdn.net/qq_37909508/article/details/91395741