DefaultHttpRequestProcessor extends ReportDecider { static CloseableHttpClient getHttpClent() { if (httpClientCache != null) { return httpClientCache; } if (httpClientInitialized.compareAndSet(false, true)) { final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultMaxPerRoute(2); connManager.setMaxTotal(4); httpClientCache = HttpClientBuilder.create().setConnectionManager(connManager) .setRetryHandler(new DefaultHttpRequestRetryHandler(1, false)) .setUserAgent(CLIENT_VERSION).build(); clearIdleConnectionsTask = new Runnable() { @Override public void run() { try { connManager.closeIdleConnections(30, TimeUnit.SECONDS); connManager.closeExpiredConnections(); } catch (Throwable e) { logger.warn("fail to close idle connections.{}", e.getMessage()); } } }; return httpClientCache; } return null; } DefaultHttpRequestProcessor(AddressService addressService, MetricConfig metricConfig); @Override boolean sendGetRequest(final HttpGet httpGet, Map<String, String> metadata); @Override boolean sendGetRequest(final HttpGet httpGet, Map<String, String> metadata,
                                  final ResultConsumer resultConsumer); @Override boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata); void handleErrorResponse(HttpResponse response, HttpRequestBase request); @Override List<LookoutMeasurement> filter(List<LookoutMeasurement> measures); static final String CLIENT_IP_HEADER_NAME; static final String LOOKOUT_REPORT_FAIL_COUNT_ID; static final String WAIT_MINUTES; }
@Test public void testGetHttpClient() { CloseableHttpClient client = DefaultHttpRequestProcessor.getHttpClent(); Assert.assertSame(client, DefaultHttpRequestProcessor.getHttpClent()); }