Mina deadlock判断:
在DefaultIoFuture类中,checkDeadLock方法:
in DefaultIoFuture the deadlock detection algorithm, the strategy is in two steps, first is a simple and rapid method to detect, and then use a more accurate method to detect. The first method to obtain the current thread by getStackTrace the entire stack of array of elements, then iterate the array to see if there is a layer called the class is AbstractPollingIoProcessor, if any, is the existence of cycles is called deadlock. This is because to achieve IoProcessor AbstractPollingIoProcessor abstract class that contains an Executor, create a thread processing tasks,
在mina的官方API文档里,在介绍IoFilter时,有这么一句话:
Please NEVER implement your filters to wrapIoSessions.Users can cache the reference to the session, which might malfunction if any filters are added or removed later.
这个是什么意思呢?为何不建议定制filters to wrap IoSession?
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. ???
如果是IoFilterChain上的最后一个filter,则调用destroy()方法。
IoService接口管理一个service下的所有session,使用Map用来存储session信息。
public interface IoService {
...
/**
*@returnthe map of all sessions which are currently managed by this
* service. The key of map is the {@linkIoSession#getId() ID} of the
* session. An empty collection if there's no session.
*/
Map getManagedSessions();
...
}
IoAcceptor代表服务器端,接收客户端的connection,调用handler处理events。
IoConnector代表客户端,连接服务器端,调用handler处理events。
IoAcceptor和IoConnector都extends IoService。