Apache Mina Development Manual II

Source: Internet
Author: User

Apache Mina Development Manual II

Apache Mina Development Manual II

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


Related Article

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.