package com.pwt.netty.initializer;

import com.pwt.common.utils.spring.SpringUtils;
import com.pwt.netty.config.NettyConfig;
import com.pwt.netty.conponents.SocketParser;
import com.pwt.netty.handler.ChargerServerHandler;
import com.pwt.netty.handler.IpFilterRuleHandler;
import com.pwt.netty.handler.Vehicle2ServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.ipfilter.RuleBasedIpFilter;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * @author linyun
 * @version V1.0
 * @Title: NettyServerChannelInitializer
 * @Description: netty服务初始化器
 * @date 2022/11/11
 **/
public class NettyServerChannelInitializer extends ChannelInitializer<SocketChannel> {
    
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception
    {
        NettyConfig nettyConfig = SpringUtils.getBean(NettyConfig.class);
        ChannelPipeline p = socketChannel.pipeline();
        // 检测空闲处理器
        p.addLast("Idle", new IdleStateHandler(nettyConfig.getREADER_IDLE_TIME_SECONDS(),
                nettyConfig.getWRITER_IDLE_TIME_SECONDS(),
                nettyConfig.getALL_IDLE_TIME_SECONDS(),
                TimeUnit.SECONDS));
        // socket websocket协议解析器
        p.addLast(new SocketParser());
    }
}
