2021-06-27 20:44:35 +00:00
|
|
|
package j0.l.c;
|
|
|
|
|
|
|
|
import j0.l.c.j;
|
|
|
|
import j0.l.e.i;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
import rx.Scheduler;
|
|
|
|
import rx.Subscription;
|
|
|
|
import rx.functions.Action0;
|
|
|
|
import rx.subscriptions.CompositeSubscription;
|
|
|
|
/* compiled from: CachedThreadScheduler */
|
|
|
|
public final class a extends Scheduler implements k {
|
|
|
|
public static final long a = ((long) Integer.getInteger("rx.io-scheduler.keepalive", 60).intValue());
|
|
|
|
public static final TimeUnit b = TimeUnit.SECONDS;
|
|
|
|
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
2021-07-04 15:26:29 +00:00
|
|
|
public static final c f2842c;
|
2021-06-27 20:44:35 +00:00
|
|
|
public static final C0324a d;
|
|
|
|
public final ThreadFactory e;
|
|
|
|
public final AtomicReference<C0324a> f;
|
|
|
|
|
|
|
|
/* compiled from: CachedThreadScheduler */
|
|
|
|
/* renamed from: j0.l.c.a$a reason: collision with other inner class name */
|
|
|
|
public static final class C0324a {
|
|
|
|
public final ThreadFactory a;
|
|
|
|
public final long b;
|
|
|
|
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
2021-07-04 15:26:29 +00:00
|
|
|
public final ConcurrentLinkedQueue<c> f2843c;
|
2021-06-27 20:44:35 +00:00
|
|
|
public final CompositeSubscription d;
|
|
|
|
public final ScheduledExecutorService e;
|
|
|
|
public final Future<?> f;
|
|
|
|
|
|
|
|
/* compiled from: CachedThreadScheduler */
|
|
|
|
/* renamed from: j0.l.c.a$a$a reason: collision with other inner class name */
|
|
|
|
public class ThreadFactoryC0325a implements ThreadFactory {
|
|
|
|
public final /* synthetic */ ThreadFactory i;
|
|
|
|
|
|
|
|
public ThreadFactoryC0325a(C0324a aVar, ThreadFactory threadFactory) {
|
|
|
|
this.i = threadFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.util.concurrent.ThreadFactory
|
|
|
|
public Thread newThread(Runnable runnable) {
|
|
|
|
Thread newThread = this.i.newThread(runnable);
|
|
|
|
newThread.setName(newThread.getName() + " (Evictor)");
|
|
|
|
return newThread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compiled from: CachedThreadScheduler */
|
|
|
|
/* renamed from: j0.l.c.a$a$b */
|
|
|
|
public class b implements Runnable {
|
|
|
|
public b() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.lang.Runnable
|
|
|
|
public void run() {
|
|
|
|
C0324a aVar = C0324a.this;
|
2021-07-04 15:26:29 +00:00
|
|
|
if (!aVar.f2843c.isEmpty()) {
|
2021-06-27 20:44:35 +00:00
|
|
|
long nanoTime = System.nanoTime();
|
2021-07-04 15:26:29 +00:00
|
|
|
Iterator<c> it = aVar.f2843c.iterator();
|
2021-06-27 20:44:35 +00:00
|
|
|
while (it.hasNext()) {
|
|
|
|
c next = it.next();
|
|
|
|
if (next.q > nanoTime) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-04 15:26:29 +00:00
|
|
|
if (aVar.f2843c.remove(next)) {
|
2021-06-27 20:44:35 +00:00
|
|
|
aVar.d.c(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public C0324a(ThreadFactory threadFactory, long j, TimeUnit timeUnit) {
|
|
|
|
ScheduledFuture<?> scheduledFuture;
|
|
|
|
this.a = threadFactory;
|
|
|
|
long nanos = timeUnit != null ? timeUnit.toNanos(j) : 0;
|
|
|
|
this.b = nanos;
|
2021-07-04 15:26:29 +00:00
|
|
|
this.f2843c = new ConcurrentLinkedQueue<>();
|
2021-06-27 20:44:35 +00:00
|
|
|
this.d = new CompositeSubscription();
|
|
|
|
ScheduledExecutorService scheduledExecutorService = null;
|
|
|
|
if (timeUnit != null) {
|
|
|
|
scheduledExecutorService = Executors.newScheduledThreadPool(1, new ThreadFactoryC0325a(this, threadFactory));
|
|
|
|
g.g(scheduledExecutorService);
|
|
|
|
scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(new b(), nanos, nanos, TimeUnit.NANOSECONDS);
|
|
|
|
} else {
|
|
|
|
scheduledFuture = null;
|
|
|
|
}
|
|
|
|
this.e = scheduledExecutorService;
|
|
|
|
this.f = scheduledFuture;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a() {
|
|
|
|
try {
|
|
|
|
Future<?> future = this.f;
|
|
|
|
if (future != null) {
|
|
|
|
future.cancel(true);
|
|
|
|
}
|
|
|
|
ScheduledExecutorService scheduledExecutorService = this.e;
|
|
|
|
if (scheduledExecutorService != null) {
|
|
|
|
scheduledExecutorService.shutdownNow();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
this.d.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compiled from: CachedThreadScheduler */
|
|
|
|
public static final class b extends Scheduler.Worker implements Action0 {
|
|
|
|
public final CompositeSubscription i = new CompositeSubscription();
|
|
|
|
public final C0324a j;
|
|
|
|
public final c k;
|
|
|
|
public final AtomicBoolean l;
|
|
|
|
|
|
|
|
/* compiled from: CachedThreadScheduler */
|
|
|
|
/* renamed from: j0.l.c.a$b$a reason: collision with other inner class name */
|
|
|
|
public class C0326a implements Action0 {
|
|
|
|
public final /* synthetic */ Action0 i;
|
|
|
|
|
|
|
|
public C0326a(Action0 action0) {
|
|
|
|
this.i = action0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // rx.functions.Action0
|
|
|
|
public void call() {
|
|
|
|
if (!b.this.i.j) {
|
|
|
|
this.i.call();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public b(C0324a aVar) {
|
|
|
|
c cVar;
|
|
|
|
c cVar2;
|
|
|
|
this.j = aVar;
|
|
|
|
this.l = new AtomicBoolean();
|
|
|
|
if (aVar.d.j) {
|
2021-07-04 15:26:29 +00:00
|
|
|
cVar = a.f2842c;
|
2021-06-27 20:44:35 +00:00
|
|
|
} else {
|
|
|
|
while (true) {
|
2021-07-04 15:26:29 +00:00
|
|
|
if (aVar.f2843c.isEmpty()) {
|
2021-06-27 20:44:35 +00:00
|
|
|
cVar2 = new c(aVar.a);
|
|
|
|
aVar.d.a(cVar2);
|
|
|
|
break;
|
|
|
|
}
|
2021-07-04 15:26:29 +00:00
|
|
|
cVar2 = aVar.f2843c.poll();
|
2021-06-27 20:44:35 +00:00
|
|
|
if (cVar2 != null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cVar = cVar2;
|
|
|
|
}
|
|
|
|
this.k = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
|
|
public Subscription a(Action0 action0) {
|
|
|
|
return b(action0, 0, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
|
|
public Subscription b(Action0 action0, long j, TimeUnit timeUnit) {
|
|
|
|
if (this.i.j) {
|
|
|
|
return j0.r.c.a;
|
|
|
|
}
|
|
|
|
j f = this.k.f(new C0326a(action0), j, timeUnit);
|
|
|
|
this.i.a(f);
|
|
|
|
f.cancel.a(new j.c(f, this.i));
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // rx.functions.Action0
|
|
|
|
public void call() {
|
|
|
|
C0324a aVar = this.j;
|
|
|
|
c cVar = this.k;
|
|
|
|
Objects.requireNonNull(aVar);
|
|
|
|
cVar.q = System.nanoTime() + aVar.b;
|
2021-07-04 15:26:29 +00:00
|
|
|
aVar.f2843c.offer(cVar);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // rx.Subscription
|
|
|
|
public boolean isUnsubscribed() {
|
|
|
|
return this.i.j;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // rx.Subscription
|
|
|
|
public void unsubscribe() {
|
|
|
|
if (this.l.compareAndSet(false, true)) {
|
|
|
|
this.k.a(this);
|
|
|
|
}
|
|
|
|
this.i.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compiled from: CachedThreadScheduler */
|
|
|
|
public static final class c extends g {
|
|
|
|
public long q = 0;
|
|
|
|
|
|
|
|
public c(ThreadFactory threadFactory) {
|
|
|
|
super(threadFactory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
|
|
|
c cVar = new c(i.i);
|
2021-07-04 15:26:29 +00:00
|
|
|
f2842c = cVar;
|
2021-06-27 20:44:35 +00:00
|
|
|
cVar.unsubscribe();
|
|
|
|
C0324a aVar = new C0324a(null, 0, null);
|
|
|
|
d = aVar;
|
|
|
|
aVar.a();
|
|
|
|
}
|
|
|
|
|
|
|
|
public a(ThreadFactory threadFactory) {
|
|
|
|
this.e = threadFactory;
|
|
|
|
C0324a aVar = d;
|
|
|
|
AtomicReference<C0324a> atomicReference = new AtomicReference<>(aVar);
|
|
|
|
this.f = atomicReference;
|
|
|
|
C0324a aVar2 = new C0324a(threadFactory, a, b);
|
|
|
|
if (!atomicReference.compareAndSet(aVar, aVar2)) {
|
|
|
|
aVar2.a();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // rx.Scheduler
|
|
|
|
public Scheduler.Worker a() {
|
|
|
|
return new b(this.f.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // j0.l.c.k
|
|
|
|
public void shutdown() {
|
|
|
|
C0324a aVar;
|
|
|
|
C0324a aVar2;
|
|
|
|
do {
|
|
|
|
aVar = this.f.get();
|
|
|
|
aVar2 = d;
|
|
|
|
if (aVar == aVar2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (!this.f.compareAndSet(aVar, aVar2));
|
|
|
|
aVar.a();
|
|
|
|
}
|
|
|
|
}
|