`
Donald_Draper
  • 浏览: 980019 次
社区版块
存档分类
最新评论

Mina 抽象Polling连接器(AbstractPollingIoConnector)

    博客分类:
  • Mina
阅读更多
Mina 连接器接口定义及抽象实现(IoConnector ):http://donald-draper.iteye.com/blog/2378936
引言:
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。

0
2
分享到:
评论

相关推荐

    Mina实现长连接和短连接实例

    Apache Mina是一个流行的Java框架,专门用于简化和优化网络应用开发,它支持多种协议如TCP/IP、UDP/IP等,并提供了长连接和短连接的支持。在这个实例中,我们将探讨如何使用Mina实现长连接和短连接。 首先,理解长...

    mina连接 mina心跳连接 mina断线重连

    Mina提供了一种事件驱动的模型,通过IoSession接口来管理连接,包括读写数据、添加监听器、关闭连接等操作。IoSession是连接状态的容器,包含了会话中的所有信息,如远程地址、本地地址、缓冲区大小、已发送和接收的...

    mina自定义编解码器详解

    **mina自定义编解码器详解** mina是一个Java开发的网络通信框架,广泛应用于TCP和UDP协议的服务器和客户端开发。在mina框架中,编解码器(Codec)扮演着至关重要的角色,它负责将应用层的数据转换为网络传输的字节...

    Mina长连接短连接实例

    本文将深入探讨Mina框架中的长连接与短连接,并通过提供的Minaclient和MinaHost工程实例进行详细解析。 首先,我们需要了解什么是长连接和短连接。在TCP/IP通信中,短连接是指一次完整的通信过程(如HTTP请求)结束...

    使用MINA实现长连接

    5. **IoService:** 提供了服务端和客户端的抽象,负责实际的I/O操作,如Acceptor用于监听和接受新的连接,Connector用于建立到远程服务器的连接。 **实现长连接的关键步骤:** 1. **配置Acceptor:** 创建一个...

    MINA 协议解码过滤器

    在`mina src`压缩包中,可能包含MINA框架的源代码,你可以通过阅读这些源码来深入理解MINA的工作原理,特别是过滤器和解码器的实现。这对于学习MINA、理解和定制自己的网络服务非常有帮助。同时,结合提供的博客链接...

    MINA长连接框架实现通讯

    综上所述,MINA长连接框架在实现服务器与Android客户端通讯时,涉及到网络编程、数据传输协议、异常处理、过滤器机制、长连接维护等多个技术要点,开发者需要根据实际需求进行合理的架构设计和优化。通过MINA提供的...

    socket通信,mina长连接通信

    Socket通信和MINA长连接是网络编程中的两个关键概念,主要应用于服务器与客户端之间的数据交互。在移动应用开发,特别是需要实时推送功能时,这两种技术显得尤为重要。 **Socket通信** Socket,也称为套接字,是...

    mina 长连接 客户端+服务端

    在这个"mina 长连接 客户端+服务端"的示例中,我们将探讨如何使用Mina实现长连接以及收发消息的功能。 长连接是网络通信中的一种模式,与短连接相对。短连接在每次通信后都会关闭连接,而长连接则保持连接状态,...

    Android-MinaSocket一款基于Mina的Socket长连接库

    **Android-MinaSocket:基于Mina的高效Socket长连接库** 在移动应用开发中,尤其是Android平台,实时性与稳定性是许多应用场景的核心需求,比如在线游戏、即时通讯、物联网设备等。在这种背景下,使用Socket进行长...

    基于mina的短连接组件

    基于mina的短连接组件(内含binary与source包),关于本组件的说明见配套的文章:https://blog.csdn.net/smartcore/article/details/80084634

    Mina+Socket通信

    文件"MinaSocket"可能包含了实现上述功能的详细代码,包括服务端的Acceptor配置、过滤器设置、事件处理器编写,以及客户端的Socket连接、数据发送和接收等。通过阅读和理解这些代码,你可以更好地掌握Mina与Socket...

    mina自定义编码解码器

    本文将深入探讨如何在Mina中自定义编码解码器,这对于实现特定的网络通信协议至关重要。 首先,了解Mina的编码解码器架构是必要的。Mina使用了Chain of Responsibility设计模式,通过Filter链来处理进来的数据。...

    mina UDP 数据库连接池

    《mina UDP 数据库连接池详解》 在现代的网络编程中,UDP(User Datagram Protocol)因其无连接、轻量级的特性,在某些实时性要求高的场景下被广泛应用。然而,UDP的数据传输通常缺乏稳定性,因此如何高效且可靠地...

    mina框架自定义解编码器

    MINA的核心设计思想是将网络通信过程中的I/O操作抽象化,使得开发者可以专注于业务逻辑,而无需关心底层网络通信的细节。在实际应用中,我们经常需要根据业务需求定制解编码器来处理网络传输的数据。本文将深入探讨...

    java-mina通信框架详解.docx

    在Mina的架构中,IoService接口负责在一个线程上建立套接字连接,并通过Selector监听连接状态。当IoSession关闭时,如果不通过IoService的close方法,实际连接并不会断开。 IoProcessor接口则在另一个线程上处理...

    apache-mina-2.0.4.rar_apache mina_mina

    6. **Transport Layer**:Mina支持多种传输层实现,如TCP、UDP等,这些都抽象为IoAcceptor和IoConnector接口,方便开发者使用。 深入研究源码,你可能会关注以下方面: - **mina-core**模块:这是Mina的核心库,...

    基于Apache Mina实现的TCP长连接和短连接实例

    在这个实例中,我们将深入探讨如何利用Apache Mina实现TCP的长连接和短连接。 首先,TCP(传输控制协议)是互联网上广泛使用的面向连接的协议,它保证了数据的可靠传输。TCP连接分为两种类型:长连接和短连接。 1....

    mina socket客户度工程相关类

    2.mina若有空闲连接则使用已有连接,若无则新建mina连接; 3.mina空闲连接超过保活时间25分钟后,自动删除; 4.mina发送指令后,接收指定时长内收到的消息; &lt;groupId&gt;org.apache.mina &lt;artifactId&gt;mina-core ...

Global site tag (gtag.js) - Google Analytics