package com.cm.central.control.client.socket.startup;

import com.cm.central.control.client.socket.socket.SocketClientRunnable;
import com.cm.socket.pojo.SocketClient;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: SocketClientStartUp
 * @Description: Socket客户端启动
 * @Author: WangGeng
 * @Date: 2020/7/29 4:55 下午
 * @Version: 1.0
 **/
@Component
public class SocketClientStartUp implements ApplicationRunner {

    private static final Logger LOG = LoggerFactory.getLogger(SocketClientStartUp.class);
    @Value("${socket.central-control.active:false}")
    private Boolean socketServerActive;

    @Autowired
    private SocketClientRunnable socketClientRunnable;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (socketServerActive != null && socketServerActive) {
            new Thread(socketClientRunnable).start();
        } else {
            LOG.debug("Socket监控未激活");
        }
    }
}
