package m4;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes3.dex */
public final class N0 implements Runnable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f20692a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ P0 f20693b;

    public /* synthetic */ N0(P0 p02, int i6) {
        this.f20692a = i6;
        this.f20693b = p02;
    }

    @Override // java.lang.Runnable
    public final void run() {
        ArrayList arrayList;
        switch (this.f20692a) {
            case 0:
                P0 p02 = this.f20693b;
                if (p02.f20721d.f20763B == null) {
                    AtomicReference atomicReference = p02.f20718a;
                    if (atomicReference.get() == S0.f20760j0) {
                        atomicReference.set(null);
                    }
                    p02.f20721d.f20767F.h(S0.g0);
                    return;
                }
                return;
            case 1:
                if (this.f20693b.f20718a.get() == S0.f20760j0) {
                    this.f20693b.f20718a.set(null);
                }
                LinkedHashSet linkedHashSet = this.f20693b.f20721d.f20763B;
                if (linkedHashSet != null) {
                    Iterator it = linkedHashSet.iterator();
                    while (it.hasNext()) {
                        ((O0) it.next()).cancel("Channel is forcefully shutdown", null);
                    }
                }
                C0.J j4 = this.f20693b.f20721d.f20767F;
                k4.r0 r0Var = S0.f0;
                j4.h(r0Var);
                synchronized (j4.f533b) {
                    arrayList = new ArrayList((HashSet) j4.f534c);
                    break;
                }
                Iterator it2 = arrayList.iterator();
                while (it2.hasNext()) {
                    ((InterfaceC2547u) it2.next()).g(r0Var);
                }
                ((S0) j4.f536e).f20766E.a(r0Var);
                return;
            default:
                this.f20693b.f20721d.C();
                return;
        }
    }
}
