86 lines
2.7 KiB
Java
86 lines
2.7 KiB
Java
package androidx.arch.core.executor;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import java.util.concurrent.Executor;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public class ArchTaskExecutor extends TaskExecutor {
|
|
@NonNull
|
|
private static final Executor sIOThreadExecutor = new AnonymousClass2();
|
|
private static volatile ArchTaskExecutor sInstance;
|
|
@NonNull
|
|
private static final Executor sMainThreadExecutor = new AnonymousClass1();
|
|
@NonNull
|
|
private TaskExecutor mDefaultTaskExecutor;
|
|
@NonNull
|
|
private TaskExecutor mDelegate;
|
|
|
|
/* renamed from: androidx.arch.core.executor.ArchTaskExecutor$1 reason: invalid class name */
|
|
public static class AnonymousClass1 implements Executor {
|
|
@Override // java.util.concurrent.Executor
|
|
public void execute(Runnable runnable) {
|
|
ArchTaskExecutor.getInstance().postToMainThread(runnable);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.arch.core.executor.ArchTaskExecutor$2 reason: invalid class name */
|
|
public static class AnonymousClass2 implements Executor {
|
|
@Override // java.util.concurrent.Executor
|
|
public void execute(Runnable runnable) {
|
|
ArchTaskExecutor.getInstance().executeOnDiskIO(runnable);
|
|
}
|
|
}
|
|
|
|
private ArchTaskExecutor() {
|
|
DefaultTaskExecutor defaultTaskExecutor = new DefaultTaskExecutor();
|
|
this.mDefaultTaskExecutor = defaultTaskExecutor;
|
|
this.mDelegate = defaultTaskExecutor;
|
|
}
|
|
|
|
@NonNull
|
|
public static Executor getIOThreadExecutor() {
|
|
return sIOThreadExecutor;
|
|
}
|
|
|
|
@NonNull
|
|
public static ArchTaskExecutor getInstance() {
|
|
if (sInstance != null) {
|
|
return sInstance;
|
|
}
|
|
synchronized (ArchTaskExecutor.class) {
|
|
if (sInstance == null) {
|
|
sInstance = new ArchTaskExecutor();
|
|
}
|
|
}
|
|
return sInstance;
|
|
}
|
|
|
|
@NonNull
|
|
public static Executor getMainThreadExecutor() {
|
|
return sMainThreadExecutor;
|
|
}
|
|
|
|
@Override // androidx.arch.core.executor.TaskExecutor
|
|
public void executeOnDiskIO(Runnable runnable) {
|
|
this.mDelegate.executeOnDiskIO(runnable);
|
|
}
|
|
|
|
@Override // androidx.arch.core.executor.TaskExecutor
|
|
public boolean isMainThread() {
|
|
return this.mDelegate.isMainThread();
|
|
}
|
|
|
|
@Override // androidx.arch.core.executor.TaskExecutor
|
|
public void postToMainThread(Runnable runnable) {
|
|
this.mDelegate.postToMainThread(runnable);
|
|
}
|
|
|
|
public void setDelegate(@Nullable TaskExecutor taskExecutor) {
|
|
if (taskExecutor == null) {
|
|
taskExecutor = this.mDefaultTaskExecutor;
|
|
}
|
|
this.mDelegate = taskExecutor;
|
|
}
|
|
}
|