找回密码
 FreeOZ用户注册
查看: 1805|回复: 9
打印 上一主题 下一主题

My First Glance @ Apache MINA - A Network Application Development Framework

[复制链接]
跳转到指定楼层
1#
发表于 22-10-2009 10:00:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册

x
Questions of programming a network application:

1. Basic Connection Questions
1.1 Server Port and Transportation Protocol(TCP/UDP)
1.2 Connection Timeout Settings
1.3 Connection Idle Settings

2. Advanced Connection Questions
2.1 Application Protocol
2.2 Authentication and Connection Security
2.3 Data Compression
2.4 Exception Handling
2.5 Sending and Receiving Bufferring

3. Business Level Questions
3.1 Business Logic (Transactions, etc)
3.2 Network Statistics and Management
3.3 Asynchronous Communication Model

Note that this thread of articles are written by myself for discussion with you.
They're not the official programming documentation and don't take for granted,
for I'm not 100% sure about the correctivity.

Key @ Oct, 2009

[ 本帖最后由 key 于 22-10-2009 15:24 编辑 ]
回复  

使用道具 举报

2#
 楼主| 发表于 22-10-2009 10:30:56 | 只看该作者

What Apache MINA is?

A Network Application Framework

Apache MINA is a framework. As a framework, it provides features like:

  • Abstract
  • Flexible
  • Develop Model


Abstract
Apache MINA abstracts the network application into layers and
components.

Abstract - Layers
From the software layers' point of view, Apache MINA divides
the network application development into three layers:
  • 1. IoService Layer
  • 2. IoFilterChain Layer
  • 3. IoHandler Layer


1. IoService Layer
This is the layer which performs actual I/O with the communication
peer. So it's the lowest layer.

2. IoFilterChain Layer
This is a lower layer which handle the transportation protocols,
including encrypting data, compression, text reformatting, etc.
You'd better regard the communication data as chunk, rather than
as a logical message.
As the name suggests, Apache MINA apply chain-of-responsibility
design pattern.

3. IoHandler Layer
IoHandler layer is the business logic implementation layer of
MINA framework. You need to implement the business logic of your
network application within this layer.

[ 本帖最后由 key 于 22-10-2009 14:32 编辑 ]
回复  

使用道具 举报

3#
 楼主| 发表于 22-10-2009 11:04:08 | 只看该作者

What Apache MINA is? (Cont)

Abstract - Components

From the server side's point of view, there are eight
popular Apache MINA components you need to master before
you program the application. They are:

  • 1. Buffer
  • 2. Acceptor
  • 3. Config
  • 4. Filter
  • 5. Codec
  • 6. Handler
  • 7. Session
  • 8. Message


1. Buffer
Buffer is a concept from Java NIO. Please refer to
http://java.sun.com/j2se/1.5.0/d ... ml?is-external=true
for more information. To simplify, Buffer is a container which represents
the content of the communication.

Relative class/interface:
  • org.apache.mina.common.ByteBuffer
  • org.apache.mina.common.ByteBufferAllocator
  • org.apache.mina.common.SimpleByteBufferAllocator
  • org.apache.mina.common.PooledByteBufferAllocator
  • org.apache.mina.common.ByteBufferProxy
  • org.apache.mina.util.ByteBufferUtil


2. Acceptor
Acceptor is a server side concept, which accepts incoming connection,
communications with clients, and fires events to Handlers.

If you're an experienced network programmer, you must have know the
binding, listening and accepting concepts. If you only program with
Java ServerSocket before, you may miss the listening part.
However, ServerSocket combines all the network operation within one
class, while Apache MINA extracts binding, listening and accepting
operations into Acceptors.

IoAcceptor is the interface for Acceptors. The implementations of this interface
includes:
  • org.apache.mina.common.support.BaseIoAcceptor
  • org.apache.mina.transport.socket.nio.DatagramAcceptor
  • org.apache.mina.common.support.DelegatedIoAcceptor
  • org.apache.mina.transport.socket.nio.SocketAcceptor
  • org.apache.mina.transport.vmpipe.VmPipeAcceptor


Note that: IoAcceptor is a sub interface of IoService, and another
sub interface of IoService is IoConnection. Please refer to Abstract - layers
for more information about IoService Layer concept.

[ 本帖最后由 key 于 22-10-2009 12:25 编辑 ]
回复  

使用道具 举报

4#
 楼主| 发表于 22-10-2009 12:35:05 | 只看该作者
3. Config

Apache MINA Config is not configuration file set. Please refer
to the following class diagram for a high level view.

回复  

使用道具 举报

5#
 楼主| 发表于 22-10-2009 12:56:05 | 只看该作者
4. Filter

Filter is one of the most important concept of Apache MINA.
From the previous article, you can see the relationship between
Config and Filter, Filter and Codec.

4.1 Config vs. Filter
From the layer's point of view, Filter serves at the transport
layer, in between IoService and IoHandler. In terms of
class relationship, Filter is part of the service configuration.
More specifically, Filter Chain is part of the service configuration.

To make use of a filter, you can add the following code into your
program:
  1. config.getFilterChain().addLast("filter-name", filterObject);
复制代码
4.2 Filter vs. Codec
See 3

4.3 Exist Filter
回复  

使用道具 举报

6#
 楼主| 发表于 22-10-2009 13:18:24 | 只看该作者
5. Codec
回复  

使用道具 举报

7#
 楼主| 发表于 22-10-2009 13:29:07 | 只看该作者
5.1 Exist Codec
  • Message Codec: org.apache.mina.filter.codec.demux: Protocol codecs that helps you to implement even more complex protocols by splitting a codec into multiple sub-codecs.
  • Netty Codec: org.apache.mina.filter.codec.netty: Protocol codec which provides the integration with Netty2 messages.
  • Object Codec: org.apache.mina.filter.codec.serialization: Protocol codecs which uses Java object serilization and leads to rapid protocol implementation.
  • Text Codec: org.apache.mina.filter.codec.textline: A protocol codec for text-based protocols


That's cool!
回复  

使用道具 举报

8#
 楼主| 发表于 22-10-2009 14:00:42 | 只看该作者
6. Handler

Handler Components are components serve at IoHandler Layer, which is
the business layer of Apache MINA application.

Usually, people program their own Handler class for their own business
requirement. There are some exist handler classes.

回复  

使用道具 举报

9#
 楼主| 发表于 22-10-2009 14:07:41 | 只看该作者

Summary

Apache MINA is a well design Java Network Application framework,
with supporting components for developing a Java Network Application.
It's clear, clean, and useful. It takes me only 5 hours to learn
all the concepts and programming APIs. After that, I don't need
to program my Network Application from scratch. Even more,
I can get benefits from this framework, such as framework based
feature, modularisation, event-driven programming, flexibility,
NIO for efficiency, etc.
回复  

使用道具 举报

10#
发表于 22-10-2009 14:15:26 | 只看该作者
回复  

使用道具 举报

您需要登录后才可以回帖 登录 | FreeOZ用户注册

本版积分规则

小黑屋|手机版|Archiver|FreeOZ论坛

GMT+10, 22-4-2025 07:00 , Processed in 0.048407 second(s), 27 queries , Gzip On, Redis On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表