170 lines
5.4 KiB
Java
170 lines
5.4 KiB
Java
package j0.l.c;
|
|
|
|
import j0.o.l;
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.RejectedExecutionException;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import rx.Scheduler;
|
|
import rx.Subscription;
|
|
import rx.functions.Action0;
|
|
import rx.subscriptions.CompositeSubscription;
|
|
/* compiled from: ExecutorScheduler */
|
|
public final class c extends Scheduler {
|
|
public final Executor a;
|
|
|
|
/* compiled from: ExecutorScheduler */
|
|
public static final class a extends Scheduler.Worker implements Runnable {
|
|
public final Executor i;
|
|
public final CompositeSubscription j = new CompositeSubscription();
|
|
public final ConcurrentLinkedQueue<j> k = new ConcurrentLinkedQueue<>();
|
|
public final AtomicInteger l = new AtomicInteger();
|
|
public final ScheduledExecutorService m;
|
|
|
|
/* compiled from: ExecutorScheduler */
|
|
/* renamed from: j0.l.c.c$a$a reason: collision with other inner class name */
|
|
public class C0331a implements Action0 {
|
|
public final /* synthetic */ j0.r.b i;
|
|
|
|
public C0331a(j0.r.b bVar) {
|
|
this.i = bVar;
|
|
}
|
|
|
|
@Override // rx.functions.Action0
|
|
public void call() {
|
|
a.this.j.c(this.i);
|
|
}
|
|
}
|
|
|
|
/* compiled from: ExecutorScheduler */
|
|
public class b implements Action0 {
|
|
public final /* synthetic */ j0.r.b i;
|
|
public final /* synthetic */ Action0 j;
|
|
public final /* synthetic */ Subscription k;
|
|
|
|
public b(j0.r.b bVar, Action0 action0, Subscription subscription) {
|
|
this.i = bVar;
|
|
this.j = action0;
|
|
this.k = subscription;
|
|
}
|
|
|
|
@Override // rx.functions.Action0
|
|
public void call() {
|
|
if (!this.i.isUnsubscribed()) {
|
|
Subscription a = a.this.a(this.j);
|
|
this.i.a(a);
|
|
if (a.getClass() == j.class) {
|
|
((j) a).cancel.a(this.k);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public a(Executor executor) {
|
|
ScheduledExecutorService scheduledExecutorService;
|
|
this.i = executor;
|
|
ScheduledExecutorService[] scheduledExecutorServiceArr = d.f2858c.e.get();
|
|
if (scheduledExecutorServiceArr == d.a) {
|
|
scheduledExecutorService = d.b;
|
|
} else {
|
|
int i = d.d + 1;
|
|
i = i >= scheduledExecutorServiceArr.length ? 0 : i;
|
|
d.d = i;
|
|
scheduledExecutorService = scheduledExecutorServiceArr[i];
|
|
}
|
|
this.m = scheduledExecutorService;
|
|
}
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
public Subscription a(Action0 action0) {
|
|
if (this.j.j) {
|
|
return j0.r.c.a;
|
|
}
|
|
j jVar = new j(l.d(action0), this.j);
|
|
this.j.a(jVar);
|
|
this.k.offer(jVar);
|
|
if (this.l.getAndIncrement() == 0) {
|
|
try {
|
|
this.i.execute(this);
|
|
} catch (RejectedExecutionException e) {
|
|
this.j.c(jVar);
|
|
this.l.decrementAndGet();
|
|
l.b(e);
|
|
throw e;
|
|
}
|
|
}
|
|
return jVar;
|
|
}
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
public Subscription b(Action0 action0, long j, TimeUnit timeUnit) {
|
|
if (j <= 0) {
|
|
return a(action0);
|
|
}
|
|
if (this.j.j) {
|
|
return j0.r.c.a;
|
|
}
|
|
Action0 d = l.d(action0);
|
|
j0.r.b bVar = new j0.r.b();
|
|
j0.r.b bVar2 = new j0.r.b();
|
|
bVar2.a(bVar);
|
|
this.j.a(bVar2);
|
|
j0.r.a aVar = new j0.r.a(new C0331a(bVar2));
|
|
j jVar = new j(new b(bVar2, d, aVar));
|
|
bVar.a(jVar);
|
|
try {
|
|
jVar.a(this.m.schedule(jVar, j, timeUnit));
|
|
return aVar;
|
|
} catch (RejectedExecutionException e) {
|
|
l.b(e);
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
@Override // rx.Subscription
|
|
public boolean isUnsubscribed() {
|
|
return this.j.j;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
while (!this.j.j) {
|
|
j poll = this.k.poll();
|
|
if (poll != null) {
|
|
if (!poll.cancel.j) {
|
|
if (!this.j.j) {
|
|
poll.run();
|
|
} else {
|
|
this.k.clear();
|
|
return;
|
|
}
|
|
}
|
|
if (this.l.decrementAndGet() == 0) {
|
|
return;
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
this.k.clear();
|
|
}
|
|
|
|
@Override // rx.Subscription
|
|
public void unsubscribe() {
|
|
this.j.unsubscribe();
|
|
this.k.clear();
|
|
}
|
|
}
|
|
|
|
public c(Executor executor) {
|
|
this.a = executor;
|
|
}
|
|
|
|
@Override // rx.Scheduler
|
|
public Scheduler.Worker a() {
|
|
return new a(this.a);
|
|
}
|
|
}
|