// Path: ace-core/src/main/java/wiki/chenxun/ace/core/base/common/AceServerConfig.java
// @Data
// @ConfigBean(AceServerConfig.PREFIX)
// public class AceServerConfig {
// 
//     public static final String PREFIX = "ace.server";
// 
//     private long timeout = 1000L;
// 
//     private int port = 8080;
// 
//     private int backSize = 1024;
// }
// 
// Path: ace-core/src/main/java/wiki/chenxun/ace/core/base/remote/Server.java
// @Spi("netty")
// public interface Server extends ConfigBeanAware<AceServerConfig> {
// 
// 
// 
//     /**
//      * 开启服务
//      *
//      * @throws Exception 异常基类
//      */
//     void start() throws Exception;
// 
//     void close();
// 
// 
// }


import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import wiki.chenxun.ace.core.base.common.AceServerConfig;
import wiki.chenxun.ace.core.base.remote.Server;
import java.io.IOException;
import java.util.Observable;
package wiki.chenxun.ace.core.base.remote.netty;



/**
 * @Description: Created by chenxun on 2017/4/7.
 */
public class DefaultServer implements Server {

    private AceServerConfig aceServerConfig;

    /**
     * io线程
     */
    private EventLoopGroup bossGroup = new NioEventLoopGroup();
    /**
     * work线程
     */
    private EventLoopGroup workerGroup = new NioEventLoopGroup(100);

    /**
     * channelHandler注册
     */
    private ChannelInitializer channelInitializer = new HttpProtocolChannelInitializer();

    /**
     * 启动服务
     *
     * @throws Exception 异常
     */
    public void start() throws Exception {
        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(channelInitializer)
                    .option(ChannelOption.SO_BACKLOG, aceServerConfig.getBackSize())
// Path: ace-core/src/main/java/wiki/chenxun/ace/core/base/common/AceServerConfig.java
// @Data
// @ConfigBean(AceServerConfig.PREFIX)
// public class AceServerConfig {
// 
//     public static final String PREFIX = "ace.server";
// 
//     private long timeout = 1000L;
// 
//     private int port = 8080;
// 
//     private int backSize = 1024;
// }
// 
// Path: ace-core/src/main/java/wiki/chenxun/ace/core/base/remote/Server.java
// @Spi("netty")
// public interface Server extends ConfigBeanAware<AceServerConfig> {
// 
// 
// 
//     /**
//      * 开启服务
//      *
//      * @throws Exception 异常基类
//      */
//     void start() throws Exception;
// 
//     void close();
// 
// 
// }


// Path: ace-core/src/main/java/wiki/chenxun/ace/core/base/remote/netty/DefaultServer.java
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import wiki.chenxun.ace.core.base.common.AceServerConfig;
import wiki.chenxun.ace.core.base.remote.Server;
import java.io.IOException;
import java.util.Observable;

package wiki.chenxun.ace.core.base.remote.netty;



/**
 * @Description: Created by chenxun on 2017/4/7.
 */
public class DefaultServer implements Server {

    private AceServerConfig aceServerConfig;

    /**
     * io线程
     */
    private EventLoopGroup bossGroup = new NioEventLoopGroup();
    /**
     * work线程
     */
    private EventLoopGroup workerGroup = new NioEventLoopGroup(100);

    /**
     * channelHandler注册
     */
    private ChannelInitializer channelInitializer = new HttpProtocolChannelInitializer();

    /**
     * 启动服务
     *
     * @throws Exception 异常
     */
    public void start() throws Exception {
        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(channelInitializer)
                    .option(ChannelOption.SO_BACKLOG, aceServerConfig.getBackSize())
                    .childOption(ChannelOption.SO_KEEPALIVE, true)