netty
2023-02-14 20:38:02 6 举报
AI智能生成
登录查看完整内容
netty
作者其他创作
大纲/内容
遍历数组,为每一个EventExecutor是设置LinkedBlockQueue
final SelectorTuple selectorTuple = openSelector(); this.selector = selectorTuple.selector;为每一个EventExecutor执行Selector.open
children = new EventExecutor[nThreads];创建一个数组
没设置线程数为CPU的2倍吗,传了参数为自己设置的
创建NioEventLoopGroup
将bootstrap的group属性设置为boosGroup
将bootstrap的childGroup属性设置为workerGroup
将ServerSocketChannel构造方法设置属性
.channel(NioServerSocketChannel.class)
将childHandler属性赋值为一个ChannelInitialize
.childHandler
设置bootstrap属性
反射出ServerSocketCHannel
pipeline = newChannelPipeline();初始化一个pipeline,有一个head和一个tail
ch.configureBlocking(false);将ServerSocketChannel设置为非阻塞
往piepline里面添加ServerBootstrapAcceptor
init(channel);往piepline里面放ChannelInitializer
init
addTask(task);将注册任务添加到taskQueue
执行taskQueue里面的任务
ranTasks = runAllTasks();
strategy = select(curDeadlineNanos);在里面进行selector.select()
SingleThreadEventExecutor.this.run();
doStartThread();
startThread();
会回调ChannelInitializer
pipeline.invokeHandlerAddedIfNeeded();
执行Handler
pipeline.fireChannelRegistered();
register0
eventLoop.execute(new Runnable() { @Override public void run() { register0(promise); } });
ChannelFuture regFuture = config().group().register(channel);将注册任务加入taskQueue
initAndRegister();
bootstrap.bind(9000).sync();绑定端口
3.SelectionKey.OP_READSocketChannel将SelectKey设置为读SocketChannel设置于非阻塞
int localRead = doReadMessages(readBuf);读信息
child.pipeline().addLast(childHandler);初始化时候创建添加的new ChannelInitializer
childGroup.register(child)
会调用ServerBootstrapAcceptor的channelRead()
pipeline.fireChannelRead(readBuf.get(i));处理channel
(SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0
netty
0 条评论
回复 删除
下一页