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; 028 029/** 030 * An executor service which forwards all its method calls to another executor service. Subclasses 031 * should override one or more methods to modify the behavior of the backing executor service as 032 * desired per the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 033 * 034 * @author Kurt Alfred Kluever 035 * @since 10.0 036 */ 037@CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict. 038@GwtIncompatible 039public abstract class ForwardingExecutorService extends ForwardingObject 040 implements ExecutorService { 041 /** Constructor for use by subclasses. */ 042 protected ForwardingExecutorService() {} 043 044 @Override 045 protected abstract ExecutorService delegate(); 046 047 @Override 048 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { 049 return delegate().awaitTermination(timeout, unit); 050 } 051 052 @Override 053 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) 054 throws InterruptedException { 055 return delegate().invokeAll(tasks); 056 } 057 058 @Override 059 public <T> List<Future<T>> invokeAll( 060 Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 061 throws InterruptedException { 062 return delegate().invokeAll(tasks, timeout, unit); 063 } 064 065 @Override 066 public <T> T invokeAny(Collection<? extends Callable<T>> tasks) 067 throws InterruptedException, ExecutionException { 068 return delegate().invokeAny(tasks); 069 } 070 071 @Override 072 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 073 throws InterruptedException, ExecutionException, TimeoutException { 074 return delegate().invokeAny(tasks, timeout, unit); 075 } 076 077 @Override 078 public boolean isShutdown() { 079 return delegate().isShutdown(); 080 } 081 082 @Override 083 public boolean isTerminated() { 084 return delegate().isTerminated(); 085 } 086 087 @Override 088 public void shutdown() { 089 delegate().shutdown(); 090 } 091 092 @Override 093 public List<Runnable> shutdownNow() { 094 return delegate().shutdownNow(); 095 } 096 097 @Override 098 public void execute(Runnable command) { 099 delegate().execute(command); 100 } 101 102 @Override 103 public <T> Future<T> submit(Callable<T> task) { 104 return delegate().submit(task); 105 } 106 107 @Override 108 public Future<?> submit(Runnable task) { 109 return delegate().submit(task); 110 } 111 112 @Override 113 public <T> Future<T> submit(Runnable task, T result) { 114 return delegate().submit(task, result); 115 } 116}