public HttpClientFactory()

in aliyun-sdk-opensearch/src/main/java/com/aliyun/opensearch/util/HttpClientFactory.java [105:140]


    public HttpClientFactory(int timeout, int connectTimeout, int connections, int cleanIdleConnInitDelay,
                             int cleanIdleConnInterval) {
        if (timeout <= 0) {
            timeout = this.timeout;
        }

        if (connectTimeout <= 0) {
            connectTimeout = this.connectTimeout;
        }

        if (connections > 0 && maxConnections != connections) {
            maxConnections = connections;
        }

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
        schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

        connectionManager = new PoolingClientConnectionManager(schemeRegistry);
        connectionManager.setMaxTotal(maxConnections);
        connectionManager.setDefaultMaxPerRoute(maxConnections);

        scheduledExeService = Executors.newScheduledThreadPool(1,
            new DaemonThreadFactory("Http-client-ConenctionPool-Monitor"));
        scheduledExeService.scheduleAtFixedRate(new IdleConnectionMonitor(connectionManager), CLEAN_INIT_DELAY,
            clean_check_interval, TimeUnit.MILLISECONDS);

        this.httpClient = new DefaultHttpClient(connectionManager);

        this.params = httpClient.getParams();

        HttpConnectionParams.setSoTimeout(params, timeout);
        HttpConnectionParams.setConnectionTimeout(params, connectTimeout);
        HttpConnectionParams.setTcpNoDelay(params, Boolean.TRUE);
        HttpConnectionParams.setStaleCheckingEnabled(params, Boolean.FALSE);
    }