Netty's easy to understand --56.ChannelPipeline use the opportunity to create a model with advanced interceptor

 In this chapter we continue in-depth analysis ChannelPipeline

We can see AbstractChannel is an abstract realization of channel

We can now understand all inherited objects in AbstractChannel the channel, its interior is a variable pipeline pipeline

 Create a pipeline

 

We found pipeline to create the final out of time turned out to be a channel object. Shock! (ΩДΩ) 

Next we want to analyze tail, head 

 

In fact AbstractChannelHandlerContext inherited ChannelHandlerContext; (then-depth analysis of this later)

 

 

 Then connect the head and tail

 

We continue to analyze ChannelPipeline

It is a set ChannelHandler, for processing and block channel push and pop operations, which implements a filter interceptor priority mode allows the user to control the interaction between each event and HannelHandler inside the pipeline.

There is a very important points:

Filter Mode:

Conventional filter mode client sends a request to the server, is assumed to be sequentially passes through A, B, C three processors, when returned to the client after processing, sequentially through C, B, A three filters

netty filter mode client sends a request to the server, then it is only through the filter A, B, C of these processing requests; and the server response to the client by the D, E, F which handles the response filters to deal with.

pipeline will be created automatically when the channel is created, each channel will have its own pipeline.

 

pipeline just a container, the request is actually processed inside it a series of ChannelHandler;

I mentioned here a little: after channelHandler been processed will be forwarded to the next nearest channelHandler, while the next nearest channelHandler by ChannelHandlerContext to decide how to determine.

 

The processor also push the stack processor or both stack is popped processor is determined by your new object

 

There is a very important points:

因为在pipeline中进行channelhander处理的时候是要通过一个个处理器来排队进行处理的,但是这样也会出现一个问题,如果一个处理很长的话,那很有可能就会出现长时间的阻塞,所以官方提出来的一个解决办法就是创建线程池来讲处理事件单独提取出来放入到线程中处理。和当前pipeline的主线程不会构成影响。

 

 

Guess you like

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