package com.cisdi.data.caliper.gateway;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

public class CaliperClientInitializer extends ChannelInitializer<SocketChannel> {

    private final CaliperClient caliperClient;
    private final CaliperTaskStartVo startVo;

    public CaliperClientInitializer(CaliperTaskStartVo startVo, CaliperClient caliperClient) {
        this.startVo = startVo;
        this.caliperClient = caliperClient;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) {
        //注册管道
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new CaliperFrameDecoder(startVo));
        pipeline.addLast("chat", new CaliperClientHandler(startVo, caliperClient));
    }
}
