com.sun.jersey.api.client.Client.setExecutorService()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中com.sun.jersey.api.client.Client.setExecutorService()方法的一些代码示例,展示了Client.setExecutorService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Client.setExecutorService()方法的具体详情如下:
包路径:com.sun.jersey.api.client.Client
类名称:Client
方法名:setExecutorService

Client.setExecutorService介绍

[英]Set the ExecutorService for sending asynchronous HTTP requests when no underlying asynchronous HTTP implementation is utilized.
[中]设置ExecutorService,以便在未使用基础异步HTTP实现时发送异步HTTP请求。

代码示例

代码示例来源:origin: io.snamp.instrumentation/http-reporter

  1. public HttpReporter(final URI snampLocation, final Map<String, ?> properties) {
  2. final DefaultClientConfig clientConfig = new SnampClientConfig(properties);
  3. clientConfig.getSingletons().add(new JacksonJsonProvider());
  4. httpClient = Client.create(clientConfig);
  5. if (clientConfig.getPropertyAsFeature(GZIP_COMPRESSION_FEATURE))
  6. httpClient.addFilter(new GZIPContentEncodingFilter());
  7. final ExecutorService customExecutorService = (ExecutorService) clientConfig.getProperty(EXECUTOR_SERVICE_PROPERTY);
  8. if(customExecutorService != null)
  9. httpClient.setExecutorService(customExecutorService);
  10. batchResource = httpClient.resource(UriBuilder.fromUri(snampLocation).path(BATCH_PATH).build());
  11. nonBatchResource = httpClient.resource(UriBuilder.fromUri(snampLocation).path(NON_BATCH_PATH).build());
  12. final MeasurementBuffer buffer = (MeasurementBuffer) clientConfig.getProperty(BUFFER_PROPERTY);
  13. this.buffer = buffer == null ? new SoftMeasurementBuffer() : buffer;
  14. resending = new AtomicBoolean(false);
  15. asynchronous = true;
  16. }

代码示例来源:origin: com.atlassian.plugins/base-hipchat-integration-plugin-api

  1. @Override
  2. protected Client create() throws Exception {
  3. ClientConfig clientConfig = new DefaultClientConfig();
  4. clientConfig.getClasses().add(JacksonJsonProvider.class);
  5. final Map<String, Object> clientProperties = clientConfig.getProperties();
  6. clientProperties.put(ClientConfig.PROPERTY_THREADPOOL_SIZE, threadPoolSize);
  7. clientProperties.put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, connectionTimeout);
  8. clientProperties.put(ClientConfig.PROPERTY_READ_TIMEOUT, readTimeout);
  9. if (disregardSslVerification) {
  10. try {
  11. clientProperties
  12. .put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
  13. new HTTPSProperties(new HostnameVerifier() {
  14. @Override
  15. public boolean verify(String hostname, SSLSession sslSession) {
  16. return true;
  17. }
  18. }, getIgnoreCertSSLContext()));
  19. } catch (NoSuchAlgorithmException e) {
  20. Throwables.propagate(e);
  21. } catch (KeyManagementException e) {
  22. Throwables.propagate(e);
  23. }
  24. }
  25. final Client client = new Client(new URLConnectionClientHandler(new ProxyingHttpURLConnectionFactory()), clientConfig);
  26. client.setExecutorService(createBoundedExecutorService());
  27. client.addFilter(rateLimitMonitoringFilter);
  28. return client;
  29. }
  30. };

代码示例来源:origin: com.yammer.dropwizard/dropwizard-client

  1. private Client build(ExecutorService threadPool,
  2. ObjectMapper objectMapper) {
  3. final Client client = new ApacheHttpClient4(buildHandler(), buildConfig(objectMapper));
  4. client.setExecutorService(threadPool);
  5. if (configuration.isGzipEnabled()) {
  6. client.addFilter(new GZIPContentEncodingFilter(configuration.isGzipEnabledForRequests()));
  7. }
  8. return client;
  9. }

相关文章