netty笔记1
来源:互联网 发布:清博大数据公司 怎么样 编辑:程序博客网 时间:2024/06/07 22:09
EventLoopGroup.next()得到EventLoop
EventLoopGroup初始化时候会实例化一个EventLoop[]数组,使用的是EventLoopGroup的newChild方法
真正干活的是EventLoop
使用EventLoopGroup的register方法会将channel注册到一个EventLoop上
在AbstractBootstrap的initAndRegister方法中会做这一步操作
ServerBootstrap的init方法会将server端接收到的channel的pipeline加上配置的ChannelHandler
Bootstrap的init方法会将client端接的channel的pipeline加上配置的ChannelHandler
DefaultChannelPipeline在addLast后会判断当前的channel是否注册到EventLoop上,如果没有会用一个task
在注册后调用ChannelHandler的handlerAdded方法
ServerBootstrapAcceptor中的channelRead会在serverChannel.accept得到channel后执行,加上childHandler,使用childGroup注册一个EventLoop
NioEventLoop有一个run方法,做了processSelectedKeys和runAllTasks,
这个run方法会最先执行 SingleThreadEventExecutor.execute方法中startThread()会将run方法包装成一个task执行
processSelectedKeys会选择注册在selector上的事件,然后AbstractNioChannel.NioUnsafe处理
比如read 先调用doReadMessages读取内容,然后使用pipeline处理,AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext, Object)
生成一个任务提交给channel的EventLoop处理
EventLoopGroup和EventLoop的executor默认是executor = new ThreadPerTaskExecutor(newDefaultThreadFactory());
EventLoopGroup初始化时候会实例化一个EventLoop[]数组,使用的是EventLoopGroup的newChild方法
真正干活的是EventLoop
使用EventLoopGroup的register方法会将channel注册到一个EventLoop上
在AbstractBootstrap的initAndRegister方法中会做这一步操作
ServerBootstrap的init方法会将server端接收到的channel的pipeline加上配置的ChannelHandler
Bootstrap的init方法会将client端接的channel的pipeline加上配置的ChannelHandler
DefaultChannelPipeline在addLast后会判断当前的channel是否注册到EventLoop上,如果没有会用一个task
在注册后调用ChannelHandler的handlerAdded方法
ChannelInitializer的handlerAdded方法会先执行initChannel,最后执行remove方法将当前的ChannelInitializer移除pipeline
ServerBootstrap中 p.addLast(new ChannelInitializer<Channel>() { //p是serverChannel的pipeline @Override public void initChannel(final Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); //ch是serverChannel ChannelHandler handler = config.handler();//handler得到AbstractBootstrap的handler,也就是handler(handler)设置的 if (handler != null) { pipeline.addLast(handler); } ch.eventLoop().execute(new Runnable() { @Override public void run() { pipeline.addLast(new ServerBootstrapAcceptor(//serverChannel的pipeline加上ServerBootstrapAcceptor ch, currentChildGroup, currentChildHandler, currentChildOptions, currentChildAttrs)); } }); } });
ServerBootstrapAcceptor中的channelRead会在serverChannel.accept得到channel后执行,加上childHandler,使用childGroup注册一个EventLoop
NioEventLoop有一个run方法,做了processSelectedKeys和runAllTasks,
这个run方法会最先执行 SingleThreadEventExecutor.execute方法中startThread()会将run方法包装成一个task执行
processSelectedKeys会选择注册在selector上的事件,然后AbstractNioChannel.NioUnsafe处理
比如read 先调用doReadMessages读取内容,然后使用pipeline处理,AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext, Object)
生成一个任务提交给channel的EventLoop处理
EventLoopGroup和EventLoop的executor默认是executor = new ThreadPerTaskExecutor(newDefaultThreadFactory());
直接生成新的FastThreadLocalThread执行
AbstractChannel
AbstractNioChannel
AbstractNioByteChannel ----NioByteUnsafe
NioSocketChannel
AbstractNioMessageChannel ----NioMessageUnsafe
NioServerSocketChannel
阅读全文
0 0
- Netty学习笔记:1
- netty笔记1
- netty笔记
- Netty 笔记
- Netty笔记
- netty笔记
- 【Netty】netty学习笔记一
- Netty权威指南学习笔记1
- 《netty权威指南》学习笔记1
- Netty源码学习笔记
- Netty学习笔记一
- Netty 学习笔记
- Netty笔记:FrameDecoder
- Netty学习笔记
- Netty学习笔记
- Netty学习笔记 开始
- Netty学习笔记:2
- Netty源码学习笔记
- windows下面安装Python和pip
- JAVA编程思想学习 --- 第三章(控制程序流程)
- DevOps落地实践:BAT系列:CICD:iPipe vs CCI
- html 使表格随着内容自动适应宽度
- 远程连接elasticsearch遇到的问题
- netty笔记1
- Cocos2d-x里面如何实现MVC(二)
- 查看Oracle当前用户下的主键、索引、sequence创建语句
- scala:Object与Class的区别
- JAVA编程思想学习 --- 第四章 (初始化和清除)
- [初学笔记] tic toc 计算程序运行时间
- 使用NOPI读取Word、Excel文档内容
- sphinx调用API参考(官方手册)
- JAVA编程思想学习 --- 第五章 (隐藏实施过程)