netty之ServerBootstrap和Bootstrap
简介
其作为netty启动引导,配置eventloop以及handler等netty的基础组件
结构
ServerBootstrap
ChannelInitializer
:用于在注册完成时添加新连接时的ChannelHandler,其保证只执行一次,不会重复添加
private boolean initChannel(ChannelHandlerContext ctx) throws Exception {
if (initMap.add(ctx)) { // Guard against re-entrance.
try {
initChannel((C) ctx.channel());
} catch (Throwable cause) {
// Explicitly call exceptionCaught(...) as we removed the handler before calling initChannel(...).
// We do so to prevent multiple calls to initChannel(...).
exceptionCaught(ctx, cause);
} finally {
ChannelPipeline pipeline = ctx.pipeline();
if (pipeline.context(this) != null) {
pipeline.remove(this);
}
}
return true;
}
return false;
}