`
QING____
  • 浏览: 2253274 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

NIO-Pile通道详解

 
阅读更多

Pipe实现单向管道传送的通道对等端.管道是由两端组成:一个可写入的sink通道和一个可读取的source通道(根据数据来源).一旦将某些字节写入接受器通道,就可以按照与写入时完全相同的顺序从源通道中读取这些字节.在另一个线程从管道中读取这些字节或先前已写入的字节之前,是否阻塞将该字节写入管道的线程是与系统相关的,因此是未指定的.

Pipe名为管道,其实底层实现为一个本地的TCP链接:即一个侦听本地port的ServerSocketChannel,以及一个链接到此port上SocketChannel,最终建立连接后获得2个SocketChannel引用;其中Server端的SocketChannel作为Pipe.sink,Client端的SocketChannel作为Pipe.source.因为Sink和Source都封装了高层的SocketChannel,所以它们也支持阻塞模式的设定,最终影响到SocketChannel.

Sink为数据的输出端,此类实现了SeleactableChannel/WritableChannel/GatheringByteChannel,由此可见Sink本身支持中断操作/Selector/write操作;Sink负责向Pipe中写入数据.

Source为数据消费端(读取端),此类实现了SelectableChannel/ReadableChannel/ScatteringByteChannel,它具有Sink的其他特性,但是Source只能read.

Pipe是IO操作中一个有趣的单工模式.大部分情况下,我们无需使用Selector,因为在Pipe中使用selector实在是难以理解:1)无事件切换 2) 必然阻塞性(根据数据流动性).

PipeImpl源码:http://javasourcecode.org/html/open-source/jdk/jdk-6u23/sun/nio/ch/PipeImpl.java.html

  • public static Pipe open() throws IOException:打开一个通道.通过调用系统级默认的SelectorProvider.openPipe()方法来创建管道.
  • public abstract Pipe.SinkChannel sink():获取通道的输入端.SinkChannel底层封装了作为客户端的SocketChannel,SinkChannel.validOps()只能为OP_WRITE
  • public abstract Pipe.SourceChannel source():获得通道的输出端.SourceChannel底层封装了ServerSocketChannel.accept()得到的SocketChannel,其validOps()只能为OP_READ.

Pile实例参考:http://shift-alt-ctrl.iteye.com/blog/1840414

分享到:
评论

相关推荐

    httpcore-nio-4.4.6-API文档-中文版.zip

    赠送jar包:httpcore-nio-4.4.6.jar 赠送原API文档:httpcore-nio-4.4.6-javadoc.jar 赠送源代码:httpcore-nio-4.4.6-sources.jar 包含翻译后的API文档:httpcore-nio-4.4.6-javadoc-API文档-中文(简体)版.zip ...

    httpcore-nio-4.4.15-API文档-中文版.zip

    赠送jar包:httpcore-nio-4.4.15.jar 赠送原API文档:httpcore-nio-4.4.15-javadoc.jar 赠送源代码:httpcore-nio-4.4.15-sources.jar 包含翻译后的API文档:httpcore-nio-4.4.15-javadoc-API文档-中文(简体)版....

    httpcore-nio-4.4.10-API文档-中文版.zip

    赠送jar包:httpcore-nio-4.4.10.jar; 赠送原API文档:httpcore-nio-4.4.10-javadoc.jar; 赠送源代码:httpcore-nio-4.4.10-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.10.pom; 包含翻译后的API文档...

    xnio-nio-3.8.0.Final-API文档-中文版.zip

    赠送jar包:xnio-nio-3.8.0.Final.jar; 赠送原API文档:xnio-nio-3.8.0.Final-javadoc.jar; 赠送源代码:xnio-nio-3.8.0.Final-sources.jar; 赠送Maven依赖信息文件:xnio-nio-3.8.0.Final.pom; 包含翻译后的API...

    httpcore-nio-4.4.10-API文档-中英对照版.zip

    赠送jar包:httpcore-nio-4.4.10.jar; 赠送原API文档:httpcore-nio-4.4.10-javadoc.jar; 赠送源代码:httpcore-nio-4.4.10-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.10.pom; 包含翻译后的API文档...

    httpcore-nio-4.4.15-API文档-中英对照版.zip

    赠送jar包:httpcore-nio-4.4.15.jar 赠送原API文档:httpcore-nio-4.4.15-javadoc.jar 赠送源代码:httpcore-nio-4.4.15-sources.jar 包含翻译后的API文档:httpcore-nio-4.4.15-javadoc-API文档-中文(简体)-...

    xnio-nio-3.8.4.Final-API文档-中英对照版.zip

    赠送jar包:xnio-nio-3.8.4.Final.jar; 赠送原API文档:xnio-nio-3.8.4.Final-javadoc.jar; 赠送源代码:xnio-nio-3.8.4.Final-sources.jar; 赠送Maven依赖信息文件:xnio-nio-3.8.4.Final.pom; 包含翻译后的API...

    xnio-nio-3.8.0.Final-API文档-中英对照版.zip

    赠送jar包:xnio-nio-3.8.0.Final.jar; 赠送原API文档:xnio-nio-3.8.0.Final-javadoc.jar; 赠送源代码:xnio-nio-3.8.0.Final-sources.jar; 赠送Maven依赖信息文件:xnio-nio-3.8.0.Final.pom; 包含翻译后的API...

    httpcore-nio-4.4.5-API文档-中文版.zip

    赠送jar包:httpcore-nio-4.4.5.jar; 赠送原API文档:httpcore-nio-4.4.5-javadoc.jar; 赠送源代码:httpcore-nio-4.4.5-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.5.pom; 包含翻译后的API文档:...

    nio-multipart-parser-1.1.0.jar

    java运行依赖jar包

    httpcore-nio-4.4.14-API文档-中文版.zip

    赠送jar包:httpcore-nio-4.4.14.jar; 赠送原API文档:httpcore-nio-4.4.14-javadoc.jar; 赠送源代码:httpcore-nio-4.4.14-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.14.pom; 包含翻译后的API文档...

    httpcore-nio-4.4.6-API文档-中英对照版.zip

    赠送jar包:httpcore-nio-4.4.6.jar; 赠送原API文档:httpcore-nio-4.4.6-javadoc.jar; 赠送源代码:httpcore-nio-4.4.6-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.6.pom; 包含翻译后的API文档:...

    httpcore-nio-4.4.12-API文档-中文版.zip

    赠送jar包:httpcore-nio-4.4.12.jar; 赠送原API文档:httpcore-nio-4.4.12-javadoc.jar; 赠送源代码:httpcore-nio-4.4.12-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.12.pom; 包含翻译后的API文档...

    xnio-nio-3.8.4.Final-API文档-中文版.zip

    赠送jar包:xnio-nio-3.8.4.Final.jar; 赠送原API文档:xnio-nio-3.8.4.Final-javadoc.jar; 赠送源代码:xnio-nio-3.8.4.Final-sources.jar; 赠送Maven依赖信息文件:xnio-nio-3.8.4.Final.pom; 包含翻译后的API...

    httpcore-nio-4.4.4-API文档-中文版.zip

    赠送jar包:httpcore-nio-4.4.4.jar; 赠送原API文档:httpcore-nio-4.4.4-javadoc.jar; 赠送源代码:httpcore-nio-4.4.4-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.4.pom; 包含翻译后的API文档:...

    httpcore-nio-4.3.jar包

    《深入解析httpcore-nio-4.3.jar:构建高性能的Java非阻塞网络通信》 在Java网络编程中,高效、稳定且可扩展的通信框架至关重要。Apache HttpComponents项目中的HttpCore NIO模块(httpcore-nio)就是这样一个框架...

    httpcore-nio-4.4.12-API文档-中英对照版.zip

    赠送jar包:httpcore-nio-4.4.12.jar; 赠送原API文档:httpcore-nio-4.4.12-javadoc.jar; 赠送源代码:httpcore-nio-4.4.12-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.12.pom; 包含翻译后的API文档...

    httpcore-nio-4.4.4-API文档-中英对照版.zip

    赠送jar包:httpcore-nio-4.4.4.jar; 赠送原API文档:httpcore-nio-4.4.4-javadoc.jar; 赠送源代码:httpcore-nio-4.4.4-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.4.pom; 包含翻译后的API文档:...

    httpcore-nio-4.4.5-API文档-中英对照版.zip

    赠送jar包:httpcore-nio-4.4.5.jar; 赠送原API文档:httpcore-nio-4.4.5-javadoc.jar; 赠送源代码:httpcore-nio-4.4.5-sources.jar; 赠送Maven依赖信息文件:httpcore-nio-4.4.5.pom; 包含翻译后的API文档:...

    httpcore-nio-4.4.12.jar

    java运行依赖jar包

Global site tag (gtag.js) - Google Analytics