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; 020 021import java.util.concurrent.ExecutionException; 022import java.util.concurrent.Future; 023 024/** 025 * Provides a backup {@code Future} to replace an earlier failed {@code Future}. 026 * An implementation of this interface can be applied to an input {@code Future} 027 * 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 */ 034@Beta 035public interface FutureFallback<V> { 036 /** 037 * Returns a {@code Future} to be used in place of the {@code Future} that 038 * failed with the given exception. The exception is provided so that the 039 * {@code Fallback} implementation can conditionally determine whether to 040 * propagate the exception or to attempt to recover. 041 * 042 * @param t the exception that made the future fail. If the future's {@link 043 * Future#get() get} method throws an {@link ExecutionException}, then the 044 * cause is passed to this method. Any other thrown object is passed 045 * unaltered. 046 */ 047 ListenableFuture<V> create(Throwable t) throws Exception; 048}