package IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.FSaI4_7;

import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0;
import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.Xgtqvk_8;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/* compiled from: DownloadChain.java */
/* loaded from: classes.dex */
public class IFxWkV_5 implements Runnable {
    public static final ExecutorService KQgRr5e_0 = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue(), IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("OkDownload Cancel Block", false));

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final int f59KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public long f60KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 f61KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Mqv2r_3 f62KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public volatile IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0 f63KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 f65KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Xgtqvk_8 f66KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public volatile Thread f68KQgRr5e_0;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public long f71QxJ9d_1;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final List<IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.PGPF6hQ_2> f69KQgRr5e_0 = new ArrayList();

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public final List<IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.Mqv2r_3> f72QxJ9d_1 = new ArrayList();
    public int QxJ9d_1 = 0;
    public int PGPF6hQ_2 = 0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final AtomicBoolean f70KQgRr5e_0 = new AtomicBoolean(false);

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Runnable f67KQgRr5e_0 = new KQgRr5e_0();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IMuAHx_6.KQgRr5e_0 f64KQgRr5e_0 = IMuAHx_6.KQgRr5e_0.KQgRr5e_0.X6FRs_4.KQgRr5e_0().m26KQgRr5e_0();

    /* compiled from: DownloadChain.java */
    /* loaded from: classes.dex */
    public class KQgRr5e_0 implements Runnable {
        public KQgRr5e_0() {
        }

        @Override // java.lang.Runnable
        public void run() {
            IFxWkV_5.this.m42PGPF6hQ_2();
        }
    }

    public IFxWkV_5(int i, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 pGPF6hQ_2, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 pGPF6hQ_22, Mqv2r_3 mqv2r_3, Xgtqvk_8 xgtqvk_8) {
        this.f59KQgRr5e_0 = i;
        this.f61KQgRr5e_0 = pGPF6hQ_2;
        this.f62KQgRr5e_0 = mqv2r_3;
        this.f65KQgRr5e_0 = pGPF6hQ_22;
        this.f66KQgRr5e_0 = xgtqvk_8;
    }

    public static IFxWkV_5 KQgRr5e_0(int i, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 pGPF6hQ_2, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 pGPF6hQ_22, Mqv2r_3 mqv2r_3, Xgtqvk_8 xgtqvk_8) {
        return new IFxWkV_5(i, pGPF6hQ_2, pGPF6hQ_22, mqv2r_3, xgtqvk_8);
    }

    public void IFxWkV_5() throws IOException {
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IMuAHx_6.KQgRr5e_0 m26KQgRr5e_0 = IMuAHx_6.KQgRr5e_0.KQgRr5e_0.X6FRs_4.KQgRr5e_0().m26KQgRr5e_0();
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.X6FRs_4 x6FRs_4 = new IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.X6FRs_4();
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.KQgRr5e_0 kQgRr5e_0 = new IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.KQgRr5e_0();
        this.f69KQgRr5e_0.add(x6FRs_4);
        this.f69KQgRr5e_0.add(kQgRr5e_0);
        this.f69KQgRr5e_0.add(new IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.IFxWkV_5.QxJ9d_1());
        this.f69KQgRr5e_0.add(new IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.IFxWkV_5.KQgRr5e_0());
        this.QxJ9d_1 = 0;
        KQgRr5e_0.InterfaceC0002KQgRr5e_0 m35KQgRr5e_0 = m35KQgRr5e_0();
        if (!this.f62KQgRr5e_0.m52QxJ9d_1()) {
            m26KQgRr5e_0.KQgRr5e_0().PGPF6hQ_2(this.f61KQgRr5e_0, this.f59KQgRr5e_0, m32KQgRr5e_0());
            IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.QxJ9d_1 qxJ9d_1 = new IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.QxJ9d_1(this.f59KQgRr5e_0, m35KQgRr5e_0.m71KQgRr5e_0(), m39KQgRr5e_0(), this.f61KQgRr5e_0);
            this.f72QxJ9d_1.add(x6FRs_4);
            this.f72QxJ9d_1.add(kQgRr5e_0);
            this.f72QxJ9d_1.add(qxJ9d_1);
            this.PGPF6hQ_2 = 0;
            m26KQgRr5e_0.KQgRr5e_0().KQgRr5e_0(this.f61KQgRr5e_0, this.f59KQgRr5e_0, PGPF6hQ_2());
            return;
        }
        throw IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Xgtqvk_8.PGPF6hQ_2.KQgRr5e_0;
    }

    public void Mqv2r_3() {
        KQgRr5e_0.execute(this.f67KQgRr5e_0);
    }

    /* renamed from: PGPF6hQ_2  reason: collision with other method in class */
    public synchronized void m42PGPF6hQ_2() {
        if (this.f63KQgRr5e_0 != null) {
            this.f63KQgRr5e_0.m70KQgRr5e_0();
            IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("DownloadChain", "release connection " + this.f63KQgRr5e_0 + " task[" + this.f61KQgRr5e_0.KQgRr5e_0() + "] block[" + this.f59KQgRr5e_0 + "]");
        }
        this.f63KQgRr5e_0 = null;
    }

    public void QxJ9d_1(long j) {
        this.f60KQgRr5e_0 = j;
    }

    public void X6FRs_4() {
        this.QxJ9d_1 = 1;
        m42PGPF6hQ_2();
    }

    @Override // java.lang.Runnable
    public void run() {
        if (!m41KQgRr5e_0()) {
            this.f68KQgRr5e_0 = Thread.currentThread();
            try {
                IFxWkV_5();
            } catch (IOException unused) {
            } catch (Throwable th) {
                this.f70KQgRr5e_0.set(true);
                Mqv2r_3();
                throw th;
            }
            this.f70KQgRr5e_0.set(true);
            Mqv2r_3();
            return;
        }
        throw new IllegalAccessError("The chain has been finished!");
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public long m32KQgRr5e_0() {
        return this.f60KQgRr5e_0;
    }

    /* renamed from: QxJ9d_1  reason: collision with other method in class */
    public void m43QxJ9d_1() {
        if (this.f71QxJ9d_1 == 0) {
            return;
        }
        this.f64KQgRr5e_0.KQgRr5e_0().QxJ9d_1(this.f61KQgRr5e_0, this.f59KQgRr5e_0, this.f71QxJ9d_1);
        this.f71QxJ9d_1 = 0L;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public void m40KQgRr5e_0() {
        if (this.f70KQgRr5e_0.get() || this.f68KQgRr5e_0 == null) {
            return;
        }
        this.f68KQgRr5e_0.interrupt();
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 m33KQgRr5e_0() {
        return this.f61KQgRr5e_0;
    }

    public long QxJ9d_1() throws IOException {
        if (this.PGPF6hQ_2 == this.f72QxJ9d_1.size()) {
            this.PGPF6hQ_2--;
        }
        return PGPF6hQ_2();
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 m37KQgRr5e_0() {
        return this.f65KQgRr5e_0;
    }

    public long PGPF6hQ_2() throws IOException {
        if (!this.f62KQgRr5e_0.m52QxJ9d_1()) {
            List<IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.Mqv2r_3> list = this.f72QxJ9d_1;
            int i = this.PGPF6hQ_2;
            this.PGPF6hQ_2 = i + 1;
            return list.get(i).KQgRr5e_0(this);
        }
        throw IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Xgtqvk_8.PGPF6hQ_2.KQgRr5e_0;
    }

    public int KQgRr5e_0() {
        return this.f59KQgRr5e_0;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public Mqv2r_3 m34KQgRr5e_0() {
        return this.f62KQgRr5e_0;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.XnFJ5_9.Mqv2r_3 m39KQgRr5e_0() {
        return this.f62KQgRr5e_0.KQgRr5e_0();
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public synchronized IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0 m36KQgRr5e_0() throws IOException {
        if (!this.f62KQgRr5e_0.m52QxJ9d_1()) {
            if (this.f63KQgRr5e_0 == null) {
                String m49KQgRr5e_0 = this.f62KQgRr5e_0.m49KQgRr5e_0();
                if (m49KQgRr5e_0 == null) {
                    m49KQgRr5e_0 = this.f65KQgRr5e_0.PGPF6hQ_2();
                }
                IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("DownloadChain", "create connection on url: " + m49KQgRr5e_0);
                this.f63KQgRr5e_0 = IMuAHx_6.KQgRr5e_0.KQgRr5e_0.X6FRs_4.KQgRr5e_0().m25KQgRr5e_0().KQgRr5e_0(m49KQgRr5e_0);
            }
        } else {
            throw IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Xgtqvk_8.PGPF6hQ_2.KQgRr5e_0;
        }
        return this.f63KQgRr5e_0;
    }

    public void KQgRr5e_0(long j) {
        this.f71QxJ9d_1 += j;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public KQgRr5e_0.InterfaceC0002KQgRr5e_0 m35KQgRr5e_0() throws IOException {
        if (!this.f62KQgRr5e_0.m52QxJ9d_1()) {
            List<IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Nm6q_10.PGPF6hQ_2> list = this.f69KQgRr5e_0;
            int i = this.QxJ9d_1;
            this.QxJ9d_1 = i + 1;
            return list.get(i).KQgRr5e_0(this);
        }
        throw IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Xgtqvk_8.PGPF6hQ_2.KQgRr5e_0;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public boolean m41KQgRr5e_0() {
        return this.f70KQgRr5e_0.get();
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public Xgtqvk_8 m38KQgRr5e_0() {
        return this.f66KQgRr5e_0;
    }
}
