- 浏览: 980019 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
Mina 连接器接口定义及抽象实现(IoConnector ):http://donald-draper.iteye.com/blog/2378936
引言:
IoConnector接口给Ioservice增加了连接功能,可以连接服务端。连接操作,首先检查连接器状态,本地地址与远程地址是否为空已经与传输元数据地址类型是否匹配,如果连接器Iohandler为null,创建一个对会话操作事件不处理的IoHandler,最后将实际连接操作委托给connect0,待子类实现。
从上面可以看出,抽象拉取连接器内部比较重要的几个变量为连接请求队列connectQueue,连接请求取消队列cancelQueue,
Io处理器,连接线程引用connectorRef。
再来看构造:
上面所有的构造方法,都是通过AbstractPollingIoConnector(IoSessionConfig sessionConfig, Executor executor, IoProcessor<S> processor,
boolean createdProcessor)来实现,我们来看这个方法:
从上面可以看出,拉取连接器构造主要初始化会话配置,IO事件执行器和IO处理器。
再来看其他方法的定义:
上面这些方法都是抽象的,子类实现,我们简单看一下,以便理解连接操作,我们来看连接操作:
//启动连接器线程
从上面可以看出连接操作,首先根据本地socket地址创建SocketChannel,连接远端socket地址,根据IO处理器和SocketChannel构建Io会话,将会话添加到会话关联的IO处理器中,
根据SocketChannel和会话初始化sessionInitializer构建连接请求,添加到连接请求队列,
最后启动连接器线程。
我们来看连接器线程的定义:
//Connector
从上面可以看出,连接器线程首先计算选择超时时间,执行超时选择操作,注册连接请求SocketChannel连接事件到选择器;如果没有任何连接请求SocketChannel需要处理,置空连接器连接线程引用,清空连接请求队列,如果有连接请求已经连接完成,即触发SocketChannel兴趣连接事件,处理连接事件就绪的连接请求,这个过程首先调用finishConnect完成SocketChannel连接后续工作,根据Io处理器和SocketChannel创建会话,初始化会话,添加会话到会话关联的IO处理器;然后处理连接超时的连接请求,即设置连接结果超时异常,添加到连接请求到取消队列;处理取消连接的连接请求,即关闭连接请求关联的SocketChannel。
总结:
抽象拉取连接器内部有一个连接请求队列connectQueue,连接请求取消队列cancelQueue,Io处理器和连接线程引用connectorRef。拉取连接器构造主要初始化会话配置,IO事件执行器和IO处理器。连接操作,首先根据本地socket地址创建SocketChannel,连接远端socket地址,根据IO处理器和SocketChannel构建Io会话,将会话添加到会话关联的IO处理器中,根据SocketChannel和会话初始化sessionInitializer构建连接请求,添加到连接请求队列,最后启动连接器线程。
连接器线程首先计算选择超时时间,执行超时选择操作,注册连接请求SocketChannel连接事件到选择器;如果没有任何连接请求SocketChannel需要处理,置空连接器连接线程引用,清空连接请求队列,如果有连接请求已经连接完成,即触发SocketChannel兴趣连接事件,处理连接事件就绪的连接请求,这个过程首先调用finishConnect完成SocketChannel连接后续工作,根据Io处理器和SocketChannel创建会话,初始化会话,添加会话到会话关联的IO处理器;然后处理连接超时的连接请求,即设置连接结果超时异常,添加到连接请求到取消队列;处理取消连接的连接请求,即关闭连接请求关联的SocketChannel。
引言:
IoConnector接口给Ioservice增加了连接功能,可以连接服务端。连接操作,首先检查连接器状态,本地地址与远程地址是否为空已经与传输元数据地址类型是否匹配,如果连接器Iohandler为null,创建一个对会话操作事件不处理的IoHandler,最后将实际连接操作委托给connect0,待子类实现。
/** * A base class for implementing client transport using a polling strategy. The * underlying sockets will be checked in an active loop and woke up when an * socket needed to be processed. This class handle the logic behind binding, * connecting and disposing the client sockets. A {@link Executor} will be used * for running client connection, and an {@link AbstractPollingIoProcessor} will * be used for processing connected client I/O operations like reading, writing * and closing. * * All the low level methods for binding, connecting, closing need to be * provided by the subclassing implementation. * * @see NioSocketConnector for a example of implementation * @param <H> The type of IoHandler * @param <S> The type of IoSession * * @author [url=http://mina.apache.org]Apache MINA Project[/url] */ public abstract class AbstractPollingIoConnector<S extends AbstractIoSession, H> extends AbstractIoConnector { //连接请求队列 private final Queue<ConnectionRequest> connectQueue = new ConcurrentLinkedQueue<>(); //连接关闭或取消队列 private final Queue<ConnectionRequest> cancelQueue = new ConcurrentLinkedQueue<>(); private final IoProcessor<S> processor;//Io处理器 private final boolean createdProcessor; private final ServiceOperationFuture disposalFuture = new ServiceOperationFuture();//关闭结果 private volatile boolean selectable; /** The connector thread 连接线程引用*/ private final AtomicReference<Connector> connectorRef = new AtomicReference<>(); }
从上面可以看出,抽象拉取连接器内部比较重要的几个变量为连接请求队列connectQueue,连接请求取消队列cancelQueue,
Io处理器,连接线程引用connectorRef。
再来看构造:
/** * Constructor for {@link AbstractPollingIoConnector}. You need to provide a * default session configuration, a class of {@link IoProcessor} which will * be instantiated in a {@link SimpleIoProcessorPool} for better scaling in * multiprocessor systems. The default pool size will be used. * 构造抽象拉取连接器,需要提供默认的会话配置,和一个IO处理器,用于在SimpleIoProcessorPool 中创建实例,默认线程池size,适用与多处理器系统。 * @see SimpleIoProcessorPool * * @param sessionConfig * the default configuration for the managed {@link IoSession} * @param processorClass * a {@link Class} of {@link IoProcessor} for the associated * {@link IoSession} type. */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass) { this(sessionConfig, null, new SimpleIoProcessorPool<S>(processorClass), true); } /** * Constructor for {@link AbstractPollingIoConnector}. You need to provide a * default session configuration, a class of {@link IoProcessor} which will * be instantiated in a {@link SimpleIoProcessorPool} for using multiple * thread for better scaling in multiprocessor systems. * 与上一个方法不同的时,多个个处理器线程池size参数 * @see SimpleIoProcessorPool * * @param sessionConfig * the default configuration for the managed {@link IoSession} * @param processorClass * a {@link Class} of {@link IoProcessor} for the associated * {@link IoSession} type. * @param processorCount * the amount of processor to instantiate for the pool */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass, int processorCount) { this(sessionConfig, null, new SimpleIoProcessorPool<S>(processorClass, processorCount), true); } /** * Constructor for {@link AbstractPollingIoConnector}. You need to provide a * default session configuration, a default {@link Executor} will be created * using {@link Executors#newCachedThreadPool()}. * 需要提供默认会话配置,与上两个方法不同是,传输的Io处理器实例,service共享Io处理器, 一个默认的线程池为Executors#newCachedThreadPool * @see AbstractIoService#AbstractIoService(IoSessionConfig, Executor) * * @param sessionConfig * the default configuration for the managed {@link IoSession} * @param processor * the {@link IoProcessor} for processing the {@link IoSession} * of this transport, triggering events to the bound * {@link IoHandler} and processing the chains of * {@link IoFilter} */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, IoProcessor<S> processor) { this(sessionConfig, null, processor, false); } /** * Constructor for {@link AbstractPollingIoConnector}. You need to provide a * default session configuration and an {@link Executor} for handling I/O * events. If null {@link Executor} is provided, a default one will be * created using {@link Executors#newCachedThreadPool()}. * 与上面不同的是添加IO事件执行器参数Executor * @see AbstractIoService#AbstractIoService(IoSessionConfig, Executor) * * @param sessionConfig * the default configuration for the managed {@link IoSession} * @param executor * the {@link Executor} used for handling asynchronous execution * of I/O events. Can be <code>null</code>. * @param processor * the {@link IoProcessor} for processing the {@link IoSession} * of this transport, triggering events to the bound * {@link IoHandler} and processing the chains of * {@link IoFilter} */ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Executor executor, IoProcessor<S> processor) { this(sessionConfig, executor, processor, false); }
上面所有的构造方法,都是通过AbstractPollingIoConnector(IoSessionConfig sessionConfig, Executor executor, IoProcessor<S> processor,
boolean createdProcessor)来实现,我们来看这个方法:
/** * Constructor for {@link AbstractPollingIoAcceptor}. You need to provide a * default session configuration and an {@link Executor} for handling I/O * events. If null {@link Executor} is provided, a default one will be * created using {@link Executors#newCachedThreadPool()}. * * @see AbstractIoService#AbstractIoService(IoSessionConfig, Executor) * * @param sessionConfig * the default configuration for the managed {@link IoSession} * @param executor * the {@link Executor} used for handling asynchronous execution * of I/O events. Can be <code>null</code>. * @param processor * the {@link IoProcessor} for processing the {@link IoSession} * of this transport, triggering events to the bound * {@link IoHandler} and processing the chains of * {@link IoFilter} * @param createdProcessor * tagging the processor as automatically created, so it will be * automatically disposed */ private AbstractPollingIoConnector(IoSessionConfig sessionConfig, Executor executor, IoProcessor<S> processor, boolean createdProcessor) { //初始化会话配置,IO事件执行器和IO处理器 super(sessionConfig, executor); if (processor == null) { throw new IllegalArgumentException("processor"); } this.processor = processor; this.createdProcessor = createdProcessor; try { init(); selectable = true; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeIoException("Failed to initialize.", e); } finally { if (!selectable) { try { destroy(); } catch (Exception e) { ExceptionMonitor.getInstance().exceptionCaught(e); } } } } /** * Initialize the polling system, will be called at construction time. * 初始化poll系统,在构造是调用 * @throws Exception * any exception thrown by the underlying system calls */ protected abstract void init() throws Exception;
从上面可以看出,拉取连接器构造主要初始化会话配置,IO事件执行器和IO处理器。
再来看其他方法的定义:
/** * Destroy the polling system, will be called when this {@link IoConnector} * implementation will be disposed. * 销毁连接器 * @throws Exception * any exception thrown by the underlying systems calls */ protected abstract void destroy() throws Exception; /** * Create a new client socket handle from a local {@link SocketAddress} * 从本地socket地址创建一个的客户端handle(SocketChannel) * @param localAddress * the socket address for binding the new client socket * @return a new client socket handle * @throws Exception * any exception thrown by the underlying systems calls */ protected abstract H newHandle(SocketAddress localAddress) throws Exception; /** * Connect a newly created client socket handle to a remote * {@link SocketAddress}. This operation is non-blocking, so at end of the * call the socket can be still in connection process. * 根据远端socket和本地socket地址创建一个客户端SocketChannel。此操作为非阻塞模式, 在方法结束,可能能在连接中 * @param handle the client socket handle * @param remoteAddress the remote address where to connect * @return <tt>true</tt> if a connection was established, <tt>false</tt> if * this client socket is in non-blocking mode and the connection * operation is in progress * @throws Exception If the connect failed */ protected abstract boolean connect(H handle, SocketAddress remoteAddress) throws Exception; /** * Finish the connection process of a client socket after it was marked as * ready to process by the {@link #select(int)} call. The socket will be * connected or reported as connection failed. * 在选择操作标记客户端SocketChannel连接完毕调用 * @param handle * the client socket handle to finish to connect * @return true if the socket is connected * @throws Exception * any exception thrown by the underlying systems calls */ protected abstract boolean finishConnect(H handle) throws Exception; /** * Create a new {@link IoSession} from a connected socket client handle. * Will assign the created {@link IoSession} to the given * {@link IoProcessor} for managing future I/O events. * 根据SocketChannel和IO处理器创建一个IO会话 * @param processor * the processor in charge of this session * @param handle * the newly connected client socket handle * @return a new {@link IoSession} * @throws Exception * any exception thrown by the underlying systems calls */ protected abstract S newSession(IoProcessor<S> processor, H handle) throws Exception; /** * Close a client socket. * 关闭SocketChannel客户端 * @param handle * the client socket * @throws Exception * any exception thrown by the underlying systems calls */ protected abstract void close(H handle) throws Exception; /** * Interrupt the {@link #select(int)} method. Used when the poll set need to * be modified. 中断选择操作 */ protected abstract void wakeup(); /** * Check for connected sockets, interrupt when at least a connection is * processed (connected or failed to connect). All the client socket * descriptors processed need to be returned by {@link #selectedHandles()} * 检查客户端来接服务器是否成功,当至少一个连接操作完成时中断(消除中断位),所有客户端描述符可以通过 #selectedHandles方法返回 * @param timeout The timeout for the select() method * @return The number of socket having received some data * @throws Exception any exception thrown by the underlying systems calls */ protected abstract int select(int timeout) throws Exception; /** * {@link Iterator} for the set of client sockets found connected or failed * to connect during the last {@link #select(int)} call. * 获取在上次选择操作调用后,连接成功或失败的客户端handler集 * @return the list of client socket handles to process */ protected abstract Iterator<H> selectedHandles(); /** * {@link Iterator} for all the client sockets polled for connection. * 连接器所有poll的客户端 * @return the list of client sockets currently polled for connection */ protected abstract Iterator<H> allHandles(); /** * Register a new client socket for connection, add it to connection polling * 注册一个连接客户端,添加到连接polling系统 * @param handle * client socket handle * @param request * the associated {@link ConnectionRequest} * @throws Exception * any exception thrown by the underlying systems calls */ protected abstract void register(H handle, ConnectionRequest request) throws Exception; /** * get the {@link ConnectionRequest} for a given client socket handle * 获取连接客户端SocketChannel的连接请求 * @param handle * the socket client handle * @return the connection request if the socket is connecting otherwise * <code>null</code> */ protected abstract ConnectionRequest getConnectionRequest(H handle);
上面这些方法都是抽象的,子类实现,我们简单看一下,以便理解连接操作,我们来看连接操作:
* * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") protected final ConnectFuture connect0(SocketAddress remoteAddress, SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer) { H handle = null; boolean success = false; try { //根据本地socket地址创建SocketChannel,连接远端socket地址 handle = newHandle(localAddress); if (connect(handle, remoteAddress)) { ConnectFuture future = new DefaultConnectFuture(); //根据IO处理器和SocketChannel构建Io会话 S session = newSession(processor, handle); initSession(session, future, sessionInitializer); // Forward the remaining process to the IoProcessor. //将会话添加到会话关联的IO处理器中 session.getProcessor().add(session); success = true; return future; } success = true; } catch (Exception e) { return DefaultConnectFuture.newFailedFuture(e); } finally { if (!success && handle != null) { try { close(handle); } catch (Exception e) { ExceptionMonitor.getInstance().exceptionCaught(e); } } } //根据SocketChannel和会话初始化sessionInitializer构建连接请求,添加到连接请求队列。 ConnectionRequest request = new ConnectionRequest(handle, sessionInitializer); connectQueue.add(request); //启动连接器线程 startupWorker(); wakeup(); return request; }
//启动连接器线程
private void startupWorker() { if (!selectable) { connectQueue.clear(); cancelQueue.clear(); } Connector connector = connectorRef.get(); if (connector == null) { connector = new Connector(); if (connectorRef.compareAndSet(null, connector)) { executeWorker(connector); } } }
从上面可以看出连接操作,首先根据本地socket地址创建SocketChannel,连接远端socket地址,根据IO处理器和SocketChannel构建Io会话,将会话添加到会话关联的IO处理器中,
根据SocketChannel和会话初始化sessionInitializer构建连接请求,添加到连接请求队列,
最后启动连接器线程。
我们来看连接器线程的定义:
//Connector
private class Connector implements Runnable { /** * {@inheritDoc} */ @Override public void run() { assert connectorRef.get() == this; int nHandles = 0; while (selectable) { try { // the timeout for select shall be smaller of the connect // timeout or 1 second... //选择超时时间 int timeout = (int) Math.min(getConnectTimeoutMillis(), 1000L); //执行选择操作 int selected = select(timeout); //从连接请求队列poll连接请求,注册连接请求SocketChannel连接事件到选择器 nHandles += registerNew(); // get a chance to get out of the connector loop, if we // don't have any more handles //如果没有任何连接请求SocketChannel需要处理 if (nHandles == 0) { //置空连接器连接线程引用 connectorRef.set(null); //清空连接请求队列 if (connectQueue.isEmpty()) { assert connectorRef.get() != this; break; } if (!connectorRef.compareAndSet(null, this)) { assert connectorRef.get() != this; break; } assert connectorRef.get() == this; } //如果有连接请求已经连接完成,即触发SocketChannel兴趣连接事件 if (selected > 0) { //处理连接事件就绪的连接请求 nHandles -= processConnections(selectedHandles()); } //处理超时的连接请求 processTimedOutSessions(allHandles()); //处理取消连接的连接请求 nHandles -= cancelKeys(); } catch (ClosedSelectorException cse) { // If the selector has been closed, we can exit the loop ExceptionMonitor.getInstance().exceptionCaught(cse); break; } catch (Exception e) { ExceptionMonitor.getInstance().exceptionCaught(e); try { Thread.sleep(1000); } catch (InterruptedException e1) { ExceptionMonitor.getInstance().exceptionCaught(e1); } } } if (selectable && isDisposing()) { selectable = false; try { if (createdProcessor) { //释放Io处理器 processor.dispose(); } } finally { try { synchronized (disposalLock) { if (isDisposing()) { //销毁连接器 destroy(); } } } catch (Exception e) { ExceptionMonitor.getInstance().exceptionCaught(e); } finally { //设置连接器已关闭 disposalFuture.setDone(); } } } } //注册连接请求SocketChannel连接事件到选择器 private int registerNew() { int nHandles = 0; for (;;) { //从连接队列获取连接请求 ConnectionRequest req = connectQueue.poll(); if (req == null) { break; } //从连接请求获取客户端SocketChannel H handle = req.handle; try { //注册SocketChannel连接事件到选择器 register(handle, req); nHandles++; } catch (Exception e) { req.setException(e); try { close(handle); } catch (Exception e2) { ExceptionMonitor.getInstance().exceptionCaught(e2); } } } return nHandles; } //处理取消连接的连接请求 private int cancelKeys() { int nHandles = 0; //遍历取消连接请求队列,关闭连接请求关联的SocketChannel for (;;) { ConnectionRequest req = cancelQueue.poll(); if (req == null) { break; } H handle = req.handle; try { close(handle); } catch (Exception e) { ExceptionMonitor.getInstance().exceptionCaught(e); } finally { nHandles++; } } if (nHandles > 0) { wakeup(); } return nHandles; } /** * Process the incoming connections, creating a new session for each valid * connection. 处理连接事件就绪的连接请求 */ private int processConnections(Iterator<H> handlers) { int nHandles = 0; // Loop on each connection request //遍历连接请求队列的SocketChannel while (handlers.hasNext()) { H handle = handlers.next(); handlers.remove(); ConnectionRequest connectionRequest = getConnectionRequest(handle); if (connectionRequest == null) { continue; } boolean success = false; try { //调用finishConnect完成SocketChannel连接后续工作 if (finishConnect(handle)) { //根据Io处理器和SocketChannel创建会话 S session = newSession(processor, handle); //初始化会话 initSession(session, connectionRequest, connectionRequest.getSessionInitializer()); // Forward the remaining process to the IoProcessor. //添加会话到会话关联的IO处理器 session.getProcessor().add(session); nHandles++; } success = true; } catch (Exception e) { //设置连接请求异常 connectionRequest.setException(e); } finally { if (!success) { // The connection failed, we have to cancel it. //如果处理失败,则添加连接请求到取消队列 cancelQueue.offer(connectionRequest); } } } return nHandles; } //处理连接超时的连接请求 private void processTimedOutSessions(Iterator<H> handles) { long currentTime = System.currentTimeMillis(); //遍历所有连接请求的SocketChannel,设置连接结果超时异常,添加到连接请求到取消队列 while (handles.hasNext()) { H handle = handles.next(); ConnectionRequest connectionRequest = getConnectionRequest(handle); if ((connectionRequest != null) && (currentTime >= connectionRequest.deadline)) { connectionRequest.setException(new ConnectException("Connection timed out.")); cancelQueue.offer(connectionRequest); } } } }
从上面可以看出,连接器线程首先计算选择超时时间,执行超时选择操作,注册连接请求SocketChannel连接事件到选择器;如果没有任何连接请求SocketChannel需要处理,置空连接器连接线程引用,清空连接请求队列,如果有连接请求已经连接完成,即触发SocketChannel兴趣连接事件,处理连接事件就绪的连接请求,这个过程首先调用finishConnect完成SocketChannel连接后续工作,根据Io处理器和SocketChannel创建会话,初始化会话,添加会话到会话关联的IO处理器;然后处理连接超时的连接请求,即设置连接结果超时异常,添加到连接请求到取消队列;处理取消连接的连接请求,即关闭连接请求关联的SocketChannel。
总结:
抽象拉取连接器内部有一个连接请求队列connectQueue,连接请求取消队列cancelQueue,Io处理器和连接线程引用connectorRef。拉取连接器构造主要初始化会话配置,IO事件执行器和IO处理器。连接操作,首先根据本地socket地址创建SocketChannel,连接远端socket地址,根据IO处理器和SocketChannel构建Io会话,将会话添加到会话关联的IO处理器中,根据SocketChannel和会话初始化sessionInitializer构建连接请求,添加到连接请求队列,最后启动连接器线程。
连接器线程首先计算选择超时时间,执行超时选择操作,注册连接请求SocketChannel连接事件到选择器;如果没有任何连接请求SocketChannel需要处理,置空连接器连接线程引用,清空连接请求队列,如果有连接请求已经连接完成,即触发SocketChannel兴趣连接事件,处理连接事件就绪的连接请求,这个过程首先调用finishConnect完成SocketChannel连接后续工作,根据Io处理器和SocketChannel创建会话,初始化会话,添加会话到会话关联的IO处理器;然后处理连接超时的连接请求,即设置连接结果超时异常,添加到连接请求到取消队列;处理取消连接的连接请求,即关闭连接请求关联的SocketChannel。
发表评论
-
Mina 报文连接器(NioDatagramConnector)
2017-06-14 08:46 1417Mina 抽象Polling连接器(A ... -
Mina 报文监听器NioDatagramAcceptor二(发送会话消息等)
2017-06-13 16:01 1541Mina 报文监听器NioDatagramAcceptor一( ... -
Mina 报文监听器NioDatagramAcceptor一(初始化,Io处理器)
2017-06-13 09:51 2575Mina Io监听器接口定义及抽象实现:http://dona ... -
Mina 报文通信简单示例
2017-06-12 09:01 2585MINA TCP简单通信实例:http://donald-dr ... -
Mina socket连接器(NioSocketConnector)
2017-06-12 08:37 4772Mina 抽象Polling连接器(AbstractPolli ... -
Mina 连接器接口定义及抽象实现(IoConnector )
2017-06-11 13:46 1831Mina IoService接口定义及抽象实现:http:// ... -
Mina socket监听器(NioSocketAcceptor)
2017-06-09 08:44 3418Mina IoService接口定义及抽象实现:http:// ... -
Mina 抽象polling监听器
2017-06-08 22:32 784Mina Io监听器接口定义及抽象实现:http://dona ... -
Mina Io监听器接口定义及抽象实现
2017-06-07 13:02 1349Mina IoService接口定义及抽象实现:http:// ... -
Mina IoService接口定义及抽象实现
2017-06-06 23:44 1195Mina IoHandler接口定义:http://donal ... -
Mina Nio会话(Socket,DataGram)
2017-06-06 12:53 1209Mina Socket会话配置:http://donald-d ... -
Mina 抽象Io会话
2017-06-05 22:45 1014Mina Io会话接口定义:http://donald-dra ... -
Mina Io会话接口定义
2017-06-04 23:15 1166Mina Nio处理器:http://donald-drape ... -
Mina Nio处理器
2017-06-04 22:19 742Mina Io处理器抽象实现:http://donald-dr ... -
Mina Io处理器抽象实现
2017-06-03 23:52 1148Mina 过滤链抽象实现:http://donald-drap ... -
Mina IoHandler接口定义
2017-06-01 21:30 1734Mina 过滤链抽象实现:http://donald-drap ... -
MINA 多路复用协议编解码器工厂二(多路复用协议解码器)
2017-06-01 12:52 2273MINA 多路复用协议编解码器工厂一(多路复用协议编码器): ... -
MINA 多路复用协议编解码器工厂一(多路复用协议编码器)
2017-05-31 22:22 1868MINA 多路分离解码器实例:http://donald-dr ... -
Mina 累计协议解码器
2017-05-31 00:09 1229MINA 编解码器实例:http://donald-drape ... -
Mina 协议编解码过滤器三(会话write与消息接收过滤)
2017-05-28 07:22 1750Mina 协议编解码过滤器一(协议编解码工厂、协议编码器): ...
相关推荐
Apache Mina是一个流行的Java框架,专门用于简化和优化网络应用开发,它支持多种协议如TCP/IP、UDP/IP等,并提供了长连接和短连接的支持。在这个实例中,我们将探讨如何使用Mina实现长连接和短连接。 首先,理解长...
Mina提供了一种事件驱动的模型,通过IoSession接口来管理连接,包括读写数据、添加监听器、关闭连接等操作。IoSession是连接状态的容器,包含了会话中的所有信息,如远程地址、本地地址、缓冲区大小、已发送和接收的...
**mina自定义编解码器详解** mina是一个Java开发的网络通信框架,广泛应用于TCP和UDP协议的服务器和客户端开发。在mina框架中,编解码器(Codec)扮演着至关重要的角色,它负责将应用层的数据转换为网络传输的字节...
本文将深入探讨Mina框架中的长连接与短连接,并通过提供的Minaclient和MinaHost工程实例进行详细解析。 首先,我们需要了解什么是长连接和短连接。在TCP/IP通信中,短连接是指一次完整的通信过程(如HTTP请求)结束...
5. **IoService:** 提供了服务端和客户端的抽象,负责实际的I/O操作,如Acceptor用于监听和接受新的连接,Connector用于建立到远程服务器的连接。 **实现长连接的关键步骤:** 1. **配置Acceptor:** 创建一个...
在`mina src`压缩包中,可能包含MINA框架的源代码,你可以通过阅读这些源码来深入理解MINA的工作原理,特别是过滤器和解码器的实现。这对于学习MINA、理解和定制自己的网络服务非常有帮助。同时,结合提供的博客链接...
综上所述,MINA长连接框架在实现服务器与Android客户端通讯时,涉及到网络编程、数据传输协议、异常处理、过滤器机制、长连接维护等多个技术要点,开发者需要根据实际需求进行合理的架构设计和优化。通过MINA提供的...
Socket通信和MINA长连接是网络编程中的两个关键概念,主要应用于服务器与客户端之间的数据交互。在移动应用开发,特别是需要实时推送功能时,这两种技术显得尤为重要。 **Socket通信** Socket,也称为套接字,是...
在这个"mina 长连接 客户端+服务端"的示例中,我们将探讨如何使用Mina实现长连接以及收发消息的功能。 长连接是网络通信中的一种模式,与短连接相对。短连接在每次通信后都会关闭连接,而长连接则保持连接状态,...
**Android-MinaSocket:基于Mina的高效Socket长连接库** 在移动应用开发中,尤其是Android平台,实时性与稳定性是许多应用场景的核心需求,比如在线游戏、即时通讯、物联网设备等。在这种背景下,使用Socket进行长...
基于mina的短连接组件(内含binary与source包),关于本组件的说明见配套的文章:https://blog.csdn.net/smartcore/article/details/80084634
文件"MinaSocket"可能包含了实现上述功能的详细代码,包括服务端的Acceptor配置、过滤器设置、事件处理器编写,以及客户端的Socket连接、数据发送和接收等。通过阅读和理解这些代码,你可以更好地掌握Mina与Socket...
本文将深入探讨如何在Mina中自定义编码解码器,这对于实现特定的网络通信协议至关重要。 首先,了解Mina的编码解码器架构是必要的。Mina使用了Chain of Responsibility设计模式,通过Filter链来处理进来的数据。...
《mina UDP 数据库连接池详解》 在现代的网络编程中,UDP(User Datagram Protocol)因其无连接、轻量级的特性,在某些实时性要求高的场景下被广泛应用。然而,UDP的数据传输通常缺乏稳定性,因此如何高效且可靠地...
MINA的核心设计思想是将网络通信过程中的I/O操作抽象化,使得开发者可以专注于业务逻辑,而无需关心底层网络通信的细节。在实际应用中,我们经常需要根据业务需求定制解编码器来处理网络传输的数据。本文将深入探讨...
在Mina的架构中,IoService接口负责在一个线程上建立套接字连接,并通过Selector监听连接状态。当IoSession关闭时,如果不通过IoService的close方法,实际连接并不会断开。 IoProcessor接口则在另一个线程上处理...
6. **Transport Layer**:Mina支持多种传输层实现,如TCP、UDP等,这些都抽象为IoAcceptor和IoConnector接口,方便开发者使用。 深入研究源码,你可能会关注以下方面: - **mina-core**模块:这是Mina的核心库,...
在这个实例中,我们将深入探讨如何利用Apache Mina实现TCP的长连接和短连接。 首先,TCP(传输控制协议)是互联网上广泛使用的面向连接的协议,它保证了数据的可靠传输。TCP连接分为两种类型:长连接和短连接。 1....
2.mina若有空闲连接则使用已有连接,若无则新建mina连接; 3.mina空闲连接超过保活时间25分钟后,自动删除; 4.mina发送指令后,接收指定时长内收到的消息; <groupId>org.apache.mina <artifactId>mina-core ...