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.annotations.J2ktIncompatible; 019import com.google.common.collect.ForwardingObject; 020import com.google.errorprone.annotations.CanIgnoreReturnValue; 021import com.google.errorprone.annotations.CheckReturnValue; 022import java.util.Collection; 023import java.util.List; 024import java.util.concurrent.Callable; 025import java.util.concurrent.ExecutionException; 026import java.util.concurrent.ExecutorService; 027import java.util.concurrent.Future; 028import java.util.concurrent.TimeUnit; 029import java.util.concurrent.TimeoutException; 030import org.checkerframework.checker.nullness.qual.Nullable; 031 032/** 033 * An executor service which forwards all its method calls to another executor service. Subclasses 034 * should override one or more methods to modify the behavior of the backing executor service as 035 * desired per the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 036 * 037 * <p><b>{@code default} method warning:</b> This class does <i>not</i> forward calls to {@code 038 * default} methods. Instead, it inherits their default implementations. When those implementations 039 * invoke methods, they invoke methods on the {@code ForwardingExecutorService}. 040 * 041 * @author Kurt Alfred Kluever 042 * @since 10.0 043 */ 044@J2ktIncompatible 045@GwtIncompatible 046public abstract class ForwardingExecutorService extends ForwardingObject 047 implements ExecutorService { 048 /** Constructor for use by subclasses. */ 049 protected ForwardingExecutorService() {} 050 051 @Override 052 protected abstract ExecutorService delegate(); 053 054 @CheckReturnValue 055 @Override 056 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { 057 return delegate().awaitTermination(timeout, unit); 058 } 059 060 @Override 061 public <T extends @Nullable Object> List<Future<T>> invokeAll( 062 Collection<? extends Callable<T>> tasks) throws InterruptedException { 063 return delegate().invokeAll(tasks); 064 } 065 066 @Override 067 public <T extends @Nullable Object> List<Future<T>> invokeAll( 068 Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 069 throws InterruptedException { 070 return delegate().invokeAll(tasks, timeout, unit); 071 } 072 073 @Override 074 public <T extends @Nullable Object> T invokeAny(Collection<? extends Callable<T>> tasks) 075 throws InterruptedException, ExecutionException { 076 return delegate().invokeAny(tasks); 077 } 078 079 @Override 080 public <T extends @Nullable Object> T invokeAny( 081 Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 082 throws InterruptedException, ExecutionException, TimeoutException { 083 return delegate().invokeAny(tasks, timeout, unit); 084 } 085 086 @Override 087 public boolean isShutdown() { 088 return delegate().isShutdown(); 089 } 090 091 @Override 092 public boolean isTerminated() { 093 return delegate().isTerminated(); 094 } 095 096 @Override 097 public void shutdown() { 098 delegate().shutdown(); 099 } 100 101 @Override 102 @CanIgnoreReturnValue 103 public List<Runnable> shutdownNow() { 104 return delegate().shutdownNow(); 105 } 106 107 @Override 108 public void execute(Runnable command) { 109 delegate().execute(command); 110 } 111 112 @Override 113 public <T extends @Nullable Object> Future<T> submit(Callable<T> task) { 114 return delegate().submit(task); 115 } 116 117 @Override 118 public Future<?> submit(Runnable task) { 119 return delegate().submit(task); 120 } 121 122 @Override 123 public <T extends @Nullable Object> Future<T> submit( 124 Runnable task, @ParametricNullness T result) { 125 return delegate().submit(task, result); 126 } 127}