- 浏览: 950679 次
文章分类
- 全部博客 (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 Nio处理器:http://donald-draper.iteye.com/blog/2377725
引言:
前面的文章我们看了Nio处理器,先来回顾一下:
NioProcessor内部有一个选择器Selector,一个可重入读写锁用于控制选择器相关的操作,构造主要是初始化线程执行器和选择器。Nio处理器的选择操作,唤醒等操作,实际通过内部的选择器完成。初始化会话,主要是配置会话通道为非阻塞模式,注册会话通道读事件到选择器。注册新选择器,主要是注册旧选择器的选择key(集合)关联的会话,通道,及通道兴趣事件集到新的选择器;会话时附加在通道选择key的Attachment上。处理器处理会话读写操作,主要是通过会话关联的通道完成。关闭会话主要是关闭会话关联的字节通道和取消会话关联选择key。
今天我们来看一下Io会话的定义:
附:
//TransportType
//TrafficMask
引言:
前面的文章我们看了Nio处理器,先来回顾一下:
NioProcessor内部有一个选择器Selector,一个可重入读写锁用于控制选择器相关的操作,构造主要是初始化线程执行器和选择器。Nio处理器的选择操作,唤醒等操作,实际通过内部的选择器完成。初始化会话,主要是配置会话通道为非阻塞模式,注册会话通道读事件到选择器。注册新选择器,主要是注册旧选择器的选择key(集合)关联的会话,通道,及通道兴趣事件集到新的选择器;会话时附加在通道选择key的Attachment上。处理器处理会话读写操作,主要是通过会话关联的通道完成。关闭会话主要是关闭会话关联的字节通道和取消会话关联选择key。
今天我们来看一下Io会话的定义:
/** * A handle which represents connection between two endpoints regardless of * transport types. * * {@link IoSession} provides user-defined attributes. User-defined attributes * are application-specific data which is 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. * * <h3>Adjusting Transport Type Specific Properties</h3> * <p> * You can simply downcast the session to an appropriate subclass. * * * <h3>Thread Safety</h3> * * {@link IoSession} is thread-safe. But please note that performing * more than one {@link #write(Object)} calls at the same time will * cause the {@link IoFilter#filterWrite(IoFilter.NextFilter, IoSession, IoFilter.WriteRequest)} * is executed simnutaneously, and therefore you have to make sure the * {@link IoFilter} implementations you're using are thread-safe, too. * * * @author The Apache Directory Project (mina-dev@directory.apache.org) * @version $Rev$, $Date$ */ public interface IoSession { /** * Returns the {@link IoService} which provides I/O service to this session. 获取会话关联的IoService */ IoService getService(); /** * Returns the {@link IoServiceConfig} of this session. 获取会话关联的IoService配置 */ IoServiceConfig getServiceConfig(); /** * Returns the {@link IoHandler} which handles this session. 获取会话Iohandler */ IoHandler getHandler(); /** * Returns the configuration of this session. 获取会话配置 */ IoSessionConfig getConfig(); /** * Returns the filter chain that only affects this session. 获取会话过滤链 */ IoFilterChain getFilterChain(); /** * Writes the specified <code>message</code> to remote peer. This * operation is asynchronous; {@link IoHandler#messageSent(IoSession, Object)} * will be invoked when the message is actually sent to remote peer. * You can also wait for the returned {@link WriteFuture} if you want * to wait for the message actually written. 发送消息给远端的peer。此操作是异步的,当消息实际发送到远端peer时,会调用 IoHandler#messageSent方法法。如果想等待消息实际发送完,可以等待WriteFuture。 */ WriteFuture write(Object message); /** * Closes this session immediately. This operation is asynthronous. * Wait for the returned {@link CloseFuture} if you want to wait for * the session actually closed. 立刻关闭会话。此操作为异步的。如果想要等待会话实际完成关闭,可以等待CloseFuture */ CloseFuture close(); /** * Returns an attachment of this session. * This method is identical with <tt>getAttribute( "" )</tt>. 返回会话附加物 */ Object getAttachment(); /** * Sets an attachment of this session. * This method is identical with <tt>setAttribute( "", attachment )</tt>. * 设置会话附加物 * @return Old attachment. <tt>null</tt> if it is new. */ Object setAttachment(Object attachment); /** * Returns the value of user-defined attribute of this session. * 获取会话属性key对一个的属性值 * @param key the key of the attribute * @return <tt>null</tt> if there is no attribute with the specified key */ Object getAttribute(String key); /** * Sets a user-defined attribute. * 设置会话属性 * @param key the key of the attribute * @param value the value of the attribute * @return The old value of the attribute. <tt>null</tt> if it is new. */ Object setAttribute(String key, Object value); /** * Sets a user defined attribute without a value. This is useful when * you just want to put a 'mark' attribute. Its value is set to * {@link Boolean#TRUE}. * 设置会话无值属性 * @param key the key of the attribute * @return The old value of the attribute. <tt>null</tt> if it is new. */ Object setAttribute(String key); /** * Removes a user-defined attribute with the specified key. * 移除会话属性 * @return The old value of the attribute. <tt>null</tt> if not found. */ Object removeAttribute(String key); /** * Returns <tt>true</tt> if this session contains the attribute with * the specified <tt>key</tt>. 判断是否包含属性key */ boolean containsAttribute(String key); /** * Returns the set of keys of all user-defined attributes. 获取会话所有属性 */ Set getAttributeKeys(); /** * Returns transport type of this session. 获取会话transport类型,socket,Datagram,vmpipe */ TransportType getTransportType(); /** * Returns <code>true</code> if this session is connected with remote peer. 会话是否连接 */ boolean isConnected(); /** * Returns <code>true</tt> if and only if this session is being closed * (but not disconnected yet) or is closed. 会话是否关闭 */ boolean isClosing(); /** * Returns the {@link CloseFuture} of this session. This method returns * the same instance whenever user calls it. 获取会话关闭结果 */ CloseFuture getCloseFuture(); /** * Returns the socket address of remote peer. 获取会话远端peer地址 */ SocketAddress getRemoteAddress(); /** * Returns the socket address of local machine which is associated with this * session. 获取会话本地地址 */ SocketAddress getLocalAddress(); /** * Returns the socket address of the {@link IoService} listens to to manage * this session. If this session is managed by {@link IoAcceptor}, it * returns the {@link SocketAddress} which is specified as a parameter of * {@link IoAcceptor#bind(SocketAddress, IoHandler)}. If this session is * managed by {@link IoConnector}, this method returns the same address with * that of {@link #getRemoteAddress()}. 获取IoService监听管理会话的地址。如果会话被IoAcceptor管理,返回的为IoAcceptor#bind(SocketAddress, IoHandler) 的参数地址。如果会话为IoConnector,则返回的远端peer地址。 */ SocketAddress getServiceAddress(); /** * Returns idle time for the specified type of idleness in seconds. 返回空闲状态的空闲时间s */ int getIdleTime(IdleStatus status); /** * Returns idle time for the specified type of idleness in milliseconds. 返回空闲状态的空闲时间ms */ long getIdleTimeInMillis(IdleStatus status); /** * Sets idle time for the specified type of idleness in seconds. 设置空闲状态的空闲时间 */ void setIdleTime(IdleStatus status, int idleTime); /** * Returns write timeout in seconds. 获取写超时时间s */ int getWriteTimeout(); /** * Returns write timeout in milliseconds. 获取写超时时间ms */ long getWriteTimeoutInMillis(); /** * Sets write timeout in seconds. 设置写超时时间 */ void setWriteTimeout(int writeTimeout); /** * Returns the current {@link TrafficMask} of this session. 返回会话传输状态(读写) */ TrafficMask getTrafficMask(); /** * Sets the {@link TrafficMask} of this session which will result * the parent {@link IoService} to start to control the traffic * of this session immediately. 设置会话传输状态,这将引起Io服务,开始控制会话传输 */ void setTrafficMask(TrafficMask trafficMask); /** * A shortcut method for {@link #setTrafficMask(TrafficMask)} that * suspends read operations for this session. 暂定会话读操作 */ void suspendRead(); /** * A shortcut method for {@link #setTrafficMask(TrafficMask)} that * suspends write operations for this session. 暂定会话写操作 */ void suspendWrite(); /** * A shortcut method for {@link #setTrafficMask(TrafficMask)} that * resumes read operations for this session. 恢复会话读操作 */ void resumeRead(); /** * A shortcut method for {@link #setTrafficMask(TrafficMask)} that * resumes write operations for this session. 恢复会话写操作 */ void resumeWrite(); /** * Returns the total number of bytes which were read from this session. 获取从会话读取的字节数 */ long getReadBytes(); /** * Returns the total number of bytes which were written to this session. 获取会话写的字节数 */ long getWrittenBytes(); /** * Returns the total number of messages which were read and decoded from this session. 获取从会话读取或解码的消息数 */ long getReadMessages(); /** * Returns the total number of messages which were written and encoded by this session. 获取会话发送消息和编码消息的数量 */ long getWrittenMessages(); /** * Returns the total number of write requests which were written to this session. 获取会话写请求的数量 */ long getWrittenWriteRequests(); /** * Returns the number of write requests which are scheduled to be written * to this session. 获取会话写请求实际被调度的数量,即实际发送数量 */ int getScheduledWriteRequests(); /** * Returns the number of bytes which are scheduled to be written to this * session. 获取会话实际发送字节数 */ int getScheduledWriteBytes(); /** * Returns the time in millis when this session is created. 获取会话创建时间 */ long getCreationTime(); /** * Returns the time in millis when I/O occurred lastly. 获取会话上一次发送IO操作的时间 */ long getLastIoTime(); /** * Returns the time in millis when read operation occurred lastly. 获取会话上一次读操作的时间 */ long getLastReadTime(); /** * Returns the time in millis when write operation occurred lastly. 获取会话上一次写操作的时间 */ long getLastWriteTime(); /** * Returns <code>true</code> if this session is idle for the specified * {@link IdleStatus}. 判断会话是否处理空闲状态status */ boolean isIdle(IdleStatus status); /** * Returns the number of the fired continuous <tt>sessionIdle</tt> events * for the specified {@link IdleStatus}. 获取会话处于空闲状态status的次数 * <p> * If <tt>sessionIdle</tt> event is fired first after some time after I/O, * <tt>idleCount</tt> becomes <tt>1</tt>. <tt>idleCount</tt> resets to * <tt>0</tt> if any I/O occurs again, otherwise it increases to * <tt>2</tt> and so on if <tt>sessionIdle</tt> event is fired again without * any I/O between two (or more) <tt>sessionIdle</tt> events. */ int getIdleCount(IdleStatus status); /** * Returns the time in millis when the last <tt>sessionIdle</tt> event * is fired for the specified {@link IdleStatus}. 获取会话上次处于空闲状态status的时间 */ long getLastIdleTime(IdleStatus status); }
附:
//TransportType
/** * Represents network transport types. * MINA provides three transport types by default: * [list] * [*]{@link #SOCKET} - TCP/IP * [*]{@link #DATAGRAM} - UDP/IP * <li>{@link #VM_PIPE} - in-VM pipe support (only available in protocol * layer</li> * [/list] * <p> * You can also create your own transport type. Please refer to * {@link #TransportType(String[], boolean)}. * * @author The Apache Directory Project (mina-dev@directory.apache.org) * @version $Rev$, $Date$ */ public final class TransportType implements Serializable { private static final long serialVersionUID = 3258132470497883447L; private static final Map name2type = new HashMap(); private final String[] names; private final transient boolean connectionless; private final transient Class envelopeType; /** * Transport type: TCP/IP (Registry name: <tt>"SOCKET"</tt> or <tt>"TCP"</tt>) */ public static final TransportType SOCKET = new TransportType(new String[] { "SOCKET", "TCP" }, false); /** * Transport type: UDP/IP (Registry name: <tt>"DATAGRAM"</tt> or <tt>"UDP"</tt>) */ public static final TransportType DATAGRAM = new TransportType( new String[] { "DATAGRAM", "UDP" }, true); /** * Transport type: in-VM pipe (Registry name: <tt>"VM_PIPE"</tt>) * Please refer to * [url=../protocol/vmpipe/package-summary.htm]<tt>org.apache.mina.protocol.vmpipe</tt>[/url] * package. */ public static final TransportType VM_PIPE = new TransportType( new String[] { "VM_PIPE" }, Object.class, false); ... }
//TrafficMask
/** * A type-safe mask that is used to control the traffic of {@link IoSession} * with {@link IoSession#setTrafficMask(TrafficMask)}. * * @author The Apache Directory Project (mina-dev@directory.apache.org) * @version $Rev$, $Date$ */ public class TrafficMask { private final int interestOps; private final String name; /** * This mask suspends both reads and writes. */ public static final TrafficMask NONE = new TrafficMask(0, "none"); /** * This mask suspends writes, and resumes reads if reads were suspended. */ public static final TrafficMask READ = new TrafficMask( SelectionKey.OP_READ, "read"); /** * This mask suspends reads, and resumes writes if writes were suspended. */ public static final TrafficMask WRITE = new TrafficMask( SelectionKey.OP_WRITE, "write"); /** * This mask resumes both reads and writes if any of them were suspended. */ public static final TrafficMask ALL = new TrafficMask(SelectionKey.OP_READ | SelectionKey.OP_WRITE, "all"); ... }
发表评论
-
Mina 报文连接器(NioDatagramConnector)
2017-06-14 08:46 1339Mina 抽象Polling连接器(A ... -
Mina 报文监听器NioDatagramAcceptor二(发送会话消息等)
2017-06-13 16:01 1489Mina 报文监听器NioDatagramAcceptor一( ... -
Mina 报文监听器NioDatagramAcceptor一(初始化,Io处理器)
2017-06-13 09:51 2502Mina Io监听器接口定义及抽象实现:http://dona ... -
Mina 报文通信简单示例
2017-06-12 09:01 2484MINA TCP简单通信实例:http://donald-dr ... -
Mina socket连接器(NioSocketConnector)
2017-06-12 08:37 4641Mina 抽象Polling连接器(AbstractPolli ... -
Mina 抽象Polling连接器(AbstractPollingIoConnector)
2017-06-11 21:29 960Mina 连接器接口定义及抽象实现(IoConnector ) ... -
Mina 连接器接口定义及抽象实现(IoConnector )
2017-06-11 13:46 1770Mina IoService接口定义及抽象实现:http:// ... -
Mina socket监听器(NioSocketAcceptor)
2017-06-09 08:44 3338Mina IoService接口定义及抽象实现:http:// ... -
Mina 抽象polling监听器
2017-06-08 22:32 708Mina Io监听器接口定义及抽象实现:http://dona ... -
Mina Io监听器接口定义及抽象实现
2017-06-07 13:02 1296Mina IoService接口定义及抽象实现:http:// ... -
Mina IoService接口定义及抽象实现
2017-06-06 23:44 1127Mina IoHandler接口定义:http://donal ... -
Mina Nio会话(Socket,DataGram)
2017-06-06 12:53 1144Mina Socket会话配置:http://donald-d ... -
Mina 抽象Io会话
2017-06-05 22:45 968Mina Io会话接口定义:http://donald-dra ... -
Mina Nio处理器
2017-06-04 22:19 692Mina Io处理器抽象实现:http://donald-dr ... -
Mina Io处理器抽象实现
2017-06-03 23:52 1082Mina 过滤链抽象实现:http://donald-drap ... -
Mina IoHandler接口定义
2017-06-01 21:30 1671Mina 过滤链抽象实现:http://donald-drap ... -
MINA 多路复用协议编解码器工厂二(多路复用协议解码器)
2017-06-01 12:52 2193MINA 多路复用协议编解码器工厂一(多路复用协议编码器): ... -
MINA 多路复用协议编解码器工厂一(多路复用协议编码器)
2017-05-31 22:22 1790MINA 多路分离解码器实例:http://donald-dr ... -
Mina 累计协议解码器
2017-05-31 00:09 1155MINA 编解码器实例:http://donald-drape ... -
Mina 协议编解码过滤器三(会话write与消息接收过滤)
2017-05-28 07:22 1690Mina 协议编解码过滤器一(协议编解码工厂、协议编码器): ...
相关推荐
基于spring mina 封装 rest 形式接口服务器,摆脱对tomcat,resin等服务器的依赖,基于spring,mina本身可提供tcp/ip接口,同时封装rest可方面提供http形式rest接口访问服务,方便接入
此demo利用springmvc整合mina,实现客户端主动发送消息到服务端,并且以http接口的方式实现,亲测可用。
org.apache.mina.core.buffer.IoBuffer mina core 包
mina自定义编码器-自行做会话累积。apache mina编码器
前段时间整理一下代码,仿照java的mina自己做了一套C++的异步socket IO 框架。 编译环境: fedora 10 / cenos 5.4 / cygwin gcc version 4.3.2 其他linux环境没试过,不过应该也没啥问题。 使用到的库: 如果光...
mina原理[定义].pdf
NULL 博文链接:https://410063005.iteye.com/blog/1724491
mina连接,mina心跳连接,mina断线重连。其中客户端可直接用在android上。根据各方参考资料,经过自己的理解弄出来的。CSDN的资源分太难得了。
mina的使用初步入门mina的使用初步入门mina的使用初步入门
里面包含mina2.0的api(英文)和mina自学手册,还有mina的开发指导
mina-core-2.0.0-M6.jar mina-example-2.0.0-M6.jar mina-filter-codec-netty-2.0.0-M6.jar mina-filter-compression-2.0.0-M6.jar mina-integration-beans-2.0.0-M6.jar mina-integration-jmx-2.0.0-M6.jar mina-...
Chapter 10 - IoBuffer Chapter 11 - Codec Filter Chapter 12 - Executor Filter Chapter 13 - SSL Filter Chapter 14 - Logging Filter Part III - MINA Advanced Chapter 15 - Debugging Chapter 16 - State...
Apache Mina Server 2.0 中文参考手册 Apache Mina Server 是一个网络通信应用框架,也就是说,它主要是对基于TCP/IP、UDP/IP ...步(Mina 的异步IO 默认使用的是JAVA NIO 作为底层支持)操作的编程模型。
第三章:IO 服务 第四章:会话 第五章:过滤器 第六章:传输 第七章:事件处理器 第八章:字节缓存 第九章:编解码器过滤器 第十章:执行者过滤器 第十一章:SSL 过滤器 第十二章:日志过滤器 第十三章:调试 第十四...
mina的api接口文档,mina 2.0的所有类说明都在其中,对使用mina的人是很好的工具书
对mina的各个接口都做了详尽的描述,这可是做移动飞信朋友做的pdf哦!免费让大家下载吧!希望广传天下
mina的高级使用,mina文件图片传送,
mina网络编程框架,mina网络编程框架是你的网络编程更简单,我使用mina写了一个接口,还可以。如果有不明白的可以给我发邮件3864913429@163.com. qq:270445938
最近使用Mina开发一个Java的NIO服务端程序,因此也特意学习了Apache的这个Mina框架。 引言 1 一. Mina入门 2 第一步.下载使用的Jar包 2 第二步.工程创建配置 2 第三步.服务端程序 3 第四步.客户端程序 6 第五步.长...
深入理解Apache_Mina_(1)----_Mina的几个类 深入理解Apache_Mina_(2)----_与IoFilter相关的几个类 深入理解Apache_Mina_(3)----_与IoHandler相关的几个类 深入理解Apache_Mina_(4)----_IoFilter和IoHandler的区别和...