/** * 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; }
/** * 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; }
final QueuedThreadPool pool = new QueuedThreadPool(config.getNumMaxThreads()); pool.setName(JettyHttpClientModule.class.getSimpleName() + "-threadPool-" + pool.hashCode()); httpClient.setExecutor(pool);
final QueuedThreadPool threadPool = new QueuedThreadPool((Integer) threadPoolSize); threadPool.setName(name); client.setExecutor(threadPool);
/** * @param executor The executor to use * @deprecated Use {@link HttpClient#setExecutor(Executor)} * on the instance passed to {@link #WebSocketClient(HttpClient)} */ @Deprecated public void setExecutor(Executor executor) { this.httpClient.setExecutor(executor); }
@Override public HttpClient run() { if (logger.isDebugEnabled()) { if (endpoint == null) { logger.debug("creating http client for consumer {}", consumerName); } else { logger.debug("creating http client for consumer {}, endpoint {}", consumerName, endpoint); } } HttpClient httpClient = new HttpClient(createSslContextFactory(endpoint)); httpClient.setMaxConnectionsPerDestination(2); if (threadPool != null) { httpClient.setExecutor(threadPool); } else { final QueuedThreadPool queuedThreadPool = createThreadPool(consumerName, minThreadsCustom, maxThreadsCustom, keepAliveTimeoutCustom); httpClient.setExecutor(queuedThreadPool); } if (startClient) { try { httpClient.start(); } catch (Exception e) { logger.error("Could not start Jetty http client", e); throw new HttpClientInitializationException("Could not start Jetty http client", e); } } return httpClient; } });
@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 sslContextFactory = new SslContextFactory(); 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); } }
/** * 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; }
/** * 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; }
client.setExecutor(executor);
client.setExecutor(executor);
final QueuedThreadPool pool = new QueuedThreadPool(config.getNumMaxThreads()); pool.setName(JettyHttpClientModule.class.getSimpleName() + "-threadPool-" + pool.hashCode()); httpClient.setExecutor(pool);
final QueuedThreadPool threadPool = new QueuedThreadPool((Integer) threadPoolSize); threadPool.setName(name); client.setExecutor(threadPool);
final QueuedThreadPool pool = new QueuedThreadPool(config.getNumMaxThreads()); pool.setName(JettyHttpClientModule.class.getSimpleName() + "-threadPool-" + pool.hashCode()); httpClient.setExecutor(pool);
executor = threadPool; client.setExecutor(executor);
public HttpClient createClientForHttp1(String name) { ExecutorService executor = executorFactory.getExecutorService(name, configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_SIZE), configFactory.getBooleanProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_MONITORING)); HttpClient client = new HttpClient(createSslContextFactory()); client.setMaxConnectionsPerDestination(configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_MAX_CONNECTIONS_PER_DESTINATION)); client.setMaxRequestsQueuedPerDestination(configFactory.getIntProperty(CONSUMER_INFLIGHT_SIZE)); client.setExecutor(executor); client.setCookieStore(new HttpCookieStore.Empty()); return client; }
public HttpClient createClientForHttp1(String name) { ExecutorService executor = executorFactory.getExecutorService(name, configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_SIZE), configFactory.getBooleanProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_MONITORING)); HttpClient client = new HttpClient(createSslContextFactory()); client.setMaxConnectionsPerDestination(configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_MAX_CONNECTIONS_PER_DESTINATION)); client.setMaxRequestsQueuedPerDestination(configFactory.getIntProperty(CONSUMER_INFLIGHT_SIZE)); client.setExecutor(executor); client.setCookieStore(new HttpCookieStore.Empty()); return client; }
QueuedThreadPool executor = createExecutor(name, config.getMinThreads(), config.getMaxThreads()); stats = stats(executor); httpClient.setExecutor(executor);
@Override protected void doStart() throws Exception { if (executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); setExecutor(threadPool); } if (byteBufferPool == null) setByteBufferPool(new MappedByteBufferPool(2048, executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool)executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2)); if (scheduler == null) setScheduler(new ScheduledExecutorScheduler(name + "-scheduler", false)); if (resolver == null) setSocketAddressResolver(new SocketAddressResolver.Async(executor, scheduler, getAddressResolutionTimeout())); handlers.put(new ContinueProtocolHandler()); handlers.put(new RedirectProtocolHandler(this)); handlers.put(new WWWAuthenticationProtocolHandler(this)); handlers.put(new ProxyAuthenticationProtocolHandler(this)); decoderFactories.add(new GZIPContentDecoder.Factory(byteBufferPool)); cookieManager = newCookieManager(); cookieStore = cookieManager.getCookieStore(); transport.setHttpClient(this); super.doStart(); }
HttpClient client = new HttpClient(); QueuedThreadPool executor = new QueuedThreadPool(); client.setExecutor(executor); client.start();