package com.choodon.learn.netty.tcp.ReplayingDecoder;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.ssl.SslContext;

public class ReplayingDecoderServerChannelInitializer extends ChannelInitializer {

    private final SslContext sslCtx;

    public ReplayingDecoderServerChannelInitializer(SslContext sslCtx) {
        this.sslCtx = sslCtx;
    }

    @Override
    protected void initChannel(Channel ch) throws Exception {
        ChannelPipeline channelPipeline = ch.pipeline();
        if (null != sslCtx) {
            channelPipeline.addLast(sslCtx.newHandler(ch.alloc()));
        }
        channelPipeline.addLast(new TcpReplayingDecoder());
        channelPipeline.addLast(new TcpReplayingEncoder());
        channelPipeline.addLast(new ReplayingDecoderServerHandler());
    }
}
