想要启动一个 Server,全景如下:
// 1. 创建 selector
Selector selector = sun.nio.ch.SelectorProviderImpl.openSelector()
// 2. 创建 server socket channel,初始化等
ServerSocketChannel serverSocketChannel = provider.openServerSocketChannel()
// 3. 启用 reactor 并且注册 OP_ACCEPT 事件等待连接
selectionKey = javaChannel().register(eventLoop().unwrappedSelector(), 0, this);
javaChannel().bind(localAddress, config.getBacklog());
selectionKey.interestOps(OP_ACCEPT);
Debug 注意点
因为是最开始的源码分析:
read 事件的时候