package com.google.common.util.concurrent; import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.util.concurrent.Futures; import com.huawei.hms.support.api.entity.common.CommonConstant; import java.io.Closeable; import java.io.IOException; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; /* loaded from: classes2.dex */ public final class ClosingFuture { private static final Logger logger = Logger.getLogger(ClosingFuture.class.getName()); private final CloseableList closeables; private final FluentFuture future; private final AtomicReference state; /* loaded from: classes2.dex */ public interface AsyncClosingCallable { ClosingFuture call(DeferredCloser deferredCloser) throws Exception; } /* loaded from: classes2.dex */ public interface AsyncClosingFunction { ClosingFuture apply(DeferredCloser deferredCloser, T t) throws Exception; } /* loaded from: classes2.dex */ public interface ClosingCallable { V call(DeferredCloser deferredCloser) throws Exception; } /* loaded from: classes2.dex */ public interface ClosingFunction { U apply(DeferredCloser deferredCloser, T t) throws Exception; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public enum State { OPEN, SUBSUMED, WILL_CLOSE, CLOSING, CLOSED, WILL_CREATE_VALUE_AND_CLOSER } /* loaded from: classes2.dex */ public interface ValueAndCloserConsumer { void accept(ValueAndCloser valueAndCloser); } /* loaded from: classes2.dex */ public static final class DeferredCloser { private final CloseableList list; DeferredCloser(CloseableList closeableList) { this.list = closeableList; } public final C eventuallyClose(C c, Executor executor) { Preconditions.checkNotNull(executor); if (c != null) { this.list.add(c, executor); } return c; } } /* loaded from: classes2.dex */ public static final class ValueAndCloser { private final ClosingFuture closingFuture; ValueAndCloser(ClosingFuture closingFuture) { this.closingFuture = (ClosingFuture) Preconditions.checkNotNull(closingFuture); } public final V get() throws ExecutionException { return (V) Futures.getDone(((ClosingFuture) this.closingFuture).future); } public final void closeAsync() { this.closingFuture.close(); } } public static ClosingFuture submit(ClosingCallable closingCallable, Executor executor) { return new ClosingFuture<>(closingCallable, executor); } public static ClosingFuture submitAsync(AsyncClosingCallable asyncClosingCallable, Executor executor) { return new ClosingFuture<>(asyncClosingCallable, executor); } public static ClosingFuture from(ListenableFuture listenableFuture) { return new ClosingFuture<>(listenableFuture); } @Deprecated public static ClosingFuture eventuallyClosing(ListenableFuture listenableFuture, Executor executor) { Preconditions.checkNotNull(executor); ClosingFuture closingFuture = new ClosingFuture<>(Futures.nonCancellationPropagating(listenableFuture)); Futures.addCallback(listenableFuture, new FutureCallback(closingFuture, executor) { // from class: com.google.common.util.concurrent.ClosingFuture.1 final Executor val$closingExecutor; final ClosingFuture val$closingFuture; @Override // com.google.common.util.concurrent.FutureCallback public void onFailure(Throwable th) { } { this.val$closingFuture = closingFuture; this.val$closingExecutor = executor; } @Override // com.google.common.util.concurrent.FutureCallback public void onSuccess(Closeable closeable) { this.val$closingFuture.closeables.closer.eventuallyClose(closeable, this.val$closingExecutor); } }, MoreExecutors.directExecutor()); return closingFuture; } public static Combiner whenAllComplete(Iterable> iterable) { return new Combiner(false, iterable); } public static Combiner whenAllComplete(ClosingFuture closingFuture, ClosingFuture... closingFutureArr) { return whenAllComplete(Lists.asList(closingFuture, closingFutureArr)); } public static Combiner whenAllSucceed(Iterable> iterable) { return new Combiner(true, iterable); } public static Combiner2 whenAllSucceed(ClosingFuture closingFuture, ClosingFuture closingFuture2) { return new Combiner2<>(closingFuture2); } public static Combiner3 whenAllSucceed(ClosingFuture closingFuture, ClosingFuture closingFuture2, ClosingFuture closingFuture3) { return new Combiner3<>(closingFuture2, closingFuture3); } public static Combiner4 whenAllSucceed(ClosingFuture closingFuture, ClosingFuture closingFuture2, ClosingFuture closingFuture3, ClosingFuture closingFuture4) { return new Combiner4<>(closingFuture2, closingFuture3, closingFuture4); } public static Combiner5 whenAllSucceed(ClosingFuture closingFuture, ClosingFuture closingFuture2, ClosingFuture closingFuture3, ClosingFuture closingFuture4, ClosingFuture closingFuture5) { return new Combiner5<>(closingFuture2, closingFuture3, closingFuture4, closingFuture5); } public static Combiner whenAllSucceed(ClosingFuture closingFuture, ClosingFuture closingFuture2, ClosingFuture closingFuture3, ClosingFuture closingFuture4, ClosingFuture closingFuture5, ClosingFuture closingFuture6, ClosingFuture... closingFutureArr) { return whenAllSucceed(FluentIterable.of(closingFuture, closingFuture2, closingFuture3, closingFuture4, closingFuture5, closingFuture6).append(closingFutureArr)); } private ClosingFuture(ListenableFuture listenableFuture) { this.state = new AtomicReference<>(State.OPEN); this.closeables = new CloseableList(); this.future = FluentFuture.from(listenableFuture); } private ClosingFuture(ClosingCallable closingCallable, Executor executor) { this.state = new AtomicReference<>(State.OPEN); this.closeables = new CloseableList(); Preconditions.checkNotNull(closingCallable); TrustedListenableFutureTask create = TrustedListenableFutureTask.create(new Callable(this, closingCallable) { // from class: com.google.common.util.concurrent.ClosingFuture.2 final ClosingFuture this$0; final ClosingCallable val$callable; { this.this$0 = this; this.val$callable = closingCallable; } @Override // java.util.concurrent.Callable public V call() throws Exception { return (V) this.val$callable.call(this.this$0.closeables.closer); } public String toString() { return this.val$callable.toString(); } }); executor.execute(create); this.future = create; } private ClosingFuture(AsyncClosingCallable asyncClosingCallable, Executor executor) { this.state = new AtomicReference<>(State.OPEN); this.closeables = new CloseableList(); Preconditions.checkNotNull(asyncClosingCallable); TrustedListenableFutureTask create = TrustedListenableFutureTask.create(new AsyncCallable(this, asyncClosingCallable) { // from class: com.google.common.util.concurrent.ClosingFuture.3 final ClosingFuture this$0; final AsyncClosingCallable val$callable; { this.this$0 = this; this.val$callable = asyncClosingCallable; } @Override // com.google.common.util.concurrent.AsyncCallable public ListenableFuture call() throws Exception { CloseableList closeableList = new CloseableList(); try { ClosingFuture call = this.val$callable.call(closeableList.closer); call.becomeSubsumedInto(this.this$0.closeables); return ((ClosingFuture) call).future; } finally { this.this$0.closeables.add(closeableList, MoreExecutors.directExecutor()); } } public String toString() { return this.val$callable.toString(); } }); executor.execute(create); this.future = create; } public final ListenableFuture statusFuture() { return Futures.nonCancellationPropagating(this.future.transform(Functions.constant(null), MoreExecutors.directExecutor())); } public final ClosingFuture transform(ClosingFunction closingFunction, Executor executor) { Preconditions.checkNotNull(closingFunction); return derive(this.future.transformAsync(new AsyncFunction(this, closingFunction) { // from class: com.google.common.util.concurrent.ClosingFuture.4 final ClosingFuture this$0; final ClosingFunction val$function; { this.this$0 = this; this.val$function = closingFunction; } @Override // com.google.common.util.concurrent.AsyncFunction public ListenableFuture apply(V v) throws Exception { return this.this$0.closeables.applyClosingFunction(this.val$function, v); } public String toString() { return this.val$function.toString(); } }, executor)); } public final ClosingFuture transformAsync(AsyncClosingFunction asyncClosingFunction, Executor executor) { Preconditions.checkNotNull(asyncClosingFunction); return derive(this.future.transformAsync(new AsyncFunction(this, asyncClosingFunction) { // from class: com.google.common.util.concurrent.ClosingFuture.5 final ClosingFuture this$0; final AsyncClosingFunction val$function; { this.this$0 = this; this.val$function = asyncClosingFunction; } @Override // com.google.common.util.concurrent.AsyncFunction public ListenableFuture apply(V v) throws Exception { return this.this$0.closeables.applyAsyncClosingFunction(this.val$function, v); } public String toString() { return this.val$function.toString(); } }, executor)); } public static AsyncClosingFunction withoutCloser(AsyncFunction asyncFunction) { Preconditions.checkNotNull(asyncFunction); return new AsyncClosingFunction(asyncFunction) { // from class: com.google.common.util.concurrent.ClosingFuture.6 final AsyncFunction val$function; { this.val$function = asyncFunction; } @Override // com.google.common.util.concurrent.ClosingFuture.AsyncClosingFunction public ClosingFuture apply(DeferredCloser deferredCloser, V v) throws Exception { return ClosingFuture.from(this.val$function.apply(v)); } }; } /* JADX WARN: Multi-variable type inference failed */ public final ClosingFuture catching(Class cls, ClosingFunction closingFunction, Executor executor) { return catchingMoreGeneric(cls, closingFunction, executor); } /* JADX WARN: Multi-variable type inference failed */ private ClosingFuture catchingMoreGeneric(Class cls, ClosingFunction closingFunction, Executor executor) { Preconditions.checkNotNull(closingFunction); return (ClosingFuture) derive(this.future.catchingAsync(cls, new AsyncFunction(this, closingFunction) { // from class: com.google.common.util.concurrent.ClosingFuture.7 final ClosingFuture this$0; final ClosingFunction val$fallback; { this.this$0 = this; this.val$fallback = closingFunction; } /* JADX WARN: Incorrect types in method signature: (TX;)Lcom/google/common/util/concurrent/ListenableFuture; */ @Override // com.google.common.util.concurrent.AsyncFunction public ListenableFuture apply(Throwable th) throws Exception { return this.this$0.closeables.applyClosingFunction(this.val$fallback, th); } public String toString() { return this.val$fallback.toString(); } }, executor)); } /* JADX WARN: Multi-variable type inference failed */ public final ClosingFuture catchingAsync(Class cls, AsyncClosingFunction asyncClosingFunction, Executor executor) { return catchingAsyncMoreGeneric(cls, asyncClosingFunction, executor); } /* JADX WARN: Multi-variable type inference failed */ private ClosingFuture catchingAsyncMoreGeneric(Class cls, AsyncClosingFunction asyncClosingFunction, Executor executor) { Preconditions.checkNotNull(asyncClosingFunction); return (ClosingFuture) derive(this.future.catchingAsync(cls, new AsyncFunction(this, asyncClosingFunction) { // from class: com.google.common.util.concurrent.ClosingFuture.8 final ClosingFuture this$0; final AsyncClosingFunction val$fallback; { this.this$0 = this; this.val$fallback = asyncClosingFunction; } /* JADX WARN: Incorrect types in method signature: (TX;)Lcom/google/common/util/concurrent/ListenableFuture; */ @Override // com.google.common.util.concurrent.AsyncFunction public ListenableFuture apply(Throwable th) throws Exception { return this.this$0.closeables.applyAsyncClosingFunction(this.val$fallback, th); } public String toString() { return this.val$fallback.toString(); } }, executor)); } public final FluentFuture finishToFuture() { if (compareAndUpdateState(State.OPEN, State.WILL_CLOSE)) { logger.log(Level.FINER, "will close {0}", this); this.future.addListener(new Runnable(this) { // from class: com.google.common.util.concurrent.ClosingFuture.9 final ClosingFuture this$0; { this.this$0 = this; } @Override // java.lang.Runnable public void run() { this.this$0.checkAndUpdateState(State.WILL_CLOSE, State.CLOSING); this.this$0.close(); this.this$0.checkAndUpdateState(State.CLOSING, State.CLOSED); } }, MoreExecutors.directExecutor()); } else { switch (AnonymousClass12.$SwitchMap$com$google$common$util$concurrent$ClosingFuture$State[this.state.get().ordinal()]) { case 1: throw new IllegalStateException("Cannot call finishToFuture() after deriving another step"); case 2: throw new IllegalStateException("Cannot call finishToFuture() after calling finishToValueAndCloser()"); case 3: case 4: case 5: throw new IllegalStateException("Cannot call finishToFuture() twice"); case 6: throw new AssertionError(); } } return this.future; } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: com.google.common.util.concurrent.ClosingFuture$12, reason: invalid class name */ /* loaded from: classes2.dex */ public static /* synthetic */ class AnonymousClass12 { static final int[] $SwitchMap$com$google$common$util$concurrent$ClosingFuture$State; static { int[] iArr = new int[State.values().length]; $SwitchMap$com$google$common$util$concurrent$ClosingFuture$State = iArr; try { iArr[State.SUBSUMED.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { $SwitchMap$com$google$common$util$concurrent$ClosingFuture$State[State.WILL_CREATE_VALUE_AND_CLOSER.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { $SwitchMap$com$google$common$util$concurrent$ClosingFuture$State[State.WILL_CLOSE.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } try { $SwitchMap$com$google$common$util$concurrent$ClosingFuture$State[State.CLOSING.ordinal()] = 4; } catch (NoSuchFieldError unused4) { } try { $SwitchMap$com$google$common$util$concurrent$ClosingFuture$State[State.CLOSED.ordinal()] = 5; } catch (NoSuchFieldError unused5) { } try { $SwitchMap$com$google$common$util$concurrent$ClosingFuture$State[State.OPEN.ordinal()] = 6; } catch (NoSuchFieldError unused6) { } } } public final void finishToValueAndCloser(ValueAndCloserConsumer valueAndCloserConsumer, Executor executor) { Preconditions.checkNotNull(valueAndCloserConsumer); if (!compareAndUpdateState(State.OPEN, State.WILL_CREATE_VALUE_AND_CLOSER)) { int i = AnonymousClass12.$SwitchMap$com$google$common$util$concurrent$ClosingFuture$State[this.state.get().ordinal()]; if (i == 1) { throw new IllegalStateException("Cannot call finishToValueAndCloser() after deriving another step"); } if (i == 2) { throw new IllegalStateException("Cannot call finishToValueAndCloser() twice"); } if (i == 3 || i == 4 || i == 5) { throw new IllegalStateException("Cannot call finishToValueAndCloser() after calling finishToFuture()"); } throw new AssertionError(this.state); } this.future.addListener(new Runnable(this, valueAndCloserConsumer) { // from class: com.google.common.util.concurrent.ClosingFuture.10 final ClosingFuture this$0; final ValueAndCloserConsumer val$consumer; { this.this$0 = this; this.val$consumer = valueAndCloserConsumer; } @Override // java.lang.Runnable public void run() { ClosingFuture.provideValueAndCloser(this.val$consumer, this.this$0); } }, executor); } /* JADX INFO: Access modifiers changed from: private */ public static void provideValueAndCloser(ValueAndCloserConsumer valueAndCloserConsumer, ClosingFuture closingFuture) { valueAndCloserConsumer.accept(new ValueAndCloser<>(closingFuture)); } public final boolean cancel(boolean z) { logger.log(Level.FINER, "cancelling {0}", this); boolean cancel = this.future.cancel(z); if (cancel) { close(); } return cancel; } /* JADX INFO: Access modifiers changed from: private */ public void close() { logger.log(Level.FINER, "closing {0}", this); this.closeables.close(); } private ClosingFuture derive(FluentFuture fluentFuture) { ClosingFuture closingFuture = new ClosingFuture<>(fluentFuture); becomeSubsumedInto(closingFuture.closeables); return closingFuture; } /* JADX INFO: Access modifiers changed from: private */ public void becomeSubsumedInto(CloseableList closeableList) { checkAndUpdateState(State.OPEN, State.SUBSUMED); closeableList.add(this.closeables, MoreExecutors.directExecutor()); } /* loaded from: classes2.dex */ public static final class Peeker { private volatile boolean beingCalled; private final ImmutableList> futures; private Peeker(ImmutableList> immutableList) { this.futures = (ImmutableList) Preconditions.checkNotNull(immutableList); } public final D getDone(ClosingFuture closingFuture) throws ExecutionException { Preconditions.checkState(this.beingCalled); Preconditions.checkArgument(this.futures.contains(closingFuture)); return (D) Futures.getDone(((ClosingFuture) closingFuture).future); } /* JADX INFO: Access modifiers changed from: private */ public V call(Combiner.CombiningCallable combiningCallable, CloseableList closeableList) throws Exception { this.beingCalled = true; CloseableList closeableList2 = new CloseableList(); try { return combiningCallable.call(closeableList2.closer, this); } finally { closeableList.add(closeableList2, MoreExecutors.directExecutor()); this.beingCalled = false; } } /* JADX INFO: Access modifiers changed from: private */ public FluentFuture callAsync(Combiner.AsyncCombiningCallable asyncCombiningCallable, CloseableList closeableList) throws Exception { this.beingCalled = true; CloseableList closeableList2 = new CloseableList(); try { ClosingFuture call = asyncCombiningCallable.call(closeableList2.closer, this); call.becomeSubsumedInto(closeableList); return ((ClosingFuture) call).future; } finally { closeableList.add(closeableList2, MoreExecutors.directExecutor()); this.beingCalled = false; } } } /* loaded from: classes2.dex */ public static class Combiner { private static final Function, FluentFuture> INNER_FUTURE = new Function, FluentFuture>() { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner.3 @Override // com.google.common.base.Function public FluentFuture apply(ClosingFuture closingFuture) { return ((ClosingFuture) closingFuture).future; } }; private final boolean allMustSucceed; private final CloseableList closeables; protected final ImmutableList> inputs; /* loaded from: classes2.dex */ public interface AsyncCombiningCallable { ClosingFuture call(DeferredCloser deferredCloser, Peeker peeker) throws Exception; } /* loaded from: classes2.dex */ public interface CombiningCallable { V call(DeferredCloser deferredCloser, Peeker peeker) throws Exception; } private Combiner(boolean z, Iterable> iterable) { this.closeables = new CloseableList(); this.allMustSucceed = z; this.inputs = ImmutableList.copyOf(iterable); Iterator> it = iterable.iterator(); while (it.hasNext()) { it.next().becomeSubsumedInto(this.closeables); } } public ClosingFuture call(CombiningCallable combiningCallable, Executor executor) { ClosingFuture closingFuture = new ClosingFuture<>(futureCombiner().call(new Callable(this, combiningCallable) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner.1 final Combiner this$0; final CombiningCallable val$combiningCallable; { this.this$0 = this; this.val$combiningCallable = combiningCallable; } @Override // java.util.concurrent.Callable public V call() throws Exception { return (V) new Peeker(this.this$0.inputs).call(this.val$combiningCallable, this.this$0.closeables); } public String toString() { return this.val$combiningCallable.toString(); } }, executor)); ((ClosingFuture) closingFuture).closeables.add(this.closeables, MoreExecutors.directExecutor()); return closingFuture; } public ClosingFuture callAsync(AsyncCombiningCallable asyncCombiningCallable, Executor executor) { ClosingFuture closingFuture = new ClosingFuture<>(futureCombiner().callAsync(new AsyncCallable(this, asyncCombiningCallable) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner.2 final Combiner this$0; final AsyncCombiningCallable val$combiningCallable; { this.this$0 = this; this.val$combiningCallable = asyncCombiningCallable; } @Override // com.google.common.util.concurrent.AsyncCallable public ListenableFuture call() throws Exception { return new Peeker(this.this$0.inputs).callAsync(this.val$combiningCallable, this.this$0.closeables); } public String toString() { return this.val$combiningCallable.toString(); } }, executor)); ((ClosingFuture) closingFuture).closeables.add(this.closeables, MoreExecutors.directExecutor()); return closingFuture; } private Futures.FutureCombiner futureCombiner() { if (this.allMustSucceed) { return Futures.whenAllSucceed(inputFutures()); } return Futures.whenAllComplete(inputFutures()); } private ImmutableList> inputFutures() { return FluentIterable.from(this.inputs).transform(INNER_FUTURE).toList(); } } /* loaded from: classes2.dex */ public static final class Combiner2 extends Combiner { private final ClosingFuture future1; private final ClosingFuture future2; /* loaded from: classes2.dex */ public interface AsyncClosingFunction2 { ClosingFuture apply(DeferredCloser deferredCloser, V1 v1, V2 v2) throws Exception; } /* loaded from: classes2.dex */ public interface ClosingFunction2 { U apply(DeferredCloser deferredCloser, V1 v1, V2 v2) throws Exception; } private Combiner2(ClosingFuture closingFuture, ClosingFuture closingFuture2) { super(true, ImmutableList.of((ClosingFuture) closingFuture, closingFuture2)); this.future1 = closingFuture; this.future2 = closingFuture2; } public final ClosingFuture call(ClosingFunction2 closingFunction2, Executor executor) { return call(new Combiner.CombiningCallable(this, closingFunction2) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner2.1 final Combiner2 this$0; final ClosingFunction2 val$function; { this.this$0 = this; this.val$function = closingFunction2; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.CombiningCallable public U call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return (U) this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2)); } public String toString() { return this.val$function.toString(); } }, executor); } public final ClosingFuture callAsync(AsyncClosingFunction2 asyncClosingFunction2, Executor executor) { return callAsync(new Combiner.AsyncCombiningCallable(this, asyncClosingFunction2) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner2.2 final Combiner2 this$0; final AsyncClosingFunction2 val$function; { this.this$0 = this; this.val$function = asyncClosingFunction2; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.AsyncCombiningCallable public ClosingFuture call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2)); } public String toString() { return this.val$function.toString(); } }, executor); } } /* loaded from: classes2.dex */ public static final class Combiner3 extends Combiner { private final ClosingFuture future1; private final ClosingFuture future2; private final ClosingFuture future3; /* loaded from: classes2.dex */ public interface AsyncClosingFunction3 { ClosingFuture apply(DeferredCloser deferredCloser, V1 v1, V2 v2, V3 v3) throws Exception; } /* loaded from: classes2.dex */ public interface ClosingFunction3 { U apply(DeferredCloser deferredCloser, V1 v1, V2 v2, V3 v3) throws Exception; } private Combiner3(ClosingFuture closingFuture, ClosingFuture closingFuture2, ClosingFuture closingFuture3) { super(true, ImmutableList.of((ClosingFuture) closingFuture, (ClosingFuture) closingFuture2, closingFuture3)); this.future1 = closingFuture; this.future2 = closingFuture2; this.future3 = closingFuture3; } public final ClosingFuture call(ClosingFunction3 closingFunction3, Executor executor) { return call(new Combiner.CombiningCallable(this, closingFunction3) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner3.1 final Combiner3 this$0; final ClosingFunction3 val$function; { this.this$0 = this; this.val$function = closingFunction3; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.CombiningCallable public U call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return (U) this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2), peeker.getDone(this.this$0.future3)); } public String toString() { return this.val$function.toString(); } }, executor); } public final ClosingFuture callAsync(AsyncClosingFunction3 asyncClosingFunction3, Executor executor) { return callAsync(new Combiner.AsyncCombiningCallable(this, asyncClosingFunction3) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner3.2 final Combiner3 this$0; final AsyncClosingFunction3 val$function; { this.this$0 = this; this.val$function = asyncClosingFunction3; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.AsyncCombiningCallable public ClosingFuture call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2), peeker.getDone(this.this$0.future3)); } public String toString() { return this.val$function.toString(); } }, executor); } } /* loaded from: classes2.dex */ public static final class Combiner4 extends Combiner { private final ClosingFuture future1; private final ClosingFuture future2; private final ClosingFuture future3; private final ClosingFuture future4; /* loaded from: classes2.dex */ public interface AsyncClosingFunction4 { ClosingFuture apply(DeferredCloser deferredCloser, V1 v1, V2 v2, V3 v3, V4 v4) throws Exception; } /* loaded from: classes2.dex */ public interface ClosingFunction4 { U apply(DeferredCloser deferredCloser, V1 v1, V2 v2, V3 v3, V4 v4) throws Exception; } private Combiner4(ClosingFuture closingFuture, ClosingFuture closingFuture2, ClosingFuture closingFuture3, ClosingFuture closingFuture4) { super(true, ImmutableList.of((ClosingFuture) closingFuture, (ClosingFuture) closingFuture2, (ClosingFuture) closingFuture3, closingFuture4)); this.future1 = closingFuture; this.future2 = closingFuture2; this.future3 = closingFuture3; this.future4 = closingFuture4; } public final ClosingFuture call(ClosingFunction4 closingFunction4, Executor executor) { return call(new Combiner.CombiningCallable(this, closingFunction4) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner4.1 final Combiner4 this$0; final ClosingFunction4 val$function; { this.this$0 = this; this.val$function = closingFunction4; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.CombiningCallable public U call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return (U) this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2), peeker.getDone(this.this$0.future3), peeker.getDone(this.this$0.future4)); } public String toString() { return this.val$function.toString(); } }, executor); } public final ClosingFuture callAsync(AsyncClosingFunction4 asyncClosingFunction4, Executor executor) { return callAsync(new Combiner.AsyncCombiningCallable(this, asyncClosingFunction4) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner4.2 final Combiner4 this$0; final AsyncClosingFunction4 val$function; { this.this$0 = this; this.val$function = asyncClosingFunction4; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.AsyncCombiningCallable public ClosingFuture call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2), peeker.getDone(this.this$0.future3), peeker.getDone(this.this$0.future4)); } public String toString() { return this.val$function.toString(); } }, executor); } } /* loaded from: classes2.dex */ public static final class Combiner5 extends Combiner { private final ClosingFuture future1; private final ClosingFuture future2; private final ClosingFuture future3; private final ClosingFuture future4; private final ClosingFuture future5; /* loaded from: classes2.dex */ public interface AsyncClosingFunction5 { ClosingFuture apply(DeferredCloser deferredCloser, V1 v1, V2 v2, V3 v3, V4 v4, V5 v5) throws Exception; } /* loaded from: classes2.dex */ public interface ClosingFunction5 { U apply(DeferredCloser deferredCloser, V1 v1, V2 v2, V3 v3, V4 v4, V5 v5) throws Exception; } private Combiner5(ClosingFuture closingFuture, ClosingFuture closingFuture2, ClosingFuture closingFuture3, ClosingFuture closingFuture4, ClosingFuture closingFuture5) { super(true, ImmutableList.of((ClosingFuture) closingFuture, (ClosingFuture) closingFuture2, (ClosingFuture) closingFuture3, (ClosingFuture) closingFuture4, closingFuture5)); this.future1 = closingFuture; this.future2 = closingFuture2; this.future3 = closingFuture3; this.future4 = closingFuture4; this.future5 = closingFuture5; } public final ClosingFuture call(ClosingFunction5 closingFunction5, Executor executor) { return call(new Combiner.CombiningCallable(this, closingFunction5) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner5.1 final Combiner5 this$0; final ClosingFunction5 val$function; { this.this$0 = this; this.val$function = closingFunction5; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.CombiningCallable public U call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return (U) this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2), peeker.getDone(this.this$0.future3), peeker.getDone(this.this$0.future4), peeker.getDone(this.this$0.future5)); } public String toString() { return this.val$function.toString(); } }, executor); } public final ClosingFuture callAsync(AsyncClosingFunction5 asyncClosingFunction5, Executor executor) { return callAsync(new Combiner.AsyncCombiningCallable(this, asyncClosingFunction5) { // from class: com.google.common.util.concurrent.ClosingFuture.Combiner5.2 final Combiner5 this$0; final AsyncClosingFunction5 val$function; { this.this$0 = this; this.val$function = asyncClosingFunction5; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.util.concurrent.ClosingFuture.Combiner.AsyncCombiningCallable public ClosingFuture call(DeferredCloser deferredCloser, Peeker peeker) throws Exception { return this.val$function.apply(deferredCloser, peeker.getDone(this.this$0.future1), peeker.getDone(this.this$0.future2), peeker.getDone(this.this$0.future3), peeker.getDone(this.this$0.future4), peeker.getDone(this.this$0.future5)); } public String toString() { return this.val$function.toString(); } }, executor); } } public final String toString() { return MoreObjects.toStringHelper(this).add(CommonConstant.ReqAccessTokenParam.STATE_LABEL, this.state.get()).addValue(this.future).toString(); } protected final void finalize() { if (this.state.get().equals(State.OPEN)) { logger.log(Level.SEVERE, "Uh oh! An open ClosingFuture has leaked and will close: {0}", this); finishToFuture(); } } /* JADX INFO: Access modifiers changed from: private */ public static void closeQuietly(Closeable closeable, Executor executor) { while (closeable != null) { try { executor.execute(new Runnable(closeable) { // from class: com.google.common.util.concurrent.ClosingFuture.11 final Closeable val$closeable; { this.val$closeable = closeable; } @Override // java.lang.Runnable public void run() { try { this.val$closeable.close(); } catch (IOException | RuntimeException e) { ClosingFuture.logger.log(Level.WARNING, "thrown by close()", e); } } }); return; } catch (RejectedExecutionException e) { Logger logger2 = logger; if (logger2.isLoggable(Level.WARNING)) { logger2.log(Level.WARNING, String.format("while submitting close to %s; will close inline", executor), (Throwable) e); } executor = MoreExecutors.directExecutor(); } } } /* JADX INFO: Access modifiers changed from: private */ public void checkAndUpdateState(State state, State state2) { Preconditions.checkState(compareAndUpdateState(state, state2), "Expected state to be %s, but it was %s", state, state2); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class CloseableList extends IdentityHashMap implements Closeable { private volatile boolean closed; private final DeferredCloser closer; private volatile CountDownLatch whenClosed; private CloseableList() { this.closer = new DeferredCloser(this); } /* JADX WARN: Multi-variable type inference failed */ final ListenableFuture applyClosingFunction(ClosingFunction closingFunction, V v) throws Exception { CloseableList closeableList = new CloseableList(); try { return Futures.immediateFuture(closingFunction.apply(closeableList.closer, v)); } finally { add(closeableList, MoreExecutors.directExecutor()); } } final FluentFuture applyAsyncClosingFunction(AsyncClosingFunction asyncClosingFunction, V v) throws Exception { CloseableList closeableList = new CloseableList(); try { ClosingFuture apply = asyncClosingFunction.apply(closeableList.closer, v); apply.becomeSubsumedInto(closeableList); return ((ClosingFuture) apply).future; } finally { add(closeableList, MoreExecutors.directExecutor()); } } @Override // java.io.Closeable, java.lang.AutoCloseable public final void close() { if (this.closed) { return; } synchronized (this) { if (this.closed) { return; } this.closed = true; for (Map.Entry entry : entrySet()) { ClosingFuture.closeQuietly(entry.getKey(), entry.getValue()); } clear(); if (this.whenClosed != null) { this.whenClosed.countDown(); } } } final void add(Closeable closeable, Executor executor) { Preconditions.checkNotNull(executor); if (closeable == null) { return; } synchronized (this) { if (this.closed) { ClosingFuture.closeQuietly(closeable, executor); } else { put(closeable, executor); } } } final CountDownLatch whenClosedCountDown() { if (this.closed) { return new CountDownLatch(0); } synchronized (this) { if (this.closed) { return new CountDownLatch(0); } Preconditions.checkState(this.whenClosed == null); CountDownLatch countDownLatch = new CountDownLatch(1); this.whenClosed = countDownLatch; return countDownLatch; } } } final CountDownLatch whenClosedCountDown() { return this.closeables.whenClosedCountDown(); } private boolean compareAndUpdateState(State state, State state2) { AtomicReference atomicReference = this.state; while (!atomicReference.compareAndSet(state, state2)) { if (atomicReference.get() != state) { return false; } } return true; } }