import com.google.common.util.concurrent.ExecutionList;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListenableFutureTask;
-
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.FutureTask;
-
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* to avoid blocking the thread that completed this task, as a common use case is to pass an
* executor that runs tasks in the same thread as the caller (ie MoreExecutors#sameThreadExecutor)
* to {@link #addListener}.
- * <p>
- * Note: the Executor specified on construction does not replace the Executor specified in
+ *
+ * <p>Note: the Executor specified on construction does not replace the Executor specified in
* {@link #addListener}. The latter Executor is still used however, if it is detected that the
* listener Runnable would execute in the thread that completed this task, the listener
* is executed on Executor specified on construction.
*
- * Also note that the use of this task may attach some (small) amount of state to the threads
+ * <p>Also note that the use of this task may attach some (small) amount of state to the threads
* interacting with it. That state will not be detached automatically, but you can use
* {@link #cleanStateForCurrentThread()} to clean it up.
*
* @param <V> the Future result value type
*/
public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> implements ListenableFuture<V> {
- private static final class DelegatingAsyncNotifyingListenableFutureTask<V> extends AsyncNotifyingListenableFutureTask<V> {
+
+ private static final class DelegatingAsyncNotifyingListenableFutureTask<V>
+ extends AsyncNotifyingListenableFutureTask<V> {
+
/**
* The executor used to run listener callbacks.
*/
private final Executor listenerExecutor;
- private DelegatingAsyncNotifyingListenableFutureTask(final Callable<V> callable, @Nullable final Executor listenerExecutor) {
+ private DelegatingAsyncNotifyingListenableFutureTask(final Callable<V> callable,
+ @Nullable final Executor listenerExecutor) {
super(callable);
this.listenerExecutor = Preconditions.checkNotNull(listenerExecutor);
}
*/
public static <V> AsyncNotifyingListenableFutureTask<V> create(final Callable<V> callable,
@Nullable final Executor listenerExecutor) {
- if (listenerExecutor != null) {
- return new DelegatingAsyncNotifyingListenableFutureTask<V>(callable, listenerExecutor);
- } else {
- return new AsyncNotifyingListenableFutureTask<V>(callable);
+ if (listenerExecutor == null) {
+ return new AsyncNotifyingListenableFutureTask<>(callable);
}
+ return new DelegatingAsyncNotifyingListenableFutureTask<>(callable, listenerExecutor);
}
/**
*/
public static <V> AsyncNotifyingListenableFutureTask<V> create(final Runnable runnable, @Nullable final V result,
@Nullable final Executor listenerExecutor) {
- if (listenerExecutor != null) {
- return new DelegatingAsyncNotifyingListenableFutureTask<V>(runnable, result, listenerExecutor);
- } else {
- return new AsyncNotifyingListenableFutureTask<V>(runnable, result);
+ if (listenerExecutor == null) {
+ return new AsyncNotifyingListenableFutureTask<>(runnable, result);
}
+ return new DelegatingAsyncNotifyingListenableFutureTask<>(runnable, result, listenerExecutor);
}
@Override