161 lines
5.7 KiB
Java
161 lines
5.7 KiB
Java
package j0.l.c;
|
|
|
|
import j0.l.e.i;
|
|
import j0.o.l;
|
|
import j0.r.c;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Iterator;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
import java.util.concurrent.ThreadFactory;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import rx.Scheduler;
|
|
import rx.Subscription;
|
|
import rx.functions.Action0;
|
|
/* compiled from: NewThreadWorker */
|
|
public class g extends Scheduler.Worker implements Subscription {
|
|
public static final boolean i;
|
|
public static final int j = Integer.getInteger("rx.scheduler.jdk6.purge-frequency-millis", 1000).intValue();
|
|
public static final ConcurrentHashMap<ScheduledThreadPoolExecutor, ScheduledThreadPoolExecutor> k = new ConcurrentHashMap<>();
|
|
public static final AtomicReference<ScheduledExecutorService> l = new AtomicReference<>();
|
|
public static volatile Object m;
|
|
public static final Object n = new Object();
|
|
public final ScheduledExecutorService o;
|
|
public volatile boolean p;
|
|
|
|
/* compiled from: NewThreadWorker */
|
|
public static class a implements Runnable {
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
Iterator<ScheduledThreadPoolExecutor> it = g.k.keySet().iterator();
|
|
while (it.hasNext()) {
|
|
ScheduledThreadPoolExecutor next = it.next();
|
|
if (!next.isShutdown()) {
|
|
next.purge();
|
|
} else {
|
|
it.remove();
|
|
}
|
|
}
|
|
} catch (Throwable th) {
|
|
c.q.a.k.a.a0(th);
|
|
l.b(th);
|
|
}
|
|
}
|
|
}
|
|
|
|
static {
|
|
boolean z2 = Boolean.getBoolean("rx.scheduler.jdk6.purge-force");
|
|
int i2 = j0.l.e.g.a;
|
|
i = !z2 && (i2 == 0 || i2 >= 21);
|
|
}
|
|
|
|
public g(ThreadFactory threadFactory) {
|
|
ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, threadFactory);
|
|
if (!g(newScheduledThreadPool) && (newScheduledThreadPool instanceof ScheduledThreadPoolExecutor)) {
|
|
e((ScheduledThreadPoolExecutor) newScheduledThreadPool);
|
|
}
|
|
this.o = newScheduledThreadPool;
|
|
}
|
|
|
|
public static Method d(ScheduledExecutorService scheduledExecutorService) {
|
|
Method[] methods = scheduledExecutorService.getClass().getMethods();
|
|
for (Method method : methods) {
|
|
if (method.getName().equals("setRemoveOnCancelPolicy")) {
|
|
Class<?>[] parameterTypes = method.getParameterTypes();
|
|
if (parameterTypes.length == 1 && parameterTypes[0] == Boolean.TYPE) {
|
|
return method;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static void e(ScheduledThreadPoolExecutor scheduledThreadPoolExecutor) {
|
|
while (true) {
|
|
AtomicReference<ScheduledExecutorService> atomicReference = l;
|
|
if (atomicReference.get() != null) {
|
|
break;
|
|
}
|
|
ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, new i("RxSchedulerPurge-"));
|
|
if (atomicReference.compareAndSet(null, newScheduledThreadPool)) {
|
|
a aVar = new a();
|
|
int i2 = j;
|
|
newScheduledThreadPool.scheduleAtFixedRate(aVar, (long) i2, (long) i2, TimeUnit.MILLISECONDS);
|
|
break;
|
|
}
|
|
newScheduledThreadPool.shutdownNow();
|
|
}
|
|
k.putIfAbsent(scheduledThreadPoolExecutor, scheduledThreadPoolExecutor);
|
|
}
|
|
|
|
public static boolean g(ScheduledExecutorService scheduledExecutorService) {
|
|
Method method;
|
|
if (i) {
|
|
if (scheduledExecutorService instanceof ScheduledThreadPoolExecutor) {
|
|
Object obj = m;
|
|
Object obj2 = n;
|
|
if (obj == obj2) {
|
|
return false;
|
|
}
|
|
if (obj == null) {
|
|
method = d(scheduledExecutorService);
|
|
if (method != null) {
|
|
obj2 = method;
|
|
}
|
|
m = obj2;
|
|
} else {
|
|
method = (Method) obj;
|
|
}
|
|
} else {
|
|
method = d(scheduledExecutorService);
|
|
}
|
|
if (method != null) {
|
|
try {
|
|
method.invoke(scheduledExecutorService, Boolean.TRUE);
|
|
return true;
|
|
} catch (InvocationTargetException e) {
|
|
l.b(e);
|
|
} catch (IllegalAccessException e2) {
|
|
l.b(e2);
|
|
} catch (IllegalArgumentException e3) {
|
|
l.b(e3);
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
public Subscription a(Action0 action0) {
|
|
return this.p ? c.a : f(action0, 0, null);
|
|
}
|
|
|
|
@Override // rx.Scheduler.Worker
|
|
public Subscription b(Action0 action0, long j2, TimeUnit timeUnit) {
|
|
return this.p ? c.a : f(action0, j2, timeUnit);
|
|
}
|
|
|
|
public j f(Action0 action0, long j2, TimeUnit timeUnit) {
|
|
j jVar = new j(l.d(action0));
|
|
jVar.a(j2 <= 0 ? this.o.submit(jVar) : this.o.schedule(jVar, j2, timeUnit));
|
|
return jVar;
|
|
}
|
|
|
|
@Override // rx.Subscription
|
|
public boolean isUnsubscribed() {
|
|
return this.p;
|
|
}
|
|
|
|
@Override // rx.Subscription
|
|
public void unsubscribe() {
|
|
this.p = true;
|
|
this.o.shutdownNow();
|
|
k.remove(this.o);
|
|
}
|
|
}
|