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. https://www.oschina.net/project/zhlist/326/scripting 开源

    1https://www.oschina.net/project/zhlist/326/scripting

  2. MySQL 事务 隔离级别

    前两天面试,问到了四种隔离级别,当时觉得大多数数据库都为read committed,结果没想到mysql是个例外.在此做一下隔离级别和各种数据库锁的使用. 首先说一下ACID四大特性: 四大特性   ...

  3. centos7防火墙以设置以及关闭selinux

    一.CentOS 7.X 关闭SELinux 1.查看 getenforce permissive 或者 enforcing模式 2.临时设置 setenforce 1 成为permissive模式 ...

  4. async.waterfall

    [async.waterfall] if any of the tasks pass an error to their own callback, the next function is not ...

  5. CentOS 查看是否安装软件包

    1. rpm包安装的,可以用rpm -qa看到,如果要查找某软件包是否安装,用 rpm -qa | grep "软件或者包的名字" 2. deb包安装的,可以用dpkg -l能看到 ...

  6. CentOS 查看进程状态

    Linux中ps与top命令   ============================================================================ 这两个命令都 ...

  7. CodeForces - 920C Swap Adjacent Elements

    传送门:点我 You have an array a consisting of n integers. Each integer from 1 to n appears exactly once i ...

  8. Date 时间 日期 常用方法函数

    转载自https://www.cnblogs.com/lcngu/p/5154834.html 一.java.util.Date对象用来表示时间,基本方法如下: Date mDate = new Da ...

  9. Codeforces Beta Round #49 (Div. 2)

    Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...

  10. Jmeter录制APP脚本

    启动 jmeter.bat 在 Test Plan 下 添加 Thread Group 在 WorkBench 下 添加 HTTP(S) Test Script Recorder: 配置 Global ...