package com.elab.log.ext;

import com.dianping.cat.message.Transaction;
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.AbstractTaskProducer;
import com.elab.log.utils.CatCrossProcess;

import java.util.Map;

/**
 * 消息异步串联
 *
 * @author ： liukx
 * @time ： 2020/8/7 - 10:51
 */
public class CatRealTaskExecutor implements RealTaskExecutor {

    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();
        Transaction t = CatCrossProcess.buildCrossMsg("privateQueue", taskEnums.name(), dataMap);
        try {
            realTaskExecutor.run();
            t.setSuccessStatus();
        } catch (Exception e) {
            t.setStatus(e);
        } finally {
            t.complete();
        }
    }

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

    }
}
