package com.google.common.util.concurrent; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableCollection; import com.google.common.util.concurrent.AggregateFuture; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public final class CombinedFuture extends AggregateFuture { private CombinedFuture.CombinedFutureInterruptibleTask task; @Override // com.google.common.util.concurrent.AggregateFuture final void collectOneValue(int i, Object obj) { } /* JADX INFO: Access modifiers changed from: package-private */ public CombinedFuture(ImmutableCollection> immutableCollection, boolean z, Executor executor, AsyncCallable asyncCallable) { super(immutableCollection, z, false); this.task = new AsyncCallableInterruptibleTask(this, asyncCallable, executor); init(); } /* JADX INFO: Access modifiers changed from: package-private */ public CombinedFuture(ImmutableCollection> immutableCollection, boolean z, Executor executor, Callable callable) { super(immutableCollection, z, false); this.task = new CallableInterruptibleTask(this, callable, executor); init(); } @Override // com.google.common.util.concurrent.AggregateFuture final void handleAllCompleted() { CombinedFuture.CombinedFutureInterruptibleTask combinedFutureInterruptibleTask = this.task; if (combinedFutureInterruptibleTask != null) { combinedFutureInterruptibleTask.execute(); } } @Override // com.google.common.util.concurrent.AggregateFuture final void releaseResources(AggregateFuture.ReleaseResourcesReason releaseResourcesReason) { super.releaseResources(releaseResourcesReason); if (releaseResourcesReason == AggregateFuture.ReleaseResourcesReason.OUTPUT_FUTURE_DONE) { this.task = null; } } @Override // com.google.common.util.concurrent.AbstractFuture protected final void interruptTask() { CombinedFuture.CombinedFutureInterruptibleTask combinedFutureInterruptibleTask = this.task; if (combinedFutureInterruptibleTask != null) { combinedFutureInterruptibleTask.interruptTask(); } } /* loaded from: classes2.dex */ abstract class CombinedFutureInterruptibleTask extends InterruptibleTask { private final Executor listenerExecutor; final CombinedFuture this$0; abstract void setValue(T t); CombinedFutureInterruptibleTask(CombinedFuture combinedFuture, Executor executor) { this.this$0 = combinedFuture; this.listenerExecutor = (Executor) Preconditions.checkNotNull(executor); } @Override // com.google.common.util.concurrent.InterruptibleTask final boolean isDone() { return this.this$0.isDone(); } final void execute() { try { this.listenerExecutor.execute(this); } catch (RejectedExecutionException e) { this.this$0.setException(e); } } @Override // com.google.common.util.concurrent.InterruptibleTask final void afterRanInterruptibly(T t, Throwable th) { this.this$0.task = null; if (th != null) { if (th instanceof ExecutionException) { this.this$0.setException(th.getCause()); return; } else if (th instanceof CancellationException) { this.this$0.cancel(false); return; } else { this.this$0.setException(th); return; } } setValue(t); } } /* loaded from: classes2.dex */ final class AsyncCallableInterruptibleTask extends CombinedFutureInterruptibleTask { private final AsyncCallable callable; final CombinedFuture this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ AsyncCallableInterruptibleTask(CombinedFuture combinedFuture, AsyncCallable asyncCallable, Executor executor) { super(combinedFuture, executor); this.this$0 = combinedFuture; this.callable = (AsyncCallable) Preconditions.checkNotNull(asyncCallable); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.util.concurrent.InterruptibleTask public final ListenableFuture runInterruptibly() throws Exception { return (ListenableFuture) Preconditions.checkNotNull(this.callable.call(), "AsyncCallable.call returned null instead of a Future. Did you mean to return immediateFuture(null)? %s", this.callable); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.util.concurrent.CombinedFuture.CombinedFutureInterruptibleTask public final void setValue(ListenableFuture listenableFuture) { this.this$0.setFuture(listenableFuture); } @Override // com.google.common.util.concurrent.InterruptibleTask final String toPendingString() { return this.callable.toString(); } } /* loaded from: classes2.dex */ final class CallableInterruptibleTask extends CombinedFutureInterruptibleTask { private final Callable callable; final CombinedFuture this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ CallableInterruptibleTask(CombinedFuture combinedFuture, Callable callable, Executor executor) { super(combinedFuture, executor); this.this$0 = combinedFuture; this.callable = (Callable) Preconditions.checkNotNull(callable); } @Override // com.google.common.util.concurrent.InterruptibleTask final V runInterruptibly() throws Exception { return this.callable.call(); } @Override // com.google.common.util.concurrent.CombinedFuture.CombinedFutureInterruptibleTask final void setValue(V v) { this.this$0.set(v); } @Override // com.google.common.util.concurrent.InterruptibleTask final String toPendingString() { return this.callable.toString(); } } }