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