Java Code Examples for org.eclipse.jetty.client.HttpClient#setMaxConnectionsPerDestination()

The following examples show how to use org.eclipse.jetty.client.HttpClient#setMaxConnectionsPerDestination() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InjectionModule.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
private HttpClient createHttpClient() {
    //Allow ssl by default
    SslContextFactory sslContextFactory = new SslContextFactory();
    //Don't exclude RSA because Sixt needs them, dammit!
    sslContextFactory.setExcludeCipherSuites("");
    HttpClient client = new HttpClient(sslContextFactory);
    client.setFollowRedirects(false);
    client.setMaxConnectionsPerDestination(16);
    client.setRequestBufferSize(65536);
    client.setConnectTimeout(FeatureFlags.getHttpConnectTimeout(serviceProperties));
    client.setAddressResolutionTimeout(FeatureFlags.getHttpAddressResolutionTimeout(serviceProperties));
    //You can set more restrictive timeouts per request, but not less, so
    //  we set the maximum timeout of 1 hour here.
    client.setIdleTimeout(60 * 60 * 1000);
    try {
        client.start();
    } catch (Exception e) {
        logger.error("Error building http client", e);
    }
    return client;
}
 
Example 2
Source File: ServiceImpersonatorLoadBalancer.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
private HttpClient createHttpClient() {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setExcludeCipherSuites("");
    HttpClient client = new HttpClient(sslContextFactory);
    client.setFollowRedirects(false);
    client.setMaxConnectionsPerDestination(2);
    //You can set more restrictive timeouts per request, but not less, so
    //  we set the maximum timeout of 1 hour here.
    client.setIdleTimeout(60 * 60 * 1000);
    try {
        client.start();
    } catch (Exception e) {
        logger.error("Error building http client", e);
    }
    return client;
}
 
Example 3
Source File: TestInjectionModule.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
@Provides
public HttpClient getHttpClient() {
	HttpClient client = new HttpClient();
	client.setFollowRedirects(false);
	client.setMaxConnectionsPerDestination(32);
	client.setConnectTimeout(100);
	client.setAddressResolutionTimeout(100);
	//You can set more restrictive timeouts per request, but not less, so
	//  we set the maximum timeout of 1 hour here.
	client.setIdleTimeout(60 * 60 * 1000);
	try {
		client.start();
	} catch (Exception e) {
		logger.error("Error building http client", e);
	}
	return client;
}
 
Example 4
Source File: HttpRpcEndpoint.java    From nutzcloud with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    client = new HttpClient(new SslContextFactory(true));
    client.setFollowRedirects(false);
    client.setCookieStore(new HttpCookieStore.Empty());

    executor = new QueuedThreadPool(conf.getInt(PRE + ".maxThreads", 256));
    client.setExecutor(executor);
    client.setMaxConnectionsPerDestination(conf.getInt(PRE + ".maxConnections", 256));
    client.setIdleTimeout(conf.getLong(PRE + ".idleTimeout", 30000));

    client.setConnectTimeout(conf.getLong(PRE + ".connectTime", 1000));

    if (conf.has(PRE + "requestBufferSize"))
        client.setRequestBufferSize(conf.getInt(PRE + "requestBufferSize"));

    if (conf.has(PRE + "responseBufferSize"))
        client.setResponseBufferSize(conf.getInt(PRE + "responseBufferSize"));

    client.start();

    // Content must not be decoded, otherwise the client gets confused.
    client.getContentDecoderFactories().clear();

    // Pass traffic to the client, only intercept what's necessary.
    ProtocolHandlers protocolHandlers = client.getProtocolHandlers();
    protocolHandlers.clear();
}
 
Example 5
Source File: HttpClientModule.java    From EDDI with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public HttpClient provideHttpClient(ExecutorService executorService,
                                    @Named("httpClient.maxConnectionsQueued") Integer maxConnectionsQueued,
                                    @Named("httpClient.maxConnectionPerRoute") Integer maxConnectionPerRoute,
                                    @Named("httpClient.requestBufferSize") Integer requestBufferSize,
                                    @Named("httpClient.responseBufferSize") Integer responseBufferSize,
                                    @Named("httpClient.maxRedirects") Integer maxRedirects,
                                    @Named("httpClient.trustAllCertificates") Boolean trustAllCertificates) {

    try {
        SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
        sslContextFactory.setTrustAll(trustAllCertificates);
        HttpClient httpClient = new HttpClient(sslContextFactory);
        httpClient.setExecutor(executorService);
        httpClient.setMaxConnectionsPerDestination(maxConnectionsQueued);
        httpClient.setMaxRequestsQueuedPerDestination(maxConnectionPerRoute);
        httpClient.setRequestBufferSize(requestBufferSize);
        httpClient.setResponseBufferSize(responseBufferSize);
        httpClient.setMaxRedirects(maxRedirects);
        httpClient.start();

        registerHttpClientShutdownHook(httpClient);

        return httpClient;
    } catch (Exception e) {
        System.out.println(Arrays.toString(e.getStackTrace()));
        throw new RuntimeException(e.getLocalizedMessage(), e);
    }
}
 
Example 6
Source File: JettyClientFactory.java    From moon-api-gateway with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(jettyClientConfig.getThreadCount());
    httpClient = new HttpClient();
    try {
        httpClient.setMaxConnectionsPerDestination(jettyClientConfig.getMaxConnection());
        httpClient.setConnectTimeout(jettyClientConfig.getTimeout());
        httpClient.setExecutor(executor);
        httpClient.start();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: ZeppelinhubRestApiHandler.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private HttpClient getAsyncClient() {
  SslContextFactory sslContextFactory = new SslContextFactory();
  HttpClient httpClient = new HttpClient(sslContextFactory);
  // Configure HttpClient
  httpClient.setFollowRedirects(false);
  httpClient.setMaxConnectionsPerDestination(100);

  // Config considerations
  //TODO(khalid): consider multi-threaded connection manager case
  return httpClient;
}