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

io.ryos.rhino.sdk.HttpClient Maven / Gradle / Ivy

The newest version!
package io.ryos.rhino.sdk;

import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.Dsl;
import org.asynchttpclient.filter.ThrottleRequestFilter;

/**
 * HttpClient singleton instance.
 *
 * @author Erhan Bagdemir
 * @since 2.0.0
 */
public enum HttpClient {

  INSTANCE;

  private AsyncHttpClient client;

  HttpClient() {

    var httpClientConfig = Dsl.config()
        .setKeepAlive(true)
        .setMaxConnections(SimulationConfig.getMaxConnections())
        .setMaxConnectionsPerHost(SimulationConfig.getMaxConnections())
        .setConnectTimeout(SimulationConfig.getHttpConnectTimeout())
        .setHandshakeTimeout(SimulationConfig.getHttpHandshakeTimeout())
        .setReadTimeout(SimulationConfig.getHttpReadTimeout())
        .setRequestTimeout(SimulationConfig.getHttpRequestTimeout())
        .addRequestFilter(new ThrottleRequestFilter(SimulationConfig.getMaxConnections()))
        .build();

    this.client = Dsl.asyncHttpClient(httpClientConfig);
  }

  public AsyncHttpClient getClient() {
    return client;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy