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.annotations.Beta; 020import com.google.common.annotations.GwtCompatible; 021 022import java.util.concurrent.ExecutionException; 023import java.util.concurrent.Future; 024 025/** 026 * Provides a backup {@code Future} to replace an earlier failed {@code Future}. An implementation 027 * of this interface can be applied to an input {@code Future} with {@link Futures#withFallback}. 028 * 029 * @param <V> the result type of the provided backup {@code Future} 030 * 031 * @author Bruno Diniz 032 * @since 14.0 033 * @deprecated This interface's main user, {@link Futures#withFallback(ListenableFuture, 034 * FutureFallback) Futures.withFallback}, has been updated to use {@link AsyncFunction}. We 035 * recommend that other APIs be updated in the same way. This interface will be removed in Guava 036 * release 20.0. 037 */ 038@Beta 039@Deprecated 040@GwtCompatible 041public interface FutureFallback<V> { 042 /** 043 * Returns a {@code Future} to be used in place of the {@code Future} that failed with the given 044 * exception. The exception is provided so that the {@code Fallback} implementation can 045 * conditionally determine whether to propagate the exception or to attempt to recover. 046 * 047 * @param t the exception that made the future fail. If the future's {@link Future#get() get} 048 * method throws an {@link ExecutionException}, then the cause is passed to this method. Any 049 * other thrown object is passed unaltered. 050 */ 051 ListenableFuture<V> create(Throwable t) throws Exception; 052}