当前位置:网站首页>2-3. Register selector
2-3. Register selector
2022-04-21 10:32:00 【Dongshan Mingyue】
First of all, let's review the previous work , stay netty Server startup in , Detailed netty The four steps of the initialization process :
-
Create server channel, call jdk At the bottom api establish jdk Of channel, after netty Pack it into your own channel, And create some basic components bound to the channel On . -
Initialize the server channel, After the creation is completed, the channel Do some initialization work , For example, initialize some basic properties , Add some logical processors . -
register selector,netty take jdk At the bottom channel Register to event poller selector above . -
Port binding , call jdk Bottom api Monitor the port .
The first two steps are Create server channel and Initialize the server channel In detail , This section introduces the third step : register selector, Its main function is to jdk At the bottom channel Register with the event poller .
1. register selector Overall process
Similarly, first according to the overall process given by flash , Register for selector Part has a whole cognition :
The source code part goes on channel Registration and initialization of , As shown in the figure below , After initialization, there is a registered part , The code here corresponds to AbstractChannel Class register Method , That is, the first step in the overall process .
2. register(channel) Method
The source code of this method is as follows : 
The first few lines are if Judge , There are two main places :AbstractChannel.this.eventLoop = eventLoop Be responsible for binding eventLoop Threads are used to process requests that have only ;register0(promise) Is the part of the actual registration , The source code is as follows :
register0 The method mainly analyzes the three places marked in the figure .
2.1 doRegister() Method
The method is located in AbstractNioChannel Class , The source code is as follows :
among javaChannel() Method returns through jdk Bottom api Create a new server channel, After that register Part is the specific registration , take this Sign up to eventLoop().selector above , there this It's a AbstractNioChannel object , I understand that you are right java Bottom channel An encapsulation of . Another parameter is ops Indicates that registration is a time of concern ,0 I don't care about anything . such netty By calling java Bottom channel Your registration method is complete selector Registration of .
2.2 invokeHandlerAddedIfNeeded() And fireChannelRegistered()
stay register0() In the method , Let's focus on three steps , except doRegister The other part is the part that needs to be expanded in this section .
among 2 and 3 Part corresponds to... Of the user code handler part , Here we introduce a ServerHandler, It rewrites three methods , These three methods are related to invokeHandlerAddedIfNeeded()、fireChannelRegistered() Corresponding .
Run the program , Change can see that we are ServerHandler Output in :
3. Summary
-
register selector when , With register(channel) The method is the entrance -
First bind the thread -
After that by regiter0 Complete the actual registration , The registration part is mainly divided into three steps -
call jdk Bottom channel Your registration method is complete selector Registration of -
invokeHandlerAddedIfNeeded() -
fireChannelRegistered()
-
-
版权声明
本文为[Dongshan Mingyue]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211031527297.html
边栏推荐
- 24张图攻克border-image
- torch.autograd.Function 自定义
- Alibaba cloud mobile R & D platform EMAS, product dynamics in March
- Filebeat收集日志数据传输到Redis,通过Logstash来根据日志字段创建不同的ES索引
- 比SQL还好用,又一门国产数据库语言诞生了
- Jupyter notebook修改默认开启路径
- WinPcap获取设备列表
- "Air washing" meets the iteration again, and the imitator has a new goal
- 2022信息与未来预备刷题1《New Online Judge 1112: 平面分割》
- 作业调度、中级调度、进程调度
猜你喜欢

DFS of vigorously flying brick (creation of tree)

Pytoch learning notes (2) examples of univariate linear regression and calculation diagram

24张图攻克border-image

金融零售图谱-交易流水预警图谱

Basic commands of MySQL

Nanny level tutorial on building personal home page (I)

24 pictures to conquer border image

WeChat official account web page sharing settings and problems

Read the meaning of seek tiger's launch of Genesis node

(SIP-1-话机注册)关于IP话机通过SIP协议注册到PBX电话交换机的全过程解析-如何看wireshark中的报文
随机推荐
摩尔线程与Ampere Computing达成合作
jeecgboot:online表单控件下拉框和下拉搜索框的区别
塔米狗知识|上市公司收购的基本原则
对象和类的知识点总结
Pytoch learning notes (1) check the creation of torch, CUDA and tensor
利用随机函数实现随机范围的改变
看完这篇 教你玩转渗透测试靶机vulnhub——DC9
微软更新Android/iOS版验证器应用 支持生成更安全的强密码
Mieux que SQL, un autre langage de base de données domestique est né
【并发编程043】CAS存在的问题,ABA问题,如何解决的?
趣丸集团招股书“失效”,旗下TT语音已下架,如何实现稳定增长?
[pytorch] Monai vit network graphic analysis
【WCN685x】如何判断wifi驱动调用的bdwlan文件是哪个?
IDEA和PyCharm启动时进入欢迎界面
DFS of vigorously flying brick (creation of tree)
My creation anniversary
二分查找符合要求的值及局部最小值
什么是时间戳?
2022信息与未来预备刷题4《New Online Judge 2034: [蓝桥杯2022初赛] 修剪灌木》
再战leetcode (392.判断子序列)