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 017package com.google.common.util.concurrent; 018 019import com.google.common.collect.ForwardingObject; 020 021import java.util.Collection; 022import java.util.List; 023import java.util.concurrent.Callable; 024import java.util.concurrent.ExecutionException; 025import java.util.concurrent.ExecutorService; 026import java.util.concurrent.Future; 027import java.util.concurrent.TimeUnit; 028import 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 */ 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) 049 throws InterruptedException { 050 return delegate().awaitTermination(timeout, unit); 051 } 052 053 @Override 054 public <T> List<Future<T>> invokeAll( 055 Collection<? extends Callable<T>> tasks) throws InterruptedException { 056 return delegate().invokeAll(tasks); 057 } 058 059 @Override 060 public <T> List<Future<T>> invokeAll( 061 Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 062 throws InterruptedException { 063 return delegate().invokeAll(tasks, timeout, unit); 064 } 065 066 @Override 067 public <T> T invokeAny(Collection<? extends Callable<T>> tasks) 068 throws InterruptedException, ExecutionException { 069 return delegate().invokeAny(tasks); 070 } 071 072 @Override 073 public <T> T invokeAny( 074 Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 075 throws InterruptedException, ExecutionException, TimeoutException { 076 return delegate().invokeAny(tasks, timeout, unit); 077 } 078 079 @Override 080 public boolean isShutdown() { 081 return delegate().isShutdown(); 082 } 083 084 @Override 085 public boolean isTerminated() { 086 return delegate().isTerminated(); 087 } 088 089 @Override 090 public void shutdown() { 091 delegate().shutdown(); 092 } 093 094 @Override 095 public List<Runnable> shutdownNow() { 096 return delegate().shutdownNow(); 097 } 098 099 @Override 100 public void execute(Runnable command) { 101 delegate().execute(command); 102 } 103 104 public <T> Future<T> submit(Callable<T> task) { 105 return delegate().submit(task); 106 } 107 108 @Override 109 public Future<?> submit(Runnable task) { 110 return delegate().submit(task); 111 } 112 113 @Override 114 public <T> Future<T> submit(Runnable task, T result) { 115 return delegate().submit(task, result); 116 } 117}