Source:
public ListenableFuture<Boolean> index(final String urlFormat, final String bulkString) throws IOException { int remainingCapacityOfTheBlockingQueue = threadPoolManager.remainingCapacityOfTheQueue(); logger.debug("Remaining capacity of ES blocking queue: [" + remainingCapacityOfTheBlockingQueue + "]"); if(threadPoolManager.remainingCapacityOfTheQueue() == 0) { logger.warn("Remaining capacity of ES blocking queue: [" + remainingCapacityOfTheBlockingQueue + "]"); } return threadPoolManager.listeningExecutorService.submit(() -> { String tempUrl = String.format(urlFormat, getBaseUrl()); HttpEntity entity = new NStringEntity(bulkString, ContentType.APPLICATION_JSON); int statusCode = 0; Queue<String> callQ = new LinkedList<>(); callQ.add(tempUrl); int callCount = 0; while(!callQ.isEmpty() && callCount < MAX_CALL_COUNT) { callCount++; String url = callQ.remove(); logger.debug("Using url [{}]", url); HttpPost httpPost = new HttpPost(url); httpPost.setHeaders(getHeaders()); httpPost.setEntity(entity); CloseableHttpResponse response = null; try { logger.debug("ElasticsearchRestHelper.index Thread name in use: [" + Thread.currentThread().getName() + "]"); response = closeableHttpClient.execute(httpPost); statusCode = response.getStatusLine().getStatusCode(); String str = EntityUtils.toString(response.getEntity()); EntityUtils.consume(response.getEntity()); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { logger.error("index method failed with status code: and error: {}", statusCode, str); } } catch (Exception e) { if(response == null){ logger.error("index method failed with message: {}", e.getMessage()); url = String.format(urlFormat, getBaseUrl()); callQ.add(url); } else { logger.error("index method failed with status code: and exception message: {}", statusCode, e.getMessage()); } } finally { if(response != null) { response.close(); } } } if(statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) throw new IOException("Elasticsearch indexing failed with status code: [" + statusCode + "]"); return true; }); }

Target:
public void index(final String urlFormat, final String bulkString) throws IOException { String tempUrl = String.format(urlFormat, getNextBaseUrl()); HttpEntity entity = new NStringEntity(bulkString, ContentType.APPLICATION_JSON); int statusCode = 0; Queue<String> callQ = new LinkedList<>(); callQ.add(tempUrl); int callCount = 0; while(!callQ.isEmpty() && callCount < MAX_CALL_COUNT) { callCount++; String url = callQ.remove(); logger.debug("Using url [{}]", url); HttpPost httpPost = new HttpPost(url); httpPost.setHeaders(getHeaders()); httpPost.setEntity(entity); CloseableHttpResponse response = null; try { logger.debug("ElasticsearchRestHelper.index Thread name in use: [{}]", Thread.currentThread().getName()); response = closeableHttpClient.execute(httpPost); statusCode = response.getStatusLine().getStatusCode(); String str = EntityUtils.toString(response.getEntity()); EntityUtils.consume(response.getEntity()); if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { logger.error("index method failed with status code: and error: {}", statusCode, str); } } catch (Exception e) { if(response == null){ logger.error("index method failed with message: {}", e.getMessage()); url = String.format(urlFormat, getNextBaseUrl()); callQ.add(url); } else { logger.error("index method failed with status code: and exception message: {}", statusCode, e.getMessage()); } } finally { if(response != null) { response.close(); } } } if(statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) throw new IOException("Elasticsearch indexing failed with status code: [" + statusCode + "]"); }