package com.m2pool.lease;

import com.m2pool.common.security.annotation.EnableCustomConfig;
import com.m2pool.common.security.annotation.EnableM2PoolFeignClients;
import com.m2pool.common.swagger.annotation.EnableCustomSwagger2;
import com.m2pool.lease.netty.server.NettyTcpServer;
import io.netty.channel.ChannelFuture;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;

@EnableCustomConfig
@EnableCustomSwagger2
@EnableM2PoolFeignClients
@SpringBootApplication
@MapperScan({"com.m2pool.lease.mapper"})
public class M2poolLeaseApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(M2poolLeaseApplication.class, args);
    }

    @Resource
    NettyTcpServer nettyTcpServer;


    @Override
    public void run(String... args)  {
        //启动服务端
        ChannelFuture start = nettyTcpServer.start();
        //服务端管道关闭的监听器并同步阻塞,直到channel关闭,线程才会往下执行,结束进程
        start.channel().closeFuture().syncUninterruptibly();
    }
}
