package com.yfd.platform.component.nettyserver;

import com.yfd.platform.config.HttpServerConfig;
import com.yfd.platform.utils.ExecutionJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Order(value=20)
public class NettyServerRunner implements CommandLineRunner {
    private static final Logger logger = LoggerFactory.getLogger(NettyServerRunner.class);
    @Resource
    HttpServerConfig httpServerConfig;
    @Override
    public void run(String... args) throws Exception {

        ExecutionJob.EXECUTOR.submit(() -> {
            try {
                new NettyServer(Integer.parseInt(httpServerConfig.getPatrolTcpPort())).run();
                logger.info("Netty TCP server is started!");
            } catch (Exception e) {
                logger.error("Netty TCP server start failed!", e);
                throw new RuntimeException("Netty TCP server start failed!", e);
            }
        });
    }


}

