package c.a.q.g;

import c.a.g;
import java.util.concurrent.Callable;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

/* JADX INFO: compiled from: NewThreadWorker.java */
/* JADX INFO: loaded from: classes.dex */
public class f extends g.c implements c.a.n.b {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final ScheduledExecutorService f1862c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    volatile boolean f1863d;

    public f(ThreadFactory threadFactory) {
        this.f1862c = l.a(threadFactory);
    }

    @Override // c.a.g.c
    public c.a.n.b b(Runnable runnable) {
        return c(runnable, 0L, null);
    }

    @Override // c.a.g.c
    public c.a.n.b c(Runnable runnable, long j, TimeUnit timeUnit) {
        return this.f1863d ? c.a.q.a.c.INSTANCE : e(runnable, j, timeUnit, null);
    }

    @Override // c.a.n.b
    public void dispose() {
        if (this.f1863d) {
            return;
        }
        this.f1863d = true;
        this.f1862c.shutdownNow();
    }

    public k e(Runnable runnable, long j, TimeUnit timeUnit, c.a.q.a.a aVar) {
        k kVar = new k(c.a.r.a.q(runnable), aVar);
        if (aVar != null && !aVar.b(kVar)) {
            return kVar;
        }
        try {
            kVar.a(j <= 0 ? this.f1862c.submit((Callable) kVar) : this.f1862c.schedule((Callable) kVar, j, timeUnit));
        } catch (RejectedExecutionException e2) {
            if (aVar != null) {
                aVar.a(kVar);
            }
            c.a.r.a.o(e2);
        }
        return kVar;
    }

    public c.a.n.b f(Runnable runnable, long j, TimeUnit timeUnit) {
        j jVar = new j(c.a.r.a.q(runnable));
        try {
            jVar.a(j <= 0 ? this.f1862c.submit(jVar) : this.f1862c.schedule(jVar, j, timeUnit));
            return jVar;
        } catch (RejectedExecutionException e2) {
            c.a.r.a.o(e2);
            return c.a.q.a.c.INSTANCE;
        }
    }

    public c.a.n.b g(Runnable runnable, long j, long j2, TimeUnit timeUnit) {
        Runnable runnableQ = c.a.r.a.q(runnable);
        if (j2 <= 0) {
            c cVar = new c(runnableQ, this.f1862c);
            try {
                cVar.b(j <= 0 ? this.f1862c.submit(cVar) : this.f1862c.schedule(cVar, j, timeUnit));
                return cVar;
            } catch (RejectedExecutionException e2) {
                c.a.r.a.o(e2);
                return c.a.q.a.c.INSTANCE;
            }
        }
        i iVar = new i(runnableQ);
        try {
            iVar.a(this.f1862c.scheduleAtFixedRate(iVar, j, j2, timeUnit));
            return iVar;
        } catch (RejectedExecutionException e3) {
            c.a.r.a.o(e3);
            return c.a.q.a.c.INSTANCE;
        }
    }

    public void h() {
        if (this.f1863d) {
            return;
        }
        this.f1863d = true;
        this.f1862c.shutdown();
    }
}
