netty源码解析(4.0)-6 线程模型-IO线程EventLoopGroup和NIO实现(一)

接口定义

io.netty.channel.EventLoopGroup extends EventExecutorGroup

方法

说明

ChannelFuture register(Channel channel)

把一个channel注册到一个EventLoop

ChannelFuture register(Channel channel, ChannelPromise promise);

同上

io.netty.channel.EventLoop extends OrderedEventExecutor, EventLoopGroup

方法

说明

EventLoopGroup parent()

得到创建这个eventLoop的EventLoopGroup

EventLoopGroup定义的主要方法是register, 这个方法的语义是把channel和eventLoop绑定在一起。一个channel对应一个eventLoop, 一个eventLoop会持有多个channel。

I/O线程EventLoopGroup的抽象实现

io.netty.channel.MultithreadEventLoopGroup extends MultithreadEventExecutorGroup implements EventLoopGroup

io.netty.channel.SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop

两个类主功能都是实现了EventLoopGroup定义的register方法

MultithreadEventLoopGroup

public ChannelFuture register(Channel channel) {

return next().register(channel);

}

public ChannelFuture register(Channel channel, ChannelPromise promise) {

return next().register(channel, promise);

}

SingleThreadEventLoop

public ChannelFuture register(Channel channel) {

return register(channel, new DefaultChannelPromise(channel, this));

}

public ChannelFuture register(final Channel channel, final ChannelPromise promise) {

channel.unsafe().register(this, promise);

return promise;

}

register的实现主要是为了调用Channel.Unsafe实例的register方法。

NIO实现

io.netty.channel.nio.NioEventLoopGroup extends MultithreadEventLoopGroup

io.netty.channel.nio.NioEventLoop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值