Home | History | Annotate | Download | only in concurrent
      1 /*
      2  * Copyright (C) 2011 The Guava Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.util.concurrent;
     18 
     19 import com.google.common.collect.ForwardingObject;
     20 
     21 import java.util.Collection;
     22 import java.util.List;
     23 import java.util.concurrent.Callable;
     24 import java.util.concurrent.ExecutionException;
     25 import java.util.concurrent.ExecutorService;
     26 import java.util.concurrent.Future;
     27 import java.util.concurrent.TimeUnit;
     28 import java.util.concurrent.TimeoutException;
     29 
     30 /**
     31  * An executor service which forwards all its method calls to another executor
     32  * service. Subclasses should override one or more methods to modify the
     33  * behavior of the backing executor service as desired per the <a
     34  * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
     35  *
     36  * @author Kurt Alfred Kluever
     37  * @since 10.0
     38  */
     39 public abstract class ForwardingExecutorService extends ForwardingObject
     40     implements ExecutorService {
     41   /** Constructor for use by subclasses. */
     42   protected ForwardingExecutorService() {}
     43 
     44   @Override
     45   protected abstract ExecutorService delegate();
     46 
     47   @Override
     48   public boolean awaitTermination(long timeout, TimeUnit unit)
     49       throws InterruptedException {
     50     return delegate().awaitTermination(timeout, unit);
     51   }
     52 
     53   @Override
     54   public <T> List<Future<T>> invokeAll(
     55       Collection<? extends Callable<T>> tasks) throws InterruptedException {
     56     return delegate().invokeAll(tasks);
     57   }
     58 
     59   @Override
     60   public <T> List<Future<T>> invokeAll(
     61       Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
     62       throws InterruptedException {
     63     return delegate().invokeAll(tasks, timeout, unit);
     64   }
     65 
     66   @Override
     67   public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
     68       throws InterruptedException, ExecutionException {
     69     return delegate().invokeAny(tasks);
     70   }
     71 
     72   @Override
     73   public <T> T invokeAny(
     74       Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
     75       throws InterruptedException, ExecutionException, TimeoutException {
     76     return delegate().invokeAny(tasks, timeout, unit);
     77   }
     78 
     79   @Override
     80   public boolean isShutdown() {
     81     return delegate().isShutdown();
     82   }
     83 
     84   @Override
     85   public boolean isTerminated() {
     86     return delegate().isTerminated();
     87   }
     88 
     89   @Override
     90   public void shutdown() {
     91     delegate().shutdown();
     92   }
     93 
     94   @Override
     95   public List<Runnable> shutdownNow() {
     96     return delegate().shutdownNow();
     97   }
     98 
     99   @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 }
    118