what-the-bank/sources/com/google/common/util/concurrent/CombinedFuture.java

161 lines
6.6 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
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<V> extends AggregateFuture<Object, V> {
private CombinedFuture<V>.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<? extends ListenableFuture<?>> immutableCollection, boolean z, Executor executor, AsyncCallable<V> asyncCallable) {
super(immutableCollection, z, false);
this.task = new AsyncCallableInterruptibleTask(this, asyncCallable, executor);
init();
}
/* JADX INFO: Access modifiers changed from: package-private */
public CombinedFuture(ImmutableCollection<? extends ListenableFuture<?>> immutableCollection, boolean z, Executor executor, Callable<V> callable) {
super(immutableCollection, z, false);
this.task = new CallableInterruptibleTask(this, callable, executor);
init();
}
@Override // com.google.common.util.concurrent.AggregateFuture
final void handleAllCompleted() {
CombinedFuture<V>.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<V>.CombinedFutureInterruptibleTask<?> combinedFutureInterruptibleTask = this.task;
if (combinedFutureInterruptibleTask != null) {
combinedFutureInterruptibleTask.interruptTask();
}
}
/* loaded from: classes2.dex */
abstract class CombinedFutureInterruptibleTask<T> extends InterruptibleTask<T> {
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<V> callable;
final CombinedFuture this$0;
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
AsyncCallableInterruptibleTask(CombinedFuture combinedFuture, AsyncCallable<V> 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<V> 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<V> 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<V> callable;
final CombinedFuture this$0;
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
CallableInterruptibleTask(CombinedFuture combinedFuture, Callable<V> 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();
}
}
}