Search in sources :

Example 1 with RpcConfig

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"));
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) TransportMessageDecoder(io.transport.core.protocol.codec.TransportMessageDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) RpcConfig(io.transport.core.config.Configuration.RpcConfig) TransportMessageEncoder(io.transport.core.protocol.codec.TransportMessageEncoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)1 RpcConfig (io.transport.core.config.Configuration.RpcConfig)1 TransportMessageDecoder (io.transport.core.protocol.codec.TransportMessageDecoder)1 TransportMessageEncoder (io.transport.core.protocol.codec.TransportMessageEncoder)1