All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.schoolwow.download.module.pool.domain.PoolContext Maven / Gradle / Ivy

package cn.schoolwow.download.module.pool.domain;

import cn.schoolwow.download.domain.pool.PoolConfig;
import cn.schoolwow.download.domain.progress.DownloadProgress;
import cn.schoolwow.download.domain.task.DownloadTask;
import cn.schoolwow.download.module.pool.flow.DownloadSingleFlowListener;
import cn.schoolwow.quickflow.QuickFlow;
import cn.schoolwow.quickflow.QuickFlowBuilder;
import cn.schoolwow.quickflow.dto.FlowContextDataRange;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

/**下载池上下文对象*/
public class PoolContext {
    public PoolConfig poolConfig = new PoolConfig();

    /**下载任务调度线程池*/
    public ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            Runtime.getRuntime().availableProcessors(),
            Runtime.getRuntime().availableProcessors(),
            1,
            TimeUnit.MINUTES,
            new LinkedBlockingQueue<>(),
            new NamedThreadFactory("quickdownload-dispatch")
    );
    {
        threadPoolExecutor.allowCoreThreadTimeOut(true);
    }

    /**实际http下载线程池*/
    public ThreadPoolExecutor downloadThreadPoolExecutor = new ThreadPoolExecutor(
            threadPoolExecutor.getCorePoolSize()*Runtime.getRuntime().availableProcessors()*2,
            threadPoolExecutor.getCorePoolSize()*Runtime.getRuntime().availableProcessors()*2,
            1,
            TimeUnit.MINUTES,
            new LinkedBlockingQueue<>(),
            new NamedThreadFactory("quickdownload-download")
    );
    {
        downloadThreadPoolExecutor.allowCoreThreadTimeOut(true);
    }

    /**批量任务下载完成后处理线程池*/
    public ThreadPoolExecutor postDownloadTaskThreadPoolExecutor = new ThreadPoolExecutor(
            Runtime.getRuntime().availableProcessors()*2,
            Runtime.getRuntime().availableProcessors()*2,
            1,
            TimeUnit.MINUTES,
            new LinkedBlockingQueue<>(),
            new NamedThreadFactory("quickdownload-post")
    );
    {
        postDownloadTaskThreadPoolExecutor.allowCoreThreadTimeOut(true);
    }

    /**下载任务列表*/
    public final Map> downloadTaskFutureMap = new HashMap<>();

    /**下载进度*/
    public final List downloadProgressList = new ArrayList<>();

    /**暂停任务列表*/
    public final Map pauseDownloadTaskMap = new ConcurrentHashMap<>();

    /**流程对象*/
    public QuickFlow quickFlow = QuickFlowBuilder.newInstance()
            .putContextTemporaryInstanceData(this)
            .putContextTemporaryInstanceData(this.poolConfig)
            .singleFlowListener(new DownloadSingleFlowListener());
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy