package io.netty.util.concurrent;

import io.netty.util.concurrent.Future;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

/* JADX INFO: loaded from: classes.dex */
public class PromiseNotifier<V, F extends Future<V>> implements GenericFutureListener<F> {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance((Class<?>) PromiseNotifier.class);
    private final Promise<? super V>[] promises;

    @SafeVarargs
    public PromiseNotifier(Promise<? super V>... promiseArr) {
        ObjectUtil.checkNotNull(promiseArr, "promises");
        for (Promise<? super V> promise : promiseArr) {
            if (promise == null) {
                throw new IllegalArgumentException("promises contains null Promise");
            }
        }
        this.promises = (Promise[]) promiseArr.clone();
    }

    @Override // io.netty.util.concurrent.GenericFutureListener
    public void operationComplete(F f2) throws Exception {
        int i = 0;
        if (f2.isSuccess()) {
            Object obj = f2.get();
            Promise<? super V>[] promiseArr = this.promises;
            int length = promiseArr.length;
            while (i < length) {
                Promise<? super V> promise = promiseArr[i];
                if (!promise.trySuccess(obj)) {
                    logger.warn("Failed to mark a promise as success because it is done already: {}", promise);
                }
                i++;
            }
            return;
        }
        if (f2.isCancelled()) {
            for (Promise<? super V> promise2 : this.promises) {
                if (!promise2.cancel(false)) {
                    logger.warn("Failed to cancel a promise because it is done already: {}", promise2);
                }
            }
            return;
        }
        Throwable thCause = f2.cause();
        Promise<? super V>[] promiseArr2 = this.promises;
        int length2 = promiseArr2.length;
        while (i < length2) {
            Promise<? super V> promise3 = promiseArr2[i];
            if (!promise3.tryFailure(thCause)) {
                logger.warn("Failed to mark a promise as failure because it's done already: {}", promise3, thCause);
            }
            i++;
        }
    }
}
