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。