private HttpAsyncClient startAsyncClient() { HttpAsyncClient client = getAsyncClient(); if (client instanceof CloseableHttpAsyncClient) { CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client; if (!closeableAsyncClient.isRunning()) { closeableAsyncClient.start(); } } return client; }
@Override public void sendAsyncRequestImpl(HttpUriRequest request, Callback<HttpResponse> callback) throws IOException { this.client.execute(request, new FutureCallback<HttpResponse>() { @Override public void completed(HttpResponse result) { callback.onSuccess(result); } @Override public void failed(Exception ex) { callback.onFailure(ex); } @Override public void cancelled() { throw new UnsupportedOperationException(); } }); }
public void close() throws Exception { httpClient.close(); }
public static <T> Future<HttpResponse<T>> requestAsync(HttpRequest request, final Class<T> responseClass, Callback<T> callback) { HttpUriRequest requestObj = prepareRequest(request, true); CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); if (!asyncHttpClient.isRunning()) { asyncHttpClient.start(); AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); asyncIdleConnectionMonitorThread.start(); } final Future<org.apache.http.HttpResponse> future = asyncHttpClient.execute(requestObj, prepareCallback(responseClass, callback)); return new Future<HttpResponse<T>>() { public boolean cancel(boolean mayInterruptIfRunning) { return future.cancel(mayInterruptIfRunning); } public boolean isCancelled() { return future.isCancelled(); } public boolean isDone() { return future.isDone(); } public HttpResponse<T> get() throws InterruptedException, ExecutionException { org.apache.http.HttpResponse httpResponse = future.get(); return new HttpResponse<T>(httpResponse, responseClass); } public HttpResponse<T> get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { org.apache.http.HttpResponse httpResponse = future.get(timeout, unit); return new HttpResponse<T>(httpResponse, responseClass); } }; }
/** * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. */ public static void shutdown() throws IOException { // Closing the Sync HTTP client CloseableHttpClient syncClient = (CloseableHttpClient) Options.getOption(Option.HTTPCLIENT); if (syncClient != null) { syncClient.close(); } SyncIdleConnectionMonitorThread syncIdleConnectionMonitorThread = (SyncIdleConnectionMonitorThread) Options.getOption(Option.SYNC_MONITOR); if (syncIdleConnectionMonitorThread != null) { syncIdleConnectionMonitorThread.interrupt(); } // Closing the Async HTTP client (if running) CloseableHttpAsyncClient asyncClient = (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT); if (asyncClient != null && asyncClient.isRunning()) { asyncClient.close(); } AsyncIdleConnectionMonitorThread asyncMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); if (asyncMonitorThread != null) { asyncMonitorThread.interrupt(); } }
@Override public void start() { delegate.start(); } }
@Override public boolean isRunning() { return delegate.isRunning(); }
@Autowired public AsyncNotifyService(ServerListService serverListService) { this.serverListService = serverListService; httpclient.start(); }
@Override public boolean isRunning() { return delegate.isRunning(); }
private void checkServerHealth() { long startCheckTime = System.currentTimeMillis(); for (String serverIp : serverList) { // Compatible with old codes,use status.taobao String url = "http://" + serverIp + servletContext.getContextPath() + Constants.HEALTH_CONTROLLER_PATH; // "/nacos/health"; HttpGet request = new HttpGet(url); httpclient.execute(request, new AyscCheckServerHealthCallBack(serverIp)); } long endCheckTime = System.currentTimeMillis(); long cost = endCheckTime - startCheckTime; defaultLog.debug("checkServerHealth cost: {}", cost); }
private HttpAsyncClient startAsyncClient() { HttpAsyncClient client = getAsyncClient(); if (client instanceof CloseableHttpAsyncClient) { CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client; if (!closeableAsyncClient.isRunning()) { closeableAsyncClient.start(); } } return client; }
@Override protected CloseableHttpAsyncClient newClient(HttpTracing httpTracing) { CloseableHttpAsyncClient result = TracingHttpAsyncClientBuilder.create(httpTracing).build(); result.start(); return result; }
@Override public void close() throws IOException { client.close(); } }
public static synchronized void stopDefaultClient() { if (defaultClient != null) { HttpClientUtils.closeQuietly(defaultClient); defaultClient = null; } if (closeableHttpAsyncClient != null) { try { if(closeableHttpAsyncClient.isRunning()) closeableHttpAsyncClient.close(); } catch (IOException e) { } closeableHttpAsyncClient = null; } }
@Override public boolean isRunning() { return ac.isRunning(); }
final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<String> reference = new AtomicReference<>(); httpClient.execute(httpGet, new FutureCallback<HttpResponse>() { @Override public void completed(final HttpResponse response) {
public <T extends JestResult> void executeAsync(final Action<T> clientRequest, final JestResultHandler<? super T> resultHandler, final RequestConfig requestConfig) { synchronized (this) { if (!asyncClient.isRunning()) { asyncClient.start(); } } HttpUriRequest request = prepareRequest(clientRequest, requestConfig); executeAsyncRequest(clientRequest, resultHandler, request); }
@Override protected CloseableHttpAsyncClient newClient() { CloseableHttpAsyncClient result = HttpAsyncClients.custom().build(); result.start(); return result; }