Netty 源码 Channel(一)概述

Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html)

相关文章:

Channel 为 Netty 网络操作抽象类,EventLoop 主要是为 Channel 处理 I/O 操作,两者配合参与 I/O 操作。

Unsafe 是个内部接口,聚合在 Channel 中协助进行网络读写相关的操作。

1. Channel 功能

Channel 的功能主要功能如下:

  1. 网络 IO 功能:如 read、write、connect、bind、config、isActive、isOpen 等
  2. 其它:如 eventLoop(绑定的线程)、metadata(获取 TCP 配置参数)、parent(SocketChannel 的 parent 是 ServerSocketChannel)、id(唯一标识符)

2. Channel 创建

以 NioServerSocketChannel 创建过程为例。

// 创建 NIO 底层的 ServerSocketChannel 对象
public NioServerSocketChannel() {
this(newSocket(DEFAULT_SELECTOR_PROVIDER));
}
// NioServerSocketChannel 需要注册 OP_ACCEPT 事件
public NioServerSocketChannel(ServerSocketChannel channel) {
super(null, channel, SelectionKey.OP_ACCEPT);
config = new NioServerSocketChannelConfig(this, javaChannel().socket());
} // 设置成非阻塞模式,并注册感兴趣的事件
protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) {
super(parent);
this.ch = ch;
this.readInterestOp = readInterestOp;
ch.configureBlocking(false);
} // 创建 channel 是创建对应的 pipeline
protected AbstractChannel(Channel parent) {
this.parent = parent;
id = newId();
unsafe = newUnsafe();
pipeline = newChannelPipeline();
}

NioServerSocketChannel 创建过程主要干了两件事,其配置信息保存在 NioServerSocketChannelConfig 中:

  1. 创建 JDK 底层的 ServerSocketChannel 对象
  2. 创建 ChannelPipeline

每天用心记录一点点。内容也许不重要,但习惯很重要!

Netty 源码 Channel(一)概述的更多相关文章

  1. Netty 源码 Channel(二)核心类

    Netty 源码 Channel(二)核心类 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一.Channel 类图 二. ...

  2. Netty 源码 Channel(二)主要类

    Netty 源码 Channel(二)主要类 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一.Channel 类图 二. ...

  3. Netty源码分析(前言, 概述及目录)

    Netty源码分析(完整版) 前言 前段时间公司准备改造redis的客户端, 原生的客户端是阻塞式链接, 并且链接池初始化的链接数并不高, 高并发场景会有获取不到连接的尴尬, 所以考虑了用netty长 ...

  4. Netty 源码 ChannelHandler(三)概述

    Netty 源码 ChannelHandler(三)概述 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一.Channel ...

  5. netty源码解解析(4.0)-11 Channel NIO实现-概览

      结构设计 Channel的NIO实现位于io.netty.channel.nio包和io.netty.channel.socket.nio包中,其中io.netty.channel.nio是抽象实 ...

  6. Netty 源码(二)NioEventLoop 之 Channel 注册

    Netty 源码(二)NioEventLoop 之 Channel 注册 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一 ...

  7. Netty源码分析第1章(Netty启动流程)---->第3节: 服务端channel初始化

    Netty源码分析第一章:Netty启动流程   第三节:服务端channel初始化 回顾上一小节的initAndRegister()方法: final ChannelFuture initAndRe ...

  8. Netty源码分析第5章(ByteBuf)---->第5节: directArena分配缓冲区概述

    Netty源码分析第五章: ByteBuf 第五节: directArena分配缓冲区概述 上一小节简单分析了PooledByteBufAllocator中, 线程局部缓存和arean的相关逻辑, 这 ...

  9. Netty源码分析--创建Channel(三)

    恩~,没错,其实这一篇才是真正的开始分析源码,你打我呀~. 先看一下我Netty的启动类 private void start() throws Exception { EventLoopGroup ...

随机推荐

  1. eclipse老运行上一个程序之原因总结

    运行eclipse有的时候不运行刚写的类,老是运行别的以前的类,删除了以前的类就啥都不运行.找了好久的原因,最后发现,刚写的类没有main()或者有误.这和java的特点有关,程序的运行总是main( ...

  2. Spring设置动态定时任务

    1.在Spring中经常会用到定时任务,一般会在业务方法上使用@Schedule(cron="定时执行规则"),无法实现从前台动态设置定时任务. 在java中固定频率的任务使用Sc ...

  3. metasploitable使用

    DVWA默认的用户有5个,用户名密码如下(一个足以): admin/password gordonb/abc123 1337/charley pablo/letmein smithy/password

  4. RecyclerView的单击和长按事件(转)

    转自:http://www.jianshu.com/p/f2e0463e5aef 前言 上一篇文章揭开RecyclerView的神秘面纱(一):RecyclerView的基本使用中,主要讲述了Recy ...

  5. sqlserver 查看当前连接数

    参考 https://www.cnblogs.com/lumnm/archive/2009/08/29/1556349.html SELECT * FROM[Master].[dbo].[SYSPRO ...

  6. MyLineNumberReader

    package com.itheima; import java.io.FileReader; import java.io.IOException; import java.io.Reader; p ...

  7. 第二章 向量(f)归并排序

  8. 第二章 向量(d5)有序向量:插值查找

  9. linux下访问window的共享文件,在命令行实现方法

    1.挂载共享目录 mount -t cifs //192.168.0.1/aa  /tmp/export -o username=text,password=test //192.168.0.1/aa ...

  10. enlarge your dataset

    列举常见的几种数据集增强方法: 1.flip  翻折(左右,上下) # NumPy.'img' = A single image. flip_1 = np.fliplr(img) # TensorFl ...