导航菜单

页面标题

页面副标题

SpeedCash v6.5.1482 - SynchronizationContext.java 源代码

正在查看: SpeedCash v6.5.1482 应用的 SynchronizationContext.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package io.grpc;

import com.google.common.base.Preconditions;
import java.lang.Thread;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.concurrent.ThreadSafe;

@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4984")
@ThreadSafe
public final class SynchronizationContext implements Executor {
    public final Thread.UncaughtExceptionHandler a;
    public final Queue<Runnable> b = new ConcurrentLinkedQueue();
    public final AtomicReference<Thread> c = new AtomicReference<>();

    public static final class ScheduledHandle {
        public final c a;
        public final ScheduledFuture<?> b;

        public ScheduledHandle(c cVar, ScheduledFuture scheduledFuture, a aVar) {
            this(cVar, scheduledFuture);
        }

        public void cancel() {
            this.a.b = true;
            this.b.cancel(false);
        }

        public boolean isPending() {
            c cVar = this.a;
            return (cVar.c || cVar.b) ? false : true;
        }

        public ScheduledHandle(c cVar, ScheduledFuture<?> scheduledFuture) {
            this.a = (c) Preconditions.checkNotNull(cVar, "runnable");
            this.b = (ScheduledFuture) Preconditions.checkNotNull(scheduledFuture, "future");
        }
    }

    public class a implements Runnable {
        public final c a;
        public final Runnable b;

        public a(c cVar, Runnable runnable) {
            this.a = cVar;
            this.b = runnable;
        }

        @Override
        public void run() {
            SynchronizationContext.this.execute(this.a);
        }

        public String toString() {
            return this.b.toString() + "(scheduled in SynchronizationContext)";
        }
    }

    public class b implements Runnable {
        public final c a;
        public final Runnable b;
        public final long c;

        public b(c cVar, Runnable runnable, long j) {
            this.a = cVar;
            this.b = runnable;
            this.c = j;
        }

        @Override
        public void run() {
            SynchronizationContext.this.execute(this.a);
        }

        public String toString() {
            return this.b.toString() + "(scheduled in SynchronizationContext with delay of " + this.c + ")";
        }
    }

    public static class c implements Runnable {
        public final Runnable a;
        public boolean b;
        public boolean c;

        public c(Runnable runnable) {
            this.a = (Runnable) Preconditions.checkNotNull(runnable, "task");
        }

        @Override
        public void run() {
            if (this.b) {
                return;
            }
            this.c = true;
            this.a.run();
        }
    }

    public SynchronizationContext(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
        this.a = (Thread.UncaughtExceptionHandler) Preconditions.checkNotNull(uncaughtExceptionHandler, "uncaughtExceptionHandler");
    }

    public final void drain() {
        while (yz3.a(this.c, (Object) null, Thread.currentThread())) {
            while (true) {
                try {
                    Runnable poll = this.b.poll();
                    if (poll == null) {
                        break;
                    }
                    try {
                        poll.run();
                    } catch (Throwable th) {
                        this.a.uncaughtException(Thread.currentThread(), th);
                    }
                } catch (Throwable th2) {
                    this.c.set(null);
                    throw th2;
                }
            }
            this.c.set(null);
            if (this.b.isEmpty()) {
                return;
            }
        }
    }

    @Override
    public final void execute(Runnable runnable) {
        executeLater(runnable);
        drain();
    }

    public final void executeLater(Runnable runnable) {
        this.b.add((Runnable) Preconditions.checkNotNull(runnable, "runnable is null"));
    }

    public final ScheduledHandle schedule(Runnable runnable, long j, TimeUnit timeUnit, ScheduledExecutorService scheduledExecutorService) {
        c cVar = new c(runnable);
        return new ScheduledHandle(cVar, scheduledExecutorService.schedule(new a(cVar, runnable), j, timeUnit), null);
    }

    public final ScheduledHandle scheduleWithFixedDelay(Runnable runnable, long j, long j2, TimeUnit timeUnit, ScheduledExecutorService scheduledExecutorService) {
        c cVar = new c(runnable);
        return new ScheduledHandle(cVar, scheduledExecutorService.scheduleWithFixedDelay(new b(cVar, runnable, j2), j, j2, timeUnit), null);
    }

    public void throwIfNotInThisSynchronizationContext() {
        Preconditions.checkState(Thread.currentThread() == this.c.get(), "Not called from the SynchronizationContext");
    }
}