当provider端接收到consumer的请求之后调用NettyServerHandler类的channelActive方法。dubbo底层发送网络请求使用的是Netty框架。在NettyClient类中
@Override
protected void initChannel(Channel ch) throws Exception {
NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
ch.pipeline()//.addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug
.addLast("decoder", adapter.getDecoder())
.addLast("encoder", adapter.getEncoder())
.addLast("handler", nettyClientHandler);
}
使用NettyClientHandler对象处理请求。对于接收到的请求,先调用adapter.getDecoder()的decode方法解码生成Request,调用nettyClientHandler的channelActive方法。最终调到AllChannelHandler类的connected方法:
ExecutorService cexecutor = getExecutorService();
try {
cexecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.CONNECTED));
} catch (Throwable t) {
throw new ExecutionException("connect event", channel, getClass() + " error when process connected event .", t);
}
用线程池处理。