入口 AbstractChannel.register0
private void register0(ChannelPromise promise) {
try {
..................
boolean firstRegistration = neverRegistered;
doRegister();
neverRegistered = false;
registered = true;
pipeline.invokeHandlerAddedIfNeeded();
safeSetSuccess(promise);
pipeline.fireChannelRegistered();
....................
if (isActive()) {
if (firstRegistration) {
pipeline.fireChannelActive(); // channelActive入口
} else if (config().isAutoRead()) {
beginRead();
}
}
fireChannelActive
DefaultChannelPipeline
public final ChannelPipeline fireChannelActive() {
AbstractChannelHandlerContext.invokeChannelActive(head);
return this;
}
invokeChannelActive
AbstractChannelHandlerContext
private void invokeChannelActive() {
if (invokeHandler()) {
try {
((ChannelInboundHandler) handler()).channelActive(this);
} catch (Throwable t) {
notifyHandlerException(t);
}
} else {
fireChannelActive();
}
}
fireChannelActive
public ChannelHandlerContext fireChannelActive() {
invokeChannelActive(findContextInbound(MASK_CHANNEL_ACTIVE)); // 依次调用下一个
return this;
}
流程图