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

124 lines
4.7 KiB
Java
Raw Permalink 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.Throwables;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/* loaded from: classes2.dex */
abstract class WrappingExecutorService implements ExecutorService {
private final ExecutorService delegate;
/* JADX INFO: Access modifiers changed from: protected */
public abstract <T> Callable<T> wrapTask(Callable<T> callable);
/* JADX INFO: Access modifiers changed from: protected */
public WrappingExecutorService(ExecutorService executorService) {
this.delegate = (ExecutorService) Preconditions.checkNotNull(executorService);
}
/* JADX INFO: Access modifiers changed from: protected */
public Runnable wrapTask(Runnable runnable) {
return new Runnable(this, wrapTask(Executors.callable(runnable, null))) { // from class: com.google.common.util.concurrent.WrappingExecutorService.1
final Callable val$wrapped;
{
this.val$wrapped = r2;
}
@Override // java.lang.Runnable
public void run() {
try {
this.val$wrapped.call();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
};
}
private <T> ImmutableList<Callable<T>> wrapTasks(Collection<? extends Callable<T>> collection) {
ImmutableList.Builder builder = ImmutableList.builder();
Iterator<? extends Callable<T>> it = collection.iterator();
while (it.hasNext()) {
builder.add((ImmutableList.Builder) wrapTask(it.next()));
}
return builder.build();
}
@Override // java.util.concurrent.Executor
public final void execute(Runnable runnable) {
this.delegate.execute(wrapTask(runnable));
}
@Override // java.util.concurrent.ExecutorService
public final <T> Future<T> submit(Callable<T> callable) {
return this.delegate.submit(wrapTask((Callable) Preconditions.checkNotNull(callable)));
}
@Override // java.util.concurrent.ExecutorService
public final Future<?> submit(Runnable runnable) {
return this.delegate.submit(wrapTask(runnable));
}
@Override // java.util.concurrent.ExecutorService
public final <T> Future<T> submit(Runnable runnable, T t) {
return this.delegate.submit(wrapTask(runnable), t);
}
@Override // java.util.concurrent.ExecutorService
public final <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> collection) throws InterruptedException {
return this.delegate.invokeAll(wrapTasks(collection));
}
@Override // java.util.concurrent.ExecutorService
public final <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> collection, long j, TimeUnit timeUnit) throws InterruptedException {
return this.delegate.invokeAll(wrapTasks(collection), j, timeUnit);
}
@Override // java.util.concurrent.ExecutorService
public final <T> T invokeAny(Collection<? extends Callable<T>> collection) throws InterruptedException, ExecutionException {
return (T) this.delegate.invokeAny(wrapTasks(collection));
}
@Override // java.util.concurrent.ExecutorService
public final <T> T invokeAny(Collection<? extends Callable<T>> collection, long j, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
return (T) this.delegate.invokeAny(wrapTasks(collection), j, timeUnit);
}
@Override // java.util.concurrent.ExecutorService
public final void shutdown() {
this.delegate.shutdown();
}
@Override // java.util.concurrent.ExecutorService
public final List<Runnable> shutdownNow() {
return this.delegate.shutdownNow();
}
@Override // java.util.concurrent.ExecutorService
public final boolean isShutdown() {
return this.delegate.isShutdown();
}
@Override // java.util.concurrent.ExecutorService
public final boolean isTerminated() {
return this.delegate.isTerminated();
}
@Override // java.util.concurrent.ExecutorService
public final boolean awaitTermination(long j, TimeUnit timeUnit) throws InterruptedException {
return this.delegate.awaitTermination(j, timeUnit);
}
}