create account

What is Apache MINA & MINA in Action by flyyou

View this thread on: hive.blogpeakd.comecency.com
· @flyyou ·
$7.97
What is Apache MINA & MINA in Action
안녕하세요 @flyyou 입니다.

미나라고 아시는지요? 자바로 네트웍 프로그램을 쉽게 할 수 있도록 구성된 네트웍 개발 프레임워크라고 볼 수 있습니다.
지금은 Netty라는 이름으로 변경되어서 오플 프로젝트로 진행되고 있습니다.

자세한 사항은 MINA 나 Netty로 검색해보면 정말 수많은 자료가 나옵니다.
Netty는 아래 그룹스에서 활발하게 토론이 이루어지고 있습니다.
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!forum/netty-ko

이전에 대충 메모해둔 내용과 그려놓은 아키텍처 디자인이 있어서 기록에 남기기 위해서 이곳에 다시 정리해 봅니다.

(참고 : https://mina.apache.org/)

## What is Apache MINA ##
 * A Java open-source network application framework
   - high performance
   - high scalability
 * Abstract API
   - Event-driven
   - Asynchronous
   - Unit-testable
 * Implementations
   - Sockets & datagrams ? Java NIO & APR via Tomcat Native
   - Serial ports ? RXTX.org 
   - In-VM pipes

## MINA Features ##
 * 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
 * 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
 * Out-of-the-box SSL · TLS · StartTLS support using Java 5 SSLEngine
 * Overload shielding & traffic throttling
 * Unit testability using mock objects
 * JMX managability
 * Stream-based I/O support via StreamIoHandler 
 * Integration with well known containers such as PicoContainer and Spring

## MINA Key Concepts ##

![](https://steemitimages.com/DQme8k3fHoPT7sN1Y1M18CQQ1iGW3o9X49LYWYgoHKj1wZB/image.png)

## MINA in Action ##

아래 디자인은 실제로 제가 진행했던 과제에서 도입했던 디자인입니다.

* MINA의 Event-Driven 방식으로 I/O 수행 쓰레드와 비즈니스 로직처리 쓰레드를 분리
* Handler를 이용하는 방식으로 Pool지원

![](https://steemitimages.com/DQmNRX6DUjoQSRwuoAwX5oY3UicQtbqWmSgYEa81Az1KeLZ/image.png)

## Architecture Design ##

* Start Daemon 시에 ServiceDaemonLoader의 main()메쏘드 실행
* Main() 메쏘드에서 init() / start() 실행
  - Init() : Spring DI를 이용하여 HttpProxyService의 서버 종류를 선택
  - Start() : 선택된 HttpProxyServie 실행. 

![](https://steemitimages.com/DQmb9fi9H1HkpgX755EHt825ZwrwHoLSKrgLtnXyXtt2Fe5/image.png)

* HttpProxyServie를 구현한 구현체(HttpProxyServiceMINA / HttpProxyServicePOJO)에서 start()메쏘드 실행시 해당 Bean Id에 list 형태로 매핑된 Processor Bean이 실행.
  - AbstractServiceProcessor을 구현한 해당 서비스 프로세스(ProxtServerProcessor / CommunicationProcessor / CommonProcessor)의 serviceStart() 메쏘드 실행

![](https://steemitimages.com/DQmPr8ewsC8fWxg9Amn9YzpCb1NDe5syjDGFB4GKBiMaHHi/image.png)

#### context-beans.xml ####
```xml
<bean id="proxyServerProcessor" class="com.~~~~~~~~~.service.mina.ProxyServerProcessor">
<property name="startYn" value="Y" />
<property name="ipAddress" value="127.0.0.1" />
<property name="port" value="1001" />
<property name="sslYn" value="N" />
<property name="processorName" value="proxyServerProcessor" />
</bean>
<bean id="httpProxyServiceMINA" class="com.~~~~~~~~~.service.HttpProxyServiceMINA" >
<property name="processorList">
<list>
   <ref bean="proxyServerProcessor" />
   <ref bean="communicationProcessor" />
   <ref bean="CommonProcessor" />
    </list>
 </property>
</bean>
```


* Http Client에서 요청시 MINA 실행 데몬은 Accept를 받아서 Agent에서 등록된(Session ID) Socket Object를 찾는다.
  - ServiceLocator는 동기화된 MAP으로 Command Socket Map과  Communication Socket Map의 Repository 역할.
  - Cashing으로 관리되며 Pooling.

![](https://steemitimages.com/DQmeVJ4hcHzn7iSzcZm7gfPMb7PUAdszJkUJ7EshZsvk6ZK/image.png)

## Class Diagram ###

![](https://steemitimages.com/DQmPfBEBi46wE8V1yqwKiSWea8ac1RBY2PnpjEWnP5ysZ7a/image.png)

요즘은 Netty가 책도 잘 나와있고 인터넷에 자료도 많아서 훨씬 도입하기가 쉽습니다.

좀 지난 자료지만 올려봅니다.
많은 의견 부탁드립니다.
👍  , , , , , , ,
properties (23)
authorflyyou
permlinkwhat-is-apache-mina-and-mina-in-action
categorydev
json_metadata{"tags":["dev","kr-dev","kr","memo"],"users":["flyyou"],"image":["https://steemitimages.com/DQme8k3fHoPT7sN1Y1M18CQQ1iGW3o9X49LYWYgoHKj1wZB/image.png","https://steemitimages.com/DQmNRX6DUjoQSRwuoAwX5oY3UicQtbqWmSgYEa81Az1KeLZ/image.png","https://steemitimages.com/DQmb9fi9H1HkpgX755EHt825ZwrwHoLSKrgLtnXyXtt2Fe5/image.png","https://steemitimages.com/DQmPr8ewsC8fWxg9Amn9YzpCb1NDe5syjDGFB4GKBiMaHHi/image.png","https://steemitimages.com/DQmeVJ4hcHzn7iSzcZm7gfPMb7PUAdszJkUJ7EshZsvk6ZK/image.png","https://steemitimages.com/DQmPfBEBi46wE8V1yqwKiSWea8ac1RBY2PnpjEWnP5ysZ7a/image.png"],"links":["https://groups.google.com/forum/?utm_medium=email&amp;utm_source=footer#!forum/netty-ko","https://mina.apache.org/"],"app":"steemit/0.1","format":"markdown"}
created2017-07-18 07:30:06
last_update2017-07-18 07:30:06
depth0
children6
last_payout2017-07-25 07:30:06
cashout_time1969-12-31 23:59:59
total_payout_value6.196 HBD
curator_payout_value1.769 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,657
author_reputation4,447,836,923,106
root_title"What is Apache MINA & MINA in Action"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id8,849,623
net_rshares1,539,411,031,384
author_curate_reward""
vote details (8)
@facemaker77 · (edited)
이희승님 트위터에 스카웃됬다가 현재 라인플러스에 계시죠ㅎㅎ 구글그룹스에서 질문하면 잘 답변해주십니다ㅎㅎ트위터가 네티 기반이라더군요ㅎㅎ
properties (22)
authorfacemaker77
permlinkre-flyyou-what-is-apache-mina-and-mina-in-action-20170804t113202711z
categorydev
json_metadata{"tags":["dev"],"app":"steemit/0.1"}
created2017-08-04 11:32:03
last_update2017-08-04 11:32:21
depth1
children0
last_payout2017-08-11 11:32:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length74
author_reputation1,102,596,876,877
root_title"What is Apache MINA & MINA in Action"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id10,740,547
net_rshares0
@joeyarnoldvn ·
wow
properties (22)
authorjoeyarnoldvn
permlinkre-flyyou-what-is-apache-mina-and-mina-in-action-20170718t073043973z
categorydev
json_metadata{"tags":["dev"],"app":"steemit/0.1"}
created2017-07-18 07:30:45
last_update2017-07-18 07:30:45
depth1
children1
last_payout2017-07-25 07:30:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3
author_reputation51,867,863,946,836
root_title"What is Apache MINA & MINA in Action"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id8,849,661
net_rshares0
@flyyou ·
;)
properties (22)
authorflyyou
permlinkre-joeyarnoldvn-re-flyyou-what-is-apache-mina-and-mina-in-action-20170718t074709103z
categorydev
json_metadata{"tags":["dev"],"app":"steemit/0.1"}
created2017-07-18 07:47:09
last_update2017-07-18 07:47:09
depth2
children0
last_payout2017-07-25 07:47:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2
author_reputation4,447,836,923,106
root_title"What is Apache MINA & MINA in Action"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id8,850,616
net_rshares0
@ludorum ·
이희승님의 자바소녀 네티군요 :)
properties (22)
authorludorum
permlinkre-flyyou-what-is-apache-mina-and-mina-in-action-20170718t123750919z
categorydev
json_metadata{"tags":["dev"],"app":"steemkr/0.1"}
created2017-07-18 12:37:51
last_update2017-07-18 12:37:51
depth1
children1
last_payout2017-07-25 12:37:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length18
author_reputation45,673,022,586,692
root_title"What is Apache MINA & MINA in Action"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id8,868,764
net_rshares0
@flyyou ·
네 맞습니다. 네티라는 이름보다 예전에 미나라는 이름으로 아파치 프로젝트로 관리되었을때 정말 대단했습니다. ㅋ 네티 책사면 자바소녀 브로마이드가 들어가 있어요 ㅋㅋ
properties (22)
authorflyyou
permlinkre-ludorum-re-flyyou-what-is-apache-mina-and-mina-in-action-20170718t135708445z
categorydev
json_metadata{"tags":["dev"],"app":"steemit/0.1"}
created2017-07-18 13:57:09
last_update2017-07-18 13:57:09
depth2
children0
last_payout2017-07-25 13:57:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length91
author_reputation4,447,836,923,106
root_title"What is Apache MINA & MINA in Action"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id8,874,937
net_rshares0
@numlock ·
$0.30
어여쁜 네티의
👍  
properties (23)
authornumlock
permlinkre-flyyou-2017727t15474538z
categorydev
json_metadata{"tags":"dev","app":"esteem/1.4.6","format":"markdown+html","community":"esteem"}
created2017-07-27 06:47:06
last_update2017-07-27 06:47:06
depth1
children0
last_payout2017-08-03 06:47:06
cashout_time1969-12-31 23:59:59
total_payout_value0.222 HBD
curator_payout_value0.077 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7
author_reputation7,683,157,205,946
root_title"What is Apache MINA & MINA in Action"
beneficiaries
0.
accountesteemapp
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id9,879,489
net_rshares86,527,301,570
author_curate_reward""
vote details (1)