package com.elab.log.ext;

import com.elab.core.async.RealTaskExecutor;
import com.elab.core.async.TaskEnums;
import com.elab.core.async.model.TaskStoreData;
import com.elab.core.async.pruducer.TaskProducer;
import com.elab.log.utils.CatCrossProcess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 消息异步串联
 *
 * @author ： liukx
 * @time ： 2020/8/7 - 10:51
 */
public class CatRealTaskExecutor implements RealTaskExecutor {
    private Logger logger = LoggerFactory.getLogger(getClass());
    private RealTaskExecutor realTaskExecutor;

    private TaskStoreData taskStoreData;

    private TaskEnums taskEnums;

    public CatRealTaskExecutor(TaskEnums taskEnums, RealTaskExecutor realTaskExecutor, TaskStoreData taskStoreData) {
        this.taskEnums = taskEnums;
        this.realTaskExecutor = realTaskExecutor;
        this.taskStoreData = taskStoreData;
    }

    @Override
    public void run() {
        Map<String, String> dataMap = taskStoreData.getDataMap();

        CatCrossProcess.buildRemoteMsg("privateQueue", taskEnums.name(), dataMap, () -> {
            try {
                realTaskExecutor.run();
                //MonitorSendProducer.sendMsg(taskStoreData);
                return true;
            } catch (Exception e) {
                logger.error("线程消费失败", e);
            }
            return false;
        });
    }

    public static void main(String[] args) {
        TaskProducer taskProducer = null;

    }
}
