Apache Mina Development Manual II

Source: Internet
Author: User

Apache Mina Development Manual II

Chszs, which must be noted for reprinting. Blog homepage: http://blog.csdn.net/chszs

Iv. Nio Overview

Nio api is introduced in Java 1.4. Nio means non-blocking I/O communication.
Knowing that Mina's NiO was developed based on NIO-1, and that the library of NIO-2 was introduced in JDK 7, but Mina hasn't gotten any improvements from the NIO-2, so Mina is based on NIO-1.
Although Oracle officially interpreted NiO N as new, it is widely interpreted as non-blocking in the industry.

Mina is currently divided into two major versions: 1.x and 2.x. The main difference between the two versions is that 1.x uses the traditional I/O mode, while 2.x uses NiO. Because NiO is non-blocking and traditional Io is blocking, the performance of version 2.x will be improved. However, NiO is more difficult to understand and implement than traditional Io, and it is more difficult to develop a NiO-based high-performance server by yourself. This is also the reason for choosing the Mina framework.
Mina 3.x is still in the development phase and will further improve the communication performance through NIO-2.

The Java. NiO. * package contains several key structures:
1) buffer: Data container
2) charset: Container converter with byte and Unicode encoding
3) channel: encapsulates the connection performance of entities for I/O operations
4) selector: Provides optional, multi-point multiplexing non-blocking I/O
5) regexps: provides some tools for operating regular expressions.

Advantages of using MINA:
1) hides the complexity of developing network programs and provides a unified programming interface;
-Use Java NiO for TCP/IP and UDP/IP communication
-Use rxtx for RS232 serial communication
-VM-level pipeline Communication
-Implement your own transmission protocol

2) filter interfaces similar to servlet support extension

3) low-level and high-level APIs
-Lower Layer: bytebuffer
-High Level: Use user-defined message objects and codes

4) highly customizable thread model
-Single thread
-Single thread pool
-Multiple thread pools (I .e. SEDA)

5) Implement out-of-the-box SSL, TLS, and starttls through sslengine of Java 5

6) overload protection and traffic restriction

7) unit Testability With mock objects

8) JMX management capability

9) streamiohandler supports stream I/O

10) It can be integrated with the picocontainer or spring framework.

11) smooth migration from Mina 1. X and netty

5. Mina application architecture

1. Mina application-based architecture

The architecture of Mina-based applications is usually as follows:


It can be seen that Mina is the glue layer between the application and the network layer, can complete TCP, UDP communication through Mina, or even serial RS-232C communication. Mina shields the complexity of network programming, and you only need to focus on processing business logic.

Next we will continue to go deep into the Mina framework:


In a broad sense, Mina-based applications can be divided into three layers:

1) I/O service: I/O service, which implements the actual I/O communication.
2) I/O filter chain: I/O filter chain, which filters/converts bytes into the required data structure, and vice versa.
3) I/O handler: I/O handle, which is placed in the actual business logic.

Therefore, to create a Mina-based application, you must:

1) Create an I/O service
You can select an existing service (* acceptor) or create your own I/O service.

2) create a filter chain
You can select an existing filter or create a custom filter to convert the request/response data.

3) create an I/O handle
Write business logic to process different messages


Apache Mina Development Manual II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.