Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement InterceptingExecutorService without Guava #5565

Merged
merged 2 commits into from
Jun 19, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions core/src/main/java/jenkins/util/InterceptingExecutorService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package jenkins.util;

import com.google.common.util.concurrent.ForwardingExecutorService;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -18,7 +16,7 @@
* @author Kohsuke Kawaguchi
* @since 1.557
*/
public abstract class InterceptingExecutorService extends ForwardingExecutorService {
public abstract class InterceptingExecutorService implements ExecutorService {
private final ExecutorService base;

public InterceptingExecutorService(ExecutorService base) {
Expand All @@ -29,49 +27,78 @@ public InterceptingExecutorService(ExecutorService base) {

protected abstract <V> Callable<V> wrap(Callable<V> r);

@Override
protected ExecutorService delegate() {
return base;
}

@Override
public <T> Future<T> submit(Callable<T> task) {
return super.submit(wrap(task));
return delegate().submit(wrap(task));
}

@Override
public <T> Future<T> submit(Runnable task, T result) {
return super.submit(wrap(task), result);
return delegate().submit(wrap(task), result);
}

@Override
public Future<?> submit(Runnable task) {
return super.submit(wrap(task));
return delegate().submit(wrap(task));
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
return super.invokeAll(wrap(tasks));
return delegate().invokeAll(wrap(tasks));
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
return super.invokeAll(wrap(tasks), timeout, unit);
return delegate().invokeAll(wrap(tasks), timeout, unit);
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
return super.invokeAny(wrap(tasks));
return delegate().invokeAny(wrap(tasks));
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return super.invokeAny(wrap(tasks), timeout, unit);
return delegate().invokeAny(wrap(tasks), timeout, unit);
}

@Override
public void execute(Runnable command) {
super.execute(wrap(command));
delegate().execute(wrap(command));
}


@Override
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
return delegate().awaitTermination(timeout, unit);
}

@Override
public boolean isShutdown() {
return delegate().isShutdown();
}

@Override
public boolean isTerminated() {
return delegate().isTerminated();
}

@Override
public void shutdown() {
delegate().shutdown();
}

@Override
public List<Runnable> shutdownNow() {
return delegate().shutdownNow();
}

@Override
public String toString() {
return delegate().toString();
basil marked this conversation as resolved.
Show resolved Hide resolved
}

private <T> Collection<Callable<T>> wrap(Collection<? extends Callable<T>> callables) {
Expand Down