Server Architecture
We have exposed the MINA Application Architecture in the previous section. Let's now focus on the Server Architecture. Basically, a Server listens on a port for incoming requests, process them and send replies. It also creates and handles a session for each client (whenever we have a TCP or UDP based protocol), this will be explain more extensively in the chapter 4.
我在上一章节中介绍了mina的应用架构。让我们来了解一个服务端的架构。
服务端主要监听端口进来的请求,处理请求和发送回复,为处理每一个客户端(基本tcp 或者udp协议)创建一个会话 。在第4个会更详细的介绍。
- IOAcceptor listens on the network for incoming connections/packets
- For a new connection, a new session is created and all subsequent request from IP Address/Port combination are handled in that Session
- All packets received for a Session, traverses the Filter Chain as specified in the diagram. Filters can be used to modify the content of packets (like converting to Objects, adding/removing information etc). For converting to/from raw bytes to High Level Objects, PacketEncoder/Decoder are particularly useful
- Finally the packet or converted object lands in
IOHandler
.IOHandler
s can be used to fulfill business needs.
IOAcceptor 监听来自网络的连接和数据包
一个新链接,创建一个会话,这个ip地趾端口尾随而来的请求在这个会话中处理。
会话所有的数据包会经过filter chain 。filter 被用修改数据包的内容,为转换byte为更高的对象(如string等),数据编码/解码常用到。
最数据包被转换成对象传给iohanlder ,iohanlder 被用于满足业务逻辑的需求。
Session creation
Whenever a client connects on a MINA server, we will create a new session to store persistent data into it. Even if the protocol is not connected, this session will be created. The following schema shows how MINA handles incoming connections :
当客户连接mina服务端,将会创建一个新的会话用于存储待久数据,甚至这个协议没有连接这个session也被创建。
下面的说明mina是如何处理请求链接的。
Incoming messages processing
We will now explain how MINA processes incoming messages.
Assuming that a session has been created, any new incoming message will result in a selector being waken up
假如一个会话被创建。一个新消息的到将使一个选择器被人唤醒