package io.micronaut.scheduling.instrument;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Collectors;
public interface InstrumentedExecutorService extends ExecutorService, InstrumentedExecutor {
@Override
ExecutorService getTarget();
default <T> Callable<T> instrument(Callable<T> task) {
return task;
}
@Override
default void shutdown() {
getTarget().shutdown();
}
@Override
default List<Runnable> shutdownNow() {
return getTarget().shutdownNow();
}
@Override
default boolean isShutdown() {
return getTarget().isShutdown();
}
@Override
default boolean isTerminated() {
return getTarget().isTerminated();
}
@Override
default boolean awaitTermination(long timeout, @NonNull TimeUnit unit) throws InterruptedException {
return getTarget().awaitTermination(timeout, unit);
}
@Override
default @NonNull <T> Future<T> submit(@NonNull Callable<T> task) {
return getTarget().submit(instrument(task));
}
@Override
default @NonNull <T> Future<T> submit(@NonNull Runnable task, T result) {
return getTarget().submit(instrument(task), result);
}
@Override
default @NonNull Future<?> submit(@NonNull Runnable task) {
return getTarget().submit(instrument(task));
}
@Override
default @NonNull <T> List<Future<T>> invokeAll(@NonNull Collection<? extends Callable<T>> tasks) throws InterruptedException {
return getTarget().invokeAll(
tasks.stream().map(this::instrument).collect(Collectors.toList())
);
}
@Override
default @NonNull <T> List<Future<T>> invokeAll(@NonNull Collection<? extends Callable<T>> tasks, long timeout, @NonNull TimeUnit unit) throws InterruptedException {
return getTarget().invokeAll(
tasks.stream().map(this::instrument).collect(Collectors.toList()), timeout, unit
);
}
@Override
default @NonNull <T> T invokeAny(@NonNull Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
return getTarget().invokeAny(
tasks.stream().map(this::instrument).collect(Collectors.toList())
);
}
@Override
default @NonNull <T> T invokeAny(@NonNull Collection<? extends Callable<T>> tasks, long timeout, @NonNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return getTarget().invokeAny(
tasks.stream().map(this::instrument).collect(Collectors.toList()), timeout, unit
);
}
}