Home | History | Annotate | Download | only in concurrent
      1 /*
      2  * Copyright (C) 2009 Google Inc.
      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.concurrent.ExecutionException;
     22 import java.util.concurrent.Future;
     23 import java.util.concurrent.TimeUnit;
     24 import java.util.concurrent.TimeoutException;
     25 
     26 /**
     27  * A {@link Future} which forwards all its method calls to another future.
     28  * Subclasses should override one or more methods to modify the behavior of
     29  * the backing collection as desired per the <a
     30  * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
     31  *
     32  * @see ForwardingObject
     33  * @author Sven Mawson
     34  * @since 2009.09.15 <b>tentative</b>
     35  */
     36 public abstract class ForwardingFuture<V> extends ForwardingObject
     37     implements Future<V> {
     38 
     39   @Override protected abstract Future<V> delegate();
     40 
     41   /*@Override*/
     42   public boolean cancel(boolean mayInterruptIfRunning) {
     43     return delegate().cancel(mayInterruptIfRunning);
     44   }
     45 
     46   /*@Override*/
     47   public boolean isCancelled() {
     48     return delegate().isCancelled();
     49   }
     50 
     51   /*@Override*/
     52   public boolean isDone() {
     53     return delegate().isDone();
     54   }
     55 
     56   /*@Override*/
     57   public V get() throws InterruptedException, ExecutionException {
     58     return delegate().get();
     59   }
     60 
     61   /*@Override*/
     62   public V get(long timeout, TimeUnit unit)
     63       throws InterruptedException, ExecutionException, TimeoutException {
     64     return delegate().get(timeout, unit);
     65   }
     66 }
     67