package com.friday.custody.config;

import com.alibaba.dubbo.common.utils.NamedThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {

    @Bean(name = "pullDataThreadPool")
    public ExecutorService getPullDataThreadPool() {
        ThreadPoolExecutor pullDataThreadPool = new ThreadPoolExecutor(16, 16, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("per12H"),
                new ThreadPoolExecutor.AbortPolicy());
        pullDataThreadPool.allowCoreThreadTimeOut(true);
        return pullDataThreadPool;
    }


    /*@Bean(name = "initHtscDataPool")
    public ExecutorService getInitHtscDataPool() {
        ThreadPoolExecutor initHtscDataPool = new ThreadPoolExecutor(16, 16, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("per24H"),
                new ThreadPoolExecutor.AbortPolicy());
        initHtscDataPool.allowCoreThreadTimeOut(true);
        return initHtscDataPool;
    }

    @Bean(name = "pullRemoteDataFirstPool")
    public ExecutorService getPullRemoteDataFirstPool() {
        ThreadPoolExecutor pullRemoteDataFirstPool = new ThreadPoolExecutor(16, 16, 60, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("per12M"),
                new ThreadPoolExecutor.AbortPolicy());
        pullRemoteDataFirstPool.allowCoreThreadTimeOut(true);
        return pullRemoteDataFirstPool;
    }*/

    @Bean(name = "updateData30minPool")
    public ExecutorService getUpdateData20min() {
        ThreadPoolExecutor updateData30minPool = new ThreadPoolExecutor(32, 32, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("per30M"),
                new ThreadPoolExecutor.AbortPolicy());
        updateData30minPool.allowCoreThreadTimeOut(true);
        return updateData30minPool;
    }

    @Bean(name = "updateZhongXinDataPool")
    public ExecutorService getUpdateZhongXinDataPool() {
        ThreadPoolExecutor updateZhongXinDataPool = new ThreadPoolExecutor(16, 16, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("per12HZX"),
                new ThreadPoolExecutor.AbortPolicy());
        updateZhongXinDataPool.allowCoreThreadTimeOut(true);
        return updateZhongXinDataPool;

    }

    @Bean(name = "updateData1hPool")
    public ExecutorService getUpdateData1hPool() {
        ThreadPoolExecutor updateData1hPool = new ThreadPoolExecutor(16, 16, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("per1H"),
                new ThreadPoolExecutor.AbortPolicy());
        updateData1hPool.allowCoreThreadTimeOut(true);
        return updateData1hPool;
    }

    @Bean(name = "updateDataCJPool")
    public ExecutorService updateDataCJDailyByScheduled() {
        ThreadPoolExecutor updateDataCJPool = new ThreadPoolExecutor(16, 16, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("at21H"),
                new ThreadPoolExecutor.AbortPolicy());
        updateDataCJPool.allowCoreThreadTimeOut(true);
        return updateDataCJPool;
    }


    @Bean(name = "initTenantDataThreadPool")
    public ExecutorService initTenantDataThreadPool() {
        return new ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }
    @Bean(name = "updateZhongxTotalAssetPool")
    public ExecutorService updateZhongxTotalAssetPool() {
        ThreadPoolExecutor updateZhongxTotalAssetPool = new ThreadPoolExecutor(16, 16, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("perZxta"),
                new ThreadPoolExecutor.AbortPolicy());
        updateZhongxTotalAssetPool.allowCoreThreadTimeOut(true);
        return updateZhongxTotalAssetPool;
    }
    @Bean(name = "updateNetValuePool")
    public ExecutorService updateNetValuePool() {
        ThreadPoolExecutor updateNetValuePool = new ThreadPoolExecutor(16, 16, 5, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new NamedThreadFactory("netValue"),
                new ThreadPoolExecutor.AbortPolicy());
        updateNetValuePool.allowCoreThreadTimeOut(true);
        return updateNetValuePool;
    }
}
