package com.elab.log.ext;

import com.elab.log.utils.CatCrossProcess;
import com.elab.log.utils.CatMsgConstants;

import java.util.Map;
import java.util.function.Supplier;

/**
 * @Module 异步线程
 * @Description
 * @Author liukaixiong
 * @Date 2021/1/22 15:55
 */
public class CatSupplier<T> implements Supplier<T> {

    private Supplier<T> supplier;

    private Map<String, String> msgContextMap;

    private final String name = "supplier_thread";

    public CatSupplier(Supplier<T> supplier) {
        this.msgContextMap = CatCrossProcess.getMsgContextMap();
        this.supplier = supplier;
    }

    @Override
    public T get() {
        return CatCrossProcess.buildRemoteMsg(CatMsgConstants.LOCAL_THREAD_SERVER, name, this.msgContextMap, () -> {
            return this.supplier.get();
        });
    }
}
