package com.ozs.da.job;

import com.ozs.da.constant.Constant;
import com.ozs.da.entity.model.ScheduleRoundEvent;
import com.ozs.da.entity.remotedb.MdmInfoDatabase;
import com.ozs.da.entity.task.Task;
import com.ozs.da.service.job.JobService;
import com.lmax.disruptor.RingBuffer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 许明
 * on 2019/3/6.
 * @version 2.0.0
 */
@Order(1)
public class JobServer implements CommandLineRunner {

    private static final Logger logger = LogManager.getLogger(JobServer.class);

    public static RingBuffer<ScheduleRoundEvent> SCHEDULE_CONDITION_JUDGE_BUFFER;// 条件轮询判断队列(无锁队列)
    public static ConcurrentHashMap<String, Task> MEM_JOB_CACHE = new ConcurrentHashMap<String, Task>();// 存放从数据库中查询出来的所有JOB
    // 存放新增任务选中的数据源信息
    public static ConcurrentHashMap<String, MdmInfoDatabase> SOURCE_AND_TARGET_DB_INFO_CACHE = new ConcurrentHashMap<String, MdmInfoDatabase>();

    @Autowired
    private JobService jobService;

    @Override
    public void run(String... args) throws Exception {
        logger.info("初始化数据中心调度任务轮询线程池start ...........................");
        int initResult = jobService.init();
        if(Constant.RETURN_FAILD == initResult){
            logger.info("退出系统");
            System.exit(0);
        }
        logger.info("初始化数据中心调度任务轮询线程池end ...........................");

    }
}
