Netty is a NIO framework that makes Java NIO a package that forms a high-performance, highly available network programming framework, many of which are based on Netty, so learning Netty is useful, and Netty itself code structure design, And some ideas are very good, for our programming can play a very good help.
First, there are several main lines of Netty:
1.server end-of-start
2.client end-of-start
Connection at 3.client end
4. Reading of messages
5. Sending of messages
Let's look at server-side startup today.
We can see that there are three major steps
Init-----Initialize Nioserversocketchannel
Register----Bind a thread to the channel, register read events, and trigger firechnnelactive and Firechannelregister events
Dobind-----Perform a true binding
To go deeper netty we need to know a few things:
1. The entire life cycle of each channel has only one Netty assigned thread to work for him, and doing so ensures that the event handling within a channel is thread-safe, especially if the processing of handler is linear, noting that Netty is assigned to the thread, If you were to restart a channel in the life cycle of a conceivable.
2.netty allocated threads may have multiple channel sharing at the same time, the Netty threading model is very simple, and there is time for me to say the thread model alone.
When a server is started, it is initialized according to the configured channel, and a configuration is made for him, such as Id,pipeline (which contains the processor chain), unsafe (some actual operations, such as the registration of a channel at the Java level). After initialization, it registers a thread for him and triggers an active event and register event to perform a Java-level binding operation.
Netty Study Summary (i)