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

cn.majingjing.http.client.config.HttpClientConfig Maven / Gradle / Ivy

package cn.majingjing.http.client.config;

import cn.majingjing.http.client.interceptor.HttpInterceptor;
import cn.majingjing.http.client.interceptor.impl.HttpTraceIdInterceptor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author MaMarion
 * @date 2021/2/23
 */
public class HttpClientConfig {

    private List interceptors = new ArrayList<>();
    {
        interceptors.add(0,new HttpTraceIdInterceptor());
    }
    /**
     * 头信息
     */
    private final Map headers = new HashMap<>(4);
    /**
     * 连接超时时间 (默认10s)
     */
    private int connectTimeout = 10000;
    /**
     * 流读取超时时间 (默认10s)
     */
    private int readTimeout = 10000;
    /**
     * 流写入超时时间 (默认10s)
     */
    private int writeTimeout = 10000;
    /**
     * 失败最大重试次数 (默认不重试)
     */
    private int maxRetry = 0;

    /**
     * 异步线程池核心线程数
     */
    private int asyncExecuteThreadPoolCorePoolSize = 3;
    /**
     * 异步线程池最大线程数
     */
    private int asyncExecuteThreadPoolMaxPoolSize = 8;



    public List getInterceptors() {
        return interceptors;
    }

    /**
     * 添加拦截器
     *
     * @param interceptor 拦截器
     */
    public HttpClientConfig addInterceptor(HttpInterceptor interceptor) {
        this.interceptors.add(interceptor);
        return this;
    }

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public HttpClientConfig setConnectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
        return this;
    }

    public int getReadTimeout() {
        return readTimeout;
    }

    public HttpClientConfig setReadTimeout(int readTimeout) {
        this.readTimeout = readTimeout;
        return this;
    }

    public int getWriteTimeout() {
        return writeTimeout;
    }

    public HttpClientConfig setWriteTimeout(int writeTimeout) {
        this.writeTimeout = writeTimeout;
        return this;
    }

    public int getMaxRetry() {
        return maxRetry;
    }

    public HttpClientConfig setMaxRetry(int maxRetry) {
        this.maxRetry = maxRetry;
        return this;
    }

    public Map getHeaders() {
        return headers;
    }

    public void setAsyncExecuteThreadPool(int corePoolSize,
                                          int maximumPoolSize){
        this.asyncExecuteThreadPoolCorePoolSize = corePoolSize;
        this.asyncExecuteThreadPoolMaxPoolSize = maximumPoolSize;
    }

    public int getAsyncExecuteThreadPoolCorePoolSize() {
        return asyncExecuteThreadPoolCorePoolSize;
    }

    public int getAsyncExecuteThreadPoolMaxPoolSize() {
        return asyncExecuteThreadPoolMaxPoolSize;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy