package com.tzld.piaoquan.recommend.server.common;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author dyp
 */
public final class ThreadPoolFactory {
    private final static ExecutorService DEFAULT = new CommonThreadPoolExecutor(
            64,
            64,
            0L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(1000),
            new ThreadFactoryBuilder().setNameFormat("DEFAULT-%d").build(),
            new ThreadPoolExecutor.AbortPolicy());
    public final static ExecutorService RECALL = new CommonThreadPoolExecutor(
            256,
            256,
            0L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(1000),
            new ThreadFactoryBuilder().setNameFormat("RecallService-%d").build(),
            new ThreadPoolExecutor.AbortPolicy());
    private final static ExecutorService FILTER = new CommonThreadPoolExecutor(
            256,
            256,
            0L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(1000),
            new ThreadFactoryBuilder().setNameFormat("FilterService-%d").build(),
            new ThreadPoolExecutor.AbortPolicy());

    private final static ExecutorService LOG = new CommonThreadPoolExecutor(
            128,
            128,
            0L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(1000),
            new ThreadFactoryBuilder().setNameFormat("LogService-%d").build(),
            new ThreadPoolExecutor.AbortPolicy());

    public static ExecutorService defaultPool() {
        return DEFAULT;
    }

    public static ExecutorService recallPool() {
        return RECALL;
    }

    public static ExecutorService filterPool() {
        return FILTER;
    }

    public static ExecutorService logPool() {
        return LOG;
    }

}
