public void submitRequest() { client.executeRequest(file, completionHandler); } }
public synchronized void executeRequest(final File file, final AsyncCompletionHandler<Response> completionHandler) { if (isClosed.get()) { return; } if (client == null || client.isClosed()) { client = createClient(); } final Request request = createPostRequest(file); try { client.executeRequest(request, completionHandler); } catch (Exception e) { // Recycle the client on IOException and RuntimeExceptions client.close(); client = createClient(); completionHandler.onThrowable(e); } }
public HttpSender(final String collectorHost, final int collectorPort, final EventType eventType, final long httpMaxWaitTimeInMillis, final long httpMaxKeepAliveInMillis, final int httpWorkersPoolSize) { this(new ThreadSafeAsyncHttpClient(collectorHost, collectorPort, eventType, httpMaxKeepAliveInMillis), httpMaxWaitTimeInMillis, Metrics.newTimer(HttpSender.class, collectorHost.replace(":", "_"), TimeUnit.MILLISECONDS, TimeUnit.SECONDS), httpWorkersPoolSize); }
@Override public synchronized void close() { client.close(); try { if (activeRequests.get() > 0) { log.info(String.format("%d HTTP request(s) in progress, giving them some time to finish...", activeRequests.get())); } long sleptInMillins = httpMaxWaitTimeInMillis; while (activeRequests.get() > 0 && sleptInMillins >= 0) { Thread.sleep(200); sleptInMillins -= 200; } if (activeRequests.get() > 0) { log.warn("Giving up on pending HTTP requests, shutting down NOW!"); } workers.close(); } catch (InterruptedException e) { log.warn("Interrupted while waiting for active queries to finish"); Thread.currentThread().interrupt(); } } }