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.core.async.store.TaskExecutorQueue;
import com.elab.log.utils.CatCrossProcess;

import java.util.Map;

/**
 * 消息串联队列
 *
 * @author ： liukx
 * @time ： 2020/8/7 - 11:02
 */
public class CatTaskProducer extends TaskProducer {

    public CatTaskProducer(TaskExecutorQueue taskExecutorQueue) {
        super(taskExecutorQueue);
    }

    @Override
    public boolean sendRealTimeQueue(RealTaskExecutor taskExecutor) {
        return sendRealTimeQueue(taskExecutor, noSave());
    }

    private TaskStoreData noSave() {
        TaskStoreData storeData = new TaskStoreData();
        storeData.setSave(false);
        return storeData;
    }

    @Override
    public boolean sendRealTimeQueue(RealTaskExecutor taskExecutor, TaskStoreData taskStoreData) {
        //构建消息上下文
        Map<String, String> msgContextMap = CatCrossProcess.getMsgContextMap();
        if (taskStoreData == null) {
            taskStoreData = new TaskStoreData();
        }
        taskStoreData.getDataMap().putAll(msgContextMap);
        // 构建消息串联执行器
        CatRealTaskExecutor catRealTaskExecutor = new CatRealTaskExecutor(TaskEnums.RealTime, taskExecutor,
                taskStoreData);
        return super.sendRealTimeQueue(catRealTaskExecutor, taskStoreData);
    }

}
