what-the-bank/sources/com/google/common/util/concurrent/Callables.java

114 lines
4.1 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.util.concurrent;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import java.util.concurrent.Callable;
/* loaded from: classes2.dex */
public final class Callables {
private Callables() {
}
public static <T> Callable<T> returning(T t) {
return new Callable<T>(t) { // from class: com.google.common.util.concurrent.Callables.1
final Object val$value;
{
this.val$value = t;
}
@Override // java.util.concurrent.Callable
public T call() {
return (T) this.val$value;
}
};
}
public static <T> AsyncCallable<T> asAsyncCallable(Callable<T> callable, ListeningExecutorService listeningExecutorService) {
Preconditions.checkNotNull(callable);
Preconditions.checkNotNull(listeningExecutorService);
return new AsyncCallable<T>(listeningExecutorService, callable) { // from class: com.google.common.util.concurrent.Callables.2
final Callable val$callable;
final ListeningExecutorService val$listeningExecutorService;
{
this.val$listeningExecutorService = listeningExecutorService;
this.val$callable = callable;
}
@Override // com.google.common.util.concurrent.AsyncCallable
public ListenableFuture<T> call() throws Exception {
return this.val$listeningExecutorService.submit((Callable) this.val$callable);
}
};
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <T> Callable<T> threadRenaming(Callable<T> callable, Supplier<String> supplier) {
Preconditions.checkNotNull(supplier);
Preconditions.checkNotNull(callable);
return new Callable<T>(supplier, callable) { // from class: com.google.common.util.concurrent.Callables.3
final Callable val$callable;
final Supplier val$nameSupplier;
{
this.val$nameSupplier = supplier;
this.val$callable = callable;
}
@Override // java.util.concurrent.Callable
public T call() throws Exception {
Thread currentThread = Thread.currentThread();
String name = currentThread.getName();
boolean trySetName = Callables.trySetName((String) this.val$nameSupplier.get(), currentThread);
try {
return (T) this.val$callable.call();
} finally {
if (trySetName) {
Callables.trySetName(name, currentThread);
}
}
}
};
}
/* JADX INFO: Access modifiers changed from: package-private */
public static Runnable threadRenaming(Runnable runnable, Supplier<String> supplier) {
Preconditions.checkNotNull(supplier);
Preconditions.checkNotNull(runnable);
return new Runnable(supplier, runnable) { // from class: com.google.common.util.concurrent.Callables.4
final Supplier val$nameSupplier;
final Runnable val$task;
{
this.val$nameSupplier = supplier;
this.val$task = runnable;
}
@Override // java.lang.Runnable
public void run() {
Thread currentThread = Thread.currentThread();
String name = currentThread.getName();
boolean trySetName = Callables.trySetName((String) this.val$nameSupplier.get(), currentThread);
try {
this.val$task.run();
} finally {
if (trySetName) {
Callables.trySetName(name, currentThread);
}
}
}
};
}
/* JADX INFO: Access modifiers changed from: private */
public static boolean trySetName(String str, Thread thread) {
try {
thread.setName(str);
return true;
} catch (SecurityException unused) {
return false;
}
}
}