1.首先,了解下mina框架有哪些特点,适合什么样的场景
MINA is a simple yet full-featurednetwork application framework which provides:
//可以支持各种协议,包括自己的协议
- Unified API for various transport types:
- TCP/IP & UDP/IP via Java NIO
- Serial communication (RS232) via RXTX
- In-VM pipe communication
- You can implement your own!
//提供滤波器接口
- Filter interface as an extension point; similar to Servlet filters
//可以调用不同类型的API,低层次的有ByteBuffer,高层次的有用户自己定义消息对象
- Low-level and high-level API:
- Low-level: uses ByteBuffers
- High-level: uses user-defined message objects and codecs
//非常个性化的线程订制,可以提供单线程,单线程池,多线程池
- Highly customizable thread model:
- Single thread
- One thread pool
- More than one thread pools (i.e. SEDA)
- Out-of-the-box SSL · TLS · StartTLS support using Java 5 SSLEngine
- Overload shielding & traffic throttling
- Unit testability using mock objects
- JMX manageability
//支持对象流
- Stream-based I/O support via StreamIoHandler
- Integration with well known containers such as PicoContainer and Spring
//很容易从Netty移植到mina
- Smooth migration from Netty, an ancestor of Apache MINA.
2.分析mina框架结构和原理
MINA based Application Architecture
It's the question most asked : 'How does a MINA based application look like'? In this article lets see what's the architecture of MINA based application. Have tried to gather the information from presentations based on MINA.
A Bird's Eye View :
Here, we can see that MINA is the glue between your application (be it a client or a server) and the underlying network layer, which can be based on TCP, UDP, in-VM comunication or even a RS-232C serial protocol for a client.
You just have to design your application on top of MINA without having to handle all the complexity of the newtork layer.