1-What is Apache MINA?

Apache MINA (Multipurpose Infrastructure for Network Application) is an open source java network application framework. MINA is can be used to create Scalable, high performance Network applications. MINA provides unified API's for various transports like TCP, UDP, Serial communication, In-VM pipe. It also makes it easy to make an implementation of custom transport type. MINA provides both high-level and low-level network API's.
Application Structure

MINA based Application Architecture

From the figure above, User application interacts with MINA API's, shielding the User application from Low level IO details. MINA internally uses IO API's to perform the actual IO functions. This makes it easy for the Users to concentrate on Application logic and leave the IO handling to Apache MINA.
Advantages (From the Apache MINA Home page)
  • Unified API's for various transports (TCP/UDP etc)
  • Provides high/low level API's
  • Customizable Thread Model
  • Easy Unit Testing using MockObjects
  • Integration with DI frameworks like Spring, Google Guice, picocontainer
  • JMX Manageability


2-Introduction to Apache MINA

https://www.slideshare.net/pokpitch1/introduction-to-apache-mina

 

 

 

 

 

 

 

 


3-Integrating Apache MINA with Spring

To integrate with Spring, we need to do following
  • One Handler
  • Two Filter – Logging Filter and a ProtocolCodec Filter
  • NioDatagram Socket
This is how our code looks like for the standalone application
To integrate with Spring, we need to do following
  1. Set the IO handler
  2. Create the Filters and add to the chain
  3. Create the Socket and set Socket Parameters
NOTE: The latest MINA releases doesn’t have the package specific to Spring, like its earlier versions. The package is now named Integration Beans, to make the implementation work for all DI frameworks.
Lets see the Spring xml file. Please see that I have removed generic part from xml and have put only the specific things needed to pull up the implementation. This example has been derived from Chat example shipped with MINA release.
Now lets pull things together
  1. Lets set the IO Handler

  2. Lets create the Filter chain
  3. Here, we create instance of our IoFilter. See that for the ProtocolCodec factory, we have used Constructor injection. Logging Filter creation is straight forward. Once we have defined the beans for the filters to be used, we now create the Filter Chain to be used for the implementation. We define a bean with id “FilterChainBuidler” and add the defined filters to it. We are almost ready, and we just need to create the Socket and call bind
  4. Lets complete the last part of creating the Socket and completing the chain
Now we create our ioAcceptor, set IO handler and Filter Chain. Now we have to write a function to read this file using Spring and start our application. Here’s the code
We just call this method from main, and this shall initialize our MINA application. Will try to write a post using some other DI framework like Google Guice.

4-Apache MINA with Spring Boot

https://github.com/oncekey/spring-boot-mina

TL Tham khảo