use of io.transport.core.config.Configuration.RpcConfig in project transporter by wang4ever.
the class ChildHandlerInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
RpcConfig conf = this.config.getRpcConfig();
if (logger.isDebugEnabled())
logger.debug("Initital channel handler...");
// pipeline管理channel中的Handler,在channel队列中添加一个handler来处理业务
ChannelPipeline p = ch.pipeline();
if (conf.getLoggingEnable()) {
p.addLast(new LoggingHandler(LogLevel.valueOf(conf.getLoggingLevel())));
if (logger.isInfoEnabled())
logger.info("Netty internal log has been used. (Rpc)level={}", conf.getLoggingLevel());
}
IdleStateHandler idleHandler = new IdleStateHandler(conf.getReadIdleSeconds(), conf.getWriteIdleSeconds(), conf.getAllIdleSeconds());
p.addLast(idleHandler);
// ### 必须每次 getBean(..), 不能用 @Autowired
p.addLast("decoder", SpringContextHolder.getBean(TransportMessageDecoder.class));
p.addLast("encoder", SpringContextHolder.getBean(TransportMessageEncoder.class));
p.addLast("transport", SpringContextHolder.getBean("transportMessageHandler"));
}
Aggregations