com.myseti.framework.monitor.net.MonitorServerInitializer.java Source code

Java tutorial

Introduction

Here is the source code for com.myseti.framework.monitor.net.MonitorServerInitializer.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myseti.framework.monitor.net;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.ssl.SslContext;

/**
 *
 * @author blue
 */
public class MonitorServerInitializer extends ChannelInitializer<SocketChannel> {

    private final SslContext sslCtx;

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

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        if (sslCtx != null) {
            pipeline.addLast(sslCtx.newHandler(ch.alloc()));
        }

        // Add the number codec first,
        pipeline.addLast(new DecodeProtocol());
        pipeline.addLast(new EncodeProtocol());

        // and then business logic.
        // Please note we create a handler for every new channel
        // because it has stateful properties.
        pipeline.addLast(new MonitorServerHandler());
    }

}