IoService
--- Base interface for all IoAcceptors and IoConnectors that provide I/O service and manage IoSessions.
IoAcceptors和IoConnectors的基础接口,提供I/O服务和IoSession管理功能。
IoAcceptor extends IoService
--- Accepts incoming connection,communicates with clients,and fires events to IoHandlers
接收连接请求,与客户端交互并且触发事件到IoHandler
You should bind to the desired socket address to accept in coming connections, and when events for
incoming connections will be sent to the specified default IoHandler.
Threads accept incoming connections start automatically when bind() is invoked ,and stop when unbind()
is invoked.
IoConnector extends IoService
--- Connects to endpoint,communicates with whe server,and fires events to IoHandlers.
You should connect to the desired socket address to start communication,and then events for incoming
connections will be sent to the specified default IoHandler.
Threads connect to endpoint start automatically when connect(SocketAddress) is invoked,and stop when
all connection attempts are finished.
IoHandler
--- Handles all I/O events fired by MINA.
IoSession
--- A handle which represents connection between two end-points regardless of transport types.
IoSession provides user-defined attributes.User-defined attributes are application-specific data
which are associated with a session.It often contains objects that represents the state of a higher-level
protocol and becomes a way to exchange data between filters and handlers.
Adjusting Transport Type Specific Properties
You can simply downcast the session to an appropriate subclass.
Thread Safety
IoSession is thread-safe. But please note that performing more than one write(Object) calls at the
same time will cause the IoFilter#filterWrite(IoFilter.NextFilter,IoSession,WriteRequest) to be
executed simultaneously, and therefore you have to make sure the IoFilter implementations you're useing
are thread-safe, too.
Equality of Sessions
The getId() method is totally wrong.We can't base a method which is designed to create a unique ID
on the hashCode method. equals(Object) and hashCode() shall not be overriden to the default behavior
that is defined in Object.
IoFilter
--- A filter which intercepts IoHandler events like Servlet filters. Filters can be used for these
purposes:Event loging,Performance measurement,Authorization,Overload control,Message transformation
(e.g. encryption and decryption,...), and any more.
Please NEVER implement your filters to wrap IoSessions. Users can cache the reference to the
session, which might malfunction if any filters are added or removed later.
The Life Cycle
IoFilters are activated only when they are inside IoFilterChain.
When you add an IoFilter to an IoFilterChain:
init() is invoked by ReferenceCountingFilter if the filter is added ad the first time.
onPreAdd(IoFilterChain,String,NextFilter) is invoked to notify that the filter will be added
to the chain.
The filter is added to the chain, and all events and I/O requests pass through the filter from now.
onPostAdd(IoFilterChain, String, NextFilter) is invoked to notify that the filter is added to the
chain.
The filter is removed from the chain if onPostAdd(IoFilterChain, String,
org.apache.mina.core.filterchain.IoFilter.NextFilter) threw an exception. destroy() is also invoked by
ReferenceCountingFilter if the filter is the last filter which was added to IoFilterChains.
When you removed an IoFilter from an IoFilterChain:
onPreRemove(IoFilterChain, String, NextFilter) is invoked to notify that the filter will be removed
from the chain.
The filter is removed from the chain, and any events and I/O requests don't pass through the filter
from now.
onPostRemove(IoFilterChain, String, NextFilter) is invoked to notify that the filter is removed
from the chain.
destroy() is invoked by ReferenceCountingFilter if the removed filter was the last one.
IoFilterChain
--- A container of IoFilters that forwards IoHandler events to the consisting filters and terminal
IoHandler sequentially.
Every IoSession has its own IoFilterChain (1-to-1 relationship).