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

com.github.joekerouac.common.tools.net.http.config.IHttpClientConfig Maven / Gradle / Ivy

The newest version!
// Generated by delombok at Fri Mar 14 11:41:38 CST 2025
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
 * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
 * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.github.joekerouac.common.tools.net.http.config;

import java.net.InetAddress;
import java.nio.charset.Charset;
import java.util.concurrent.ThreadFactory;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import com.github.joekerouac.common.tools.constant.Const;
import com.github.joekerouac.common.tools.net.http.dns.IDnsResolver;

/**
 * HTTP客户端配置
 *
 * @author JoeKerouac
 * @date 2022-10-14 14:37:00
 * @since 1.0.0
 */
public final class IHttpClientConfig {
    /**
     * 默认保持连接数
     */
    private static final int DEFAULT_MAX_TOTAL = 200;
    /**
     * 默认每个站点可以保持的最大连接数
     */
    private static final int DEFAULT_MAX_PER_ROUTE = 20;
    /**
     * 默认缓冲区大小,单位byte
     */
    private static final int DEFAULT_BUFFER_SIZE = 1024 * 8;
    /**
     * 默认传输超时时间
     */
    private static final int DEFAULT_SOCKET_TIMEOUT = 60 * 1000;
    /**
     * 数据传输超时时间,单位毫秒,默认一分钟
     */
    private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
    /**
     * HTTP1协议栈配置
     */
    @NotNull
    private IHttp1config http1config = new IHttp1config();
    /**
     * 总共可以保持的连接数
     */
    @Min(1)
    @Max(500)
    private int maxTotal = DEFAULT_MAX_TOTAL;
    /**
     * 每个站点可以保持的最大连接数(目标ip+port表示一个站点)
     */
    @Min(1)
    @Max(50)
    private int defaultMaxPerRoute = DEFAULT_MAX_PER_ROUTE;
    /**
     * 是否保持连接
     */
    private boolean keepAlive = true;
    /**
     * IO线程数;
     *
     * PS:注意,如果使用了异步请求,那么请求回调也在该线程执行,注意不要阻塞
     */
    @Min(1)
    @Max(10)
    private int ioThreadCount = Math.min(Math.max(2, Runtime.getRuntime().availableProcessors()), 10);
    /**
     * IO线程工厂
     */
    private ThreadFactory threadFactory;
    /**
     * socket的tcpNoDelay选项
     */
    private boolean tcpNoDelay = true;
    /**
     * socket发送缓冲,单位byte
     */
    @Min(512)
    @Max(1024 * 1024)
    private int sndBufSize = DEFAULT_BUFFER_SIZE;
    /**
     * socket接收缓冲,单位byte
     */
    @Min(512)
    @Max(1024 * 1024)
    private int rcvBufSize = DEFAULT_BUFFER_SIZE;
    /**
     * 默认连接编码字符集
     */
    private Charset charset = Const.DEFAULT_CHARSET;
    /**
     * 用户代理
     */
    @NotBlank
    private String userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0";
    /**
     * http代理
     */
    private HttpProxy proxy;
    /**
     * 要绑定的本地网卡地址,允许为空
     */
    private InetAddress localAddress;
    /**
     * dns解析器,允许为空
     */
    private IDnsResolver dnsResolver;
    /**
     * 全局请求配置
     */
    @NotNull
    private IHttpConfig httpConfig = new IHttpConfig();

    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public IHttpClientConfig() {
    }

    /**
     * 数据传输超时时间,单位毫秒,默认一分钟
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int getSocketTimeout() {
        return this.socketTimeout;
    }

    /**
     * HTTP1协议栈配置
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public IHttp1config getHttp1config() {
        return this.http1config;
    }

    /**
     * 总共可以保持的连接数
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int getMaxTotal() {
        return this.maxTotal;
    }

    /**
     * 每个站点可以保持的最大连接数(目标ip+port表示一个站点)
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int getDefaultMaxPerRoute() {
        return this.defaultMaxPerRoute;
    }

    /**
     * 是否保持连接
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public boolean isKeepAlive() {
        return this.keepAlive;
    }

    /**
     * IO线程数;
     *
     * PS:注意,如果使用了异步请求,那么请求回调也在该线程执行,注意不要阻塞
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int getIoThreadCount() {
        return this.ioThreadCount;
    }

    /**
     * IO线程工厂
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public ThreadFactory getThreadFactory() {
        return this.threadFactory;
    }

    /**
     * socket的tcpNoDelay选项
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public boolean isTcpNoDelay() {
        return this.tcpNoDelay;
    }

    /**
     * socket发送缓冲,单位byte
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int getSndBufSize() {
        return this.sndBufSize;
    }

    /**
     * socket接收缓冲,单位byte
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int getRcvBufSize() {
        return this.rcvBufSize;
    }

    /**
     * 默认连接编码字符集
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public Charset getCharset() {
        return this.charset;
    }

    /**
     * 用户代理
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public String getUserAgent() {
        return this.userAgent;
    }

    /**
     * http代理
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public HttpProxy getProxy() {
        return this.proxy;
    }

    /**
     * 要绑定的本地网卡地址,允许为空
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public InetAddress getLocalAddress() {
        return this.localAddress;
    }

    /**
     * dns解析器,允许为空
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public IDnsResolver getDnsResolver() {
        return this.dnsResolver;
    }

    /**
     * 全局请求配置
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public IHttpConfig getHttpConfig() {
        return this.httpConfig;
    }

    /**
     * 数据传输超时时间,单位毫秒,默认一分钟
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setSocketTimeout(final int socketTimeout) {
        this.socketTimeout = socketTimeout;
    }

    /**
     * HTTP1协议栈配置
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setHttp1config(final IHttp1config http1config) {
        this.http1config = http1config;
    }

    /**
     * 总共可以保持的连接数
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setMaxTotal(final int maxTotal) {
        this.maxTotal = maxTotal;
    }

    /**
     * 每个站点可以保持的最大连接数(目标ip+port表示一个站点)
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setDefaultMaxPerRoute(final int defaultMaxPerRoute) {
        this.defaultMaxPerRoute = defaultMaxPerRoute;
    }

    /**
     * 是否保持连接
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setKeepAlive(final boolean keepAlive) {
        this.keepAlive = keepAlive;
    }

    /**
     * IO线程数;
     *
     * PS:注意,如果使用了异步请求,那么请求回调也在该线程执行,注意不要阻塞
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setIoThreadCount(final int ioThreadCount) {
        this.ioThreadCount = ioThreadCount;
    }

    /**
     * IO线程工厂
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setThreadFactory(final ThreadFactory threadFactory) {
        this.threadFactory = threadFactory;
    }

    /**
     * socket的tcpNoDelay选项
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setTcpNoDelay(final boolean tcpNoDelay) {
        this.tcpNoDelay = tcpNoDelay;
    }

    /**
     * socket发送缓冲,单位byte
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setSndBufSize(final int sndBufSize) {
        this.sndBufSize = sndBufSize;
    }

    /**
     * socket接收缓冲,单位byte
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setRcvBufSize(final int rcvBufSize) {
        this.rcvBufSize = rcvBufSize;
    }

    /**
     * 默认连接编码字符集
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setCharset(final Charset charset) {
        this.charset = charset;
    }

    /**
     * 用户代理
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setUserAgent(final String userAgent) {
        this.userAgent = userAgent;
    }

    /**
     * http代理
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setProxy(final HttpProxy proxy) {
        this.proxy = proxy;
    }

    /**
     * 要绑定的本地网卡地址,允许为空
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setLocalAddress(final InetAddress localAddress) {
        this.localAddress = localAddress;
    }

    /**
     * dns解析器,允许为空
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setDnsResolver(final IDnsResolver dnsResolver) {
        this.dnsResolver = dnsResolver;
    }

    /**
     * 全局请求配置
     */
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setHttpConfig(final IHttpConfig httpConfig) {
        this.httpConfig = httpConfig;
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public boolean equals(final java.lang.Object o) {
        if (o == this) return true;
        if (!(o instanceof IHttpClientConfig)) return false;
        final IHttpClientConfig other = (IHttpClientConfig) o;
        if (this.getSocketTimeout() != other.getSocketTimeout()) return false;
        if (this.getMaxTotal() != other.getMaxTotal()) return false;
        if (this.getDefaultMaxPerRoute() != other.getDefaultMaxPerRoute()) return false;
        if (this.isKeepAlive() != other.isKeepAlive()) return false;
        if (this.getIoThreadCount() != other.getIoThreadCount()) return false;
        if (this.isTcpNoDelay() != other.isTcpNoDelay()) return false;
        if (this.getSndBufSize() != other.getSndBufSize()) return false;
        if (this.getRcvBufSize() != other.getRcvBufSize()) return false;
        final java.lang.Object this$http1config = this.getHttp1config();
        final java.lang.Object other$http1config = other.getHttp1config();
        if (this$http1config == null ? other$http1config != null : !this$http1config.equals(other$http1config)) return false;
        final java.lang.Object this$threadFactory = this.getThreadFactory();
        final java.lang.Object other$threadFactory = other.getThreadFactory();
        if (this$threadFactory == null ? other$threadFactory != null : !this$threadFactory.equals(other$threadFactory)) return false;
        final java.lang.Object this$charset = this.getCharset();
        final java.lang.Object other$charset = other.getCharset();
        if (this$charset == null ? other$charset != null : !this$charset.equals(other$charset)) return false;
        final java.lang.Object this$userAgent = this.getUserAgent();
        final java.lang.Object other$userAgent = other.getUserAgent();
        if (this$userAgent == null ? other$userAgent != null : !this$userAgent.equals(other$userAgent)) return false;
        final java.lang.Object this$proxy = this.getProxy();
        final java.lang.Object other$proxy = other.getProxy();
        if (this$proxy == null ? other$proxy != null : !this$proxy.equals(other$proxy)) return false;
        final java.lang.Object this$localAddress = this.getLocalAddress();
        final java.lang.Object other$localAddress = other.getLocalAddress();
        if (this$localAddress == null ? other$localAddress != null : !this$localAddress.equals(other$localAddress)) return false;
        final java.lang.Object this$dnsResolver = this.getDnsResolver();
        final java.lang.Object other$dnsResolver = other.getDnsResolver();
        if (this$dnsResolver == null ? other$dnsResolver != null : !this$dnsResolver.equals(other$dnsResolver)) return false;
        final java.lang.Object this$httpConfig = this.getHttpConfig();
        final java.lang.Object other$httpConfig = other.getHttpConfig();
        if (this$httpConfig == null ? other$httpConfig != null : !this$httpConfig.equals(other$httpConfig)) return false;
        return true;
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        result = result * PRIME + this.getSocketTimeout();
        result = result * PRIME + this.getMaxTotal();
        result = result * PRIME + this.getDefaultMaxPerRoute();
        result = result * PRIME + (this.isKeepAlive() ? 79 : 97);
        result = result * PRIME + this.getIoThreadCount();
        result = result * PRIME + (this.isTcpNoDelay() ? 79 : 97);
        result = result * PRIME + this.getSndBufSize();
        result = result * PRIME + this.getRcvBufSize();
        final java.lang.Object $http1config = this.getHttp1config();
        result = result * PRIME + ($http1config == null ? 43 : $http1config.hashCode());
        final java.lang.Object $threadFactory = this.getThreadFactory();
        result = result * PRIME + ($threadFactory == null ? 43 : $threadFactory.hashCode());
        final java.lang.Object $charset = this.getCharset();
        result = result * PRIME + ($charset == null ? 43 : $charset.hashCode());
        final java.lang.Object $userAgent = this.getUserAgent();
        result = result * PRIME + ($userAgent == null ? 43 : $userAgent.hashCode());
        final java.lang.Object $proxy = this.getProxy();
        result = result * PRIME + ($proxy == null ? 43 : $proxy.hashCode());
        final java.lang.Object $localAddress = this.getLocalAddress();
        result = result * PRIME + ($localAddress == null ? 43 : $localAddress.hashCode());
        final java.lang.Object $dnsResolver = this.getDnsResolver();
        result = result * PRIME + ($dnsResolver == null ? 43 : $dnsResolver.hashCode());
        final java.lang.Object $httpConfig = this.getHttpConfig();
        result = result * PRIME + ($httpConfig == null ? 43 : $httpConfig.hashCode());
        return result;
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public java.lang.String toString() {
        return "IHttpClientConfig(socketTimeout=" + this.getSocketTimeout() + ", http1config=" + this.getHttp1config() + ", maxTotal=" + this.getMaxTotal() + ", defaultMaxPerRoute=" + this.getDefaultMaxPerRoute() + ", keepAlive=" + this.isKeepAlive() + ", ioThreadCount=" + this.getIoThreadCount() + ", threadFactory=" + this.getThreadFactory() + ", tcpNoDelay=" + this.isTcpNoDelay() + ", sndBufSize=" + this.getSndBufSize() + ", rcvBufSize=" + this.getRcvBufSize() + ", charset=" + this.getCharset() + ", userAgent=" + this.getUserAgent() + ", proxy=" + this.getProxy() + ", localAddress=" + this.getLocalAddress() + ", dnsResolver=" + this.getDnsResolver() + ", httpConfig=" + this.getHttpConfig() + ")";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy