package com.elab.core.async.consumer;

import com.elab.core.async.store.TaskExecutorQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 任务消费者
 *
 * @author ： liukx
 * @time ： 2020/8/6 - 13:41
 */
public class TaskConsumer {

    private Logger logger = LoggerFactory.getLogger(TaskConsumer.class);

    private TaskExecutorQueue taskExecutorQueue;

    private RealTimeConsumer realTimeConsumer;

    private SchedulingConsumer schedulingConsumer;

    public TaskConsumer(TaskExecutorQueue taskExecutorQueue) {
        this.taskExecutorQueue = taskExecutorQueue;
    }

    /**
     * 开启实时消费异步线程
     */
    public void startRealTimeConsumer() {
        this.realTimeConsumer = new RealTimeConsumer(this.taskExecutorQueue.getRealTimeQueue());
        Thread realThread = new Thread(this.realTimeConsumer, "elab-realTimeConsumer");
        realThread.start();
        logger.info("开启实时消费异步线程");
    }

    /**
     * 开启调度消费线程
     * @param intervalSecond 调度间隔时间
     */
    public void startSchedulingConsumer(Integer intervalSecond) {
        this.schedulingConsumer = new SchedulingConsumer(this.taskExecutorQueue.getSchedulingList(), intervalSecond);
        Thread schedulingThread = new Thread(this.schedulingConsumer, "elab-schedulingConsumer");
        schedulingThread.start();
        logger.info("开启定时消费异步线程");
    }
}
