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

The following examples show how to use org.eclipse.jetty.client.HttpClient#setExecutor() . 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: JettyClientHttpConnector.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Constructor with an {@link JettyResourceFactory} that will manage shared resources.
 * @param resourceFactory the {@link JettyResourceFactory} to use
 * @param customizer the lambda used to customize the {@link HttpClient}
 */
public JettyClientHttpConnector(
		JettyResourceFactory resourceFactory, @Nullable Consumer<HttpClient> customizer) {

	HttpClient httpClient = new HttpClient();
	httpClient.setExecutor(resourceFactory.getExecutor());
	httpClient.setByteBufferPool(resourceFactory.getByteBufferPool());
	httpClient.setScheduler(resourceFactory.getScheduler());
	if (customizer != null) {
		customizer.accept(httpClient);
	}
	this.httpClient = httpClient;
}
 
Example 2
Source File: JettyClientHttpConnector.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Constructor with an {@link JettyResourceFactory} that will manage shared resources.
 * @param resourceFactory the {@link JettyResourceFactory} to use
 * @param customizer the lambda used to customize the {@link HttpClient}
 */
public JettyClientHttpConnector(
		JettyResourceFactory resourceFactory, @Nullable Consumer<HttpClient> customizer) {

	HttpClient httpClient = new HttpClient();
	httpClient.setExecutor(resourceFactory.getExecutor());
	httpClient.setByteBufferPool(resourceFactory.getByteBufferPool());
	httpClient.setScheduler(resourceFactory.getScheduler());
	if (customizer != null) {
		customizer.accept(httpClient);
	}
	this.httpClient = httpClient;
}
 
Example 3
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 4
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 5
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();
    }
}