@Override public void addListener(final Runnable listener, final Executor executor) { // Wrap the listener Runnable in a DelegatingRunnable. If the specified executor is one that // runs tasks in the same thread as the caller submitting the task // (e.g. {@link com.google.common.util.concurrent.MoreExecutors#sameThreadExecutor}) and the // listener is executed from the #done method, then the DelegatingRunnable will detect this // via the ThreadLocal and submit the listener Runnable to the listenerExecutor. // // On the other hand, if this task is already complete, the call to ExecutionList#add in // superclass will execute the listener Runnable immediately and, since the ThreadLocal won't be set, // the DelegatingRunnable will run the listener Runnable inline. super.addListener(new DelegatingRunnable(listener, listenerExecutor), executor); } }
@Override public <T> ListenableFuture<T> submit(final Callable<T> task) { final AsyncNotifyingListenableFutureTask<T> futureTask = AsyncNotifyingListenableFutureTask.create( requireNonNull(task), listenableFutureExecutor); delegate.execute(futureTask); return futureTask; }
/** * Creates a {@code AsyncListenableFutureTask} that will upon running, execute the * given {@code Runnable}, and arrange that {@code get} will return the * given result on successful completion. * * @param runnable the runnable task * @param result the result to return on successful completion. * @param listenerExecutor the executor used to run listener callbacks asynchronously. * If null, no executor is used. */ public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Runnable runnable, @Nullable final V result, @Nullable final Executor listenerExecutor) { if (listenerExecutor == null) { return new AsyncNotifyingListenableFutureTask<>(runnable, result); } return new DelegatingAsyncNotifyingListenableFutureTask<>(runnable, result, listenerExecutor); }
/** * Creates a {@code AsyncListenableFutureTask} that will upon running, execute the * given {@code Runnable}, and arrange that {@code get} will return the * given result on successful completion. * * @param runnable the runnable task * @param result the result to return on successful completion. * @param listenerExecutor the executor used to run listener callbacks asynchronously. * If null, no executor is used. */ public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Runnable runnable, @Nullable final V result, @Nullable final Executor listenerExecutor) { if (listenerExecutor == null) { return new AsyncNotifyingListenableFutureTask<>(runnable, result); } return new DelegatingAsyncNotifyingListenableFutureTask<>(runnable, result, listenerExecutor); }
@Override public <T> ListenableFuture<T> submit(final Callable<T> task) { final AsyncNotifyingListenableFutureTask<T> futureTask = AsyncNotifyingListenableFutureTask.create( requireNonNull(task), listenableFutureExecutor); delegate.execute(futureTask); return futureTask; }
/** * Creates an {@code AsyncListenableFutureTask} that will upon running, execute the given * {@code Callable}. * * @param callable the callable task * @param listenerExecutor the executor used to run listener callbacks asynchronously. * If null, no executor is used. */ public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Callable<V> callable, @Nullable final Executor listenerExecutor) { if (listenerExecutor == null) { return new AsyncNotifyingListenableFutureTask<>(callable); } return new DelegatingAsyncNotifyingListenableFutureTask<>(callable, listenerExecutor); }
@Override public void addListener(final Runnable listener, final Executor executor) { // Wrap the listener Runnable in a DelegatingRunnable. If the specified executor is one that // runs tasks in the same thread as the caller submitting the task // (e.g. {@link com.google.common.util.concurrent.MoreExecutors#sameThreadExecutor}) and the // listener is executed from the #done method, then the DelegatingRunnable will detect this // via the ThreadLocal and submit the listener Runnable to the listenerExecutor. // // On the other hand, if this task is already complete, the call to ExecutionList#add in // superclass will execute the listener Runnable immediately and, since the ThreadLocal won't be set, // the DelegatingRunnable will run the listener Runnable inline. super.addListener(new DelegatingRunnable(listener, listenerExecutor), executor); } }
/** * Creates an {@link AsyncNotifyingListenableFutureTask} instance with the listener Executor. * * @param task the Runnable to execute */ private <T> @NonNull AsyncNotifyingListenableFutureTask<T> newFutureTask(final @NonNull Runnable task, final T result) { return AsyncNotifyingListenableFutureTask.create(task, result, listenableFutureExecutor); }
/** * Creates an {@code AsyncListenableFutureTask} that will upon running, execute the given * {@code Callable}. * * @param callable the callable task * @param listenerExecutor the executor used to run listener callbacks asynchronously. * If null, no executor is used. */ public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Callable<V> callable, @Nullable final Executor listenerExecutor) { if (listenerExecutor == null) { return new AsyncNotifyingListenableFutureTask<>(callable); } return new DelegatingAsyncNotifyingListenableFutureTask<>(callable, listenerExecutor); }
/** * Creates an {@link AsyncNotifyingListenableFutureTask} instance with the listener Executor. * * @param task the Runnable to execute */ private <T> @NonNull AsyncNotifyingListenableFutureTask<T> newFutureTask(final @NonNull Runnable task, final T result) { return AsyncNotifyingListenableFutureTask.create(task, result, listenableFutureExecutor); }