/** * Cancel any scheduled run, but do not prevent subsequent restarts. */ public synchronized void cancel() { FutureUtils.cancel(scheduledFuture); scheduledFuture = null; isScheduledOrRunning = false; }
@Override public T actionGet(long timeout, TimeUnit unit) { return FutureUtils.get(this, timeout, unit); }
/** * Calls {@link Future#get()} without the checked exceptions. * * @param future to dereference * @param <T> the type returned * @return the value of the future */ public static <T> T get(Future<T> future) { try { return future.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Future got interrupted", e); } catch (ExecutionException e) { throw rethrowExecutionException(e); } }
@Override protected void doStop() { FutureUtils.cancel(backgroundFuture); }
@Override public T actionGet() { return FutureUtils.get(this); }
/** * Calls {@link Future#get(long, TimeUnit)} without the checked exceptions. * * @param future to dereference * @param timeout to wait * @param unit for timeout * @param <T> the type returned * @return the value of the future */ public static <T> T get(Future<T> future, long timeout, TimeUnit unit) { try { return future.get(timeout, unit); } catch (TimeoutException e) { throw new ElasticsearchTimeoutException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Future got interrupted", e); } catch (ExecutionException e) { throw FutureUtils.rethrowExecutionException(e); } }
public void cancel() { FutureUtils.cancel(future); }
private void notifyListener(ActionListener<V> listener, ExecutorService executorService) { try { executorService.submit(() -> { try { // call get in a non-blocking fashion as we could be on a network thread // or another thread like the scheduler, which we should never block! V value = FutureUtils.get(this, 0L, TimeUnit.NANOSECONDS); listener.onResponse(value); } catch (Exception e) { listener.onFailure(e); } }); } catch (Exception e) { listener.onFailure(e); } }
/** * Calls {@link Future#get()} without the checked exceptions. * * @param future to dereference * @param <T> the type returned * @return the value of the future */ public static <T> T get(Future<T> future) { try { return future.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Future got interrupted", e); } catch (ExecutionException e) { throw rethrowExecutionException(e); } }
public void cancelScheduling() { cancelScheduling.set(true); FutureUtils.cancel(future); removeIfSameTask(this); }
try (Releasable ignored = FutureUtils.get(permit)) {
/** * Calls {@link Future#get(long, TimeUnit)} without the checked exceptions. * * @param future to dereference * @param timeout to wait * @param unit for timeout * @param <T> the type returned * @return the value of the future */ public static <T> T get(Future<T> future, long timeout, TimeUnit unit) { try { return future.get(timeout, unit); } catch (TimeoutException e) { throw new ElasticsearchTimeoutException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Future got interrupted", e); } catch (ExecutionException e) { throw FutureUtils.rethrowExecutionException(e); } }
@Override public void run() { synchronized (this) { // make the task as stared. This is needed for synchronization with the timeout handling // see #scheduleTimeout() started = true; FutureUtils.cancel(timeoutFuture); } runAndClean(runnable); }
@Override public T actionGet(long timeout, TimeUnit unit) { return FutureUtils.get(this, timeout, unit); }
throw new IllegalStateException("Future got interrupted", e); } catch (ExecutionException e) { throw rethrowExecutionException(e); throw new IllegalStateException("Future got interrupted", e); } catch (ExecutionException e) { throw FutureUtils.rethrowExecutionException(e);
@Override public void onFailure(Exception e) { try { listener.onFailure(e); } finally { FutureUtils.cancel(scheduledRequestFuture); } }
@Override public T actionGet() { return FutureUtils.get(this); }
private void finish() { logger.trace("all expected nodes acknowledged cluster_state update (version: {})", clusterStateVersion); FutureUtils.cancel(ackTimeoutCallback); ackedTaskListener.onAllNodesAcked(lastFailure); }
@Override public T actionGet() { return FutureUtils.get(this); }
/** * cancels timeout handling. this is a best effort only to avoid running it. remove the requestId from {@link #responseHandlers} * to make sure this doesn't run. */ public void cancel() { assert responseHandlers.contains(requestId) == false : "cancel must be called after the requestId [" + requestId + "] has been removed from clientHandlers"; FutureUtils.cancel(future); }