001/*
002 * Copyright (C) 2011 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.util.concurrent;
016
017import com.google.common.annotations.GwtIncompatible;
018import com.google.common.collect.ForwardingObject;
019import com.google.errorprone.annotations.CanIgnoreReturnValue;
020import java.util.Collection;
021import java.util.List;
022import java.util.concurrent.Callable;
023import java.util.concurrent.ExecutionException;
024import java.util.concurrent.ExecutorService;
025import java.util.concurrent.Future;
026import java.util.concurrent.TimeUnit;
027import java.util.concurrent.TimeoutException;
028import org.checkerframework.checker.nullness.qual.Nullable;
029
030/**
031 * An executor service which forwards all its method calls to another executor service. Subclasses
032 * should override one or more methods to modify the behavior of the backing executor service as
033 * desired per the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
034 *
035 * @author Kurt Alfred Kluever
036 * @since 10.0
037 */
038@CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict.
039@GwtIncompatible
040@ElementTypesAreNonnullByDefault
041public abstract class ForwardingExecutorService extends ForwardingObject
042    implements ExecutorService {
043  /** Constructor for use by subclasses. */
044  protected ForwardingExecutorService() {}
045
046  @Override
047  protected abstract ExecutorService delegate();
048
049  @Override
050  public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
051    return delegate().awaitTermination(timeout, unit);
052  }
053
054  @Override
055  public <T extends @Nullable Object> List<Future<T>> invokeAll(
056      Collection<? extends Callable<T>> tasks) throws InterruptedException {
057    return delegate().invokeAll(tasks);
058  }
059
060  @Override
061  public <T extends @Nullable Object> List<Future<T>> invokeAll(
062      Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
063      throws InterruptedException {
064    return delegate().invokeAll(tasks, timeout, unit);
065  }
066
067  @Override
068  public <T extends @Nullable Object> T invokeAny(Collection<? extends Callable<T>> tasks)
069      throws InterruptedException, ExecutionException {
070    return delegate().invokeAny(tasks);
071  }
072
073  @Override
074  public <T extends @Nullable Object> T invokeAny(
075      Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
076      throws InterruptedException, ExecutionException, TimeoutException {
077    return delegate().invokeAny(tasks, timeout, unit);
078  }
079
080  @Override
081  public boolean isShutdown() {
082    return delegate().isShutdown();
083  }
084
085  @Override
086  public boolean isTerminated() {
087    return delegate().isTerminated();
088  }
089
090  @Override
091  public void shutdown() {
092    delegate().shutdown();
093  }
094
095  @Override
096  public List<Runnable> shutdownNow() {
097    return delegate().shutdownNow();
098  }
099
100  @Override
101  public void execute(Runnable command) {
102    delegate().execute(command);
103  }
104
105  @Override
106  public <T extends @Nullable Object> Future<T> submit(Callable<T> task) {
107    return delegate().submit(task);
108  }
109
110  @Override
111  public Future<?> submit(Runnable task) {
112    return delegate().submit(task);
113  }
114
115  @Override
116  public <T extends @Nullable Object> Future<T> submit(
117      Runnable task, @ParametricNullness T result) {
118    return delegate().submit(task, result);
119  }
120}