1 /* 2 * Copyright (C) 2018 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.util.concurrent.internal; 16 17 /** 18 * A future that, if it fails, may <i>optionally</i> provide access to the cause of the failure. 19 * 20 * <p>This class is used only for micro-optimization. Standard {@code Future} utilities benefit from 21 * this optimization, so there is no need to specialize methods to return or accept this type 22 * instead of {@code ListenableFuture}. 23 * 24 * <p>This class is GWT-compatible. 25 * 26 * @since {@code com.google.guava:failureaccess:1.0}, which was added as a dependency of Guava in 27 * Guava 27.0 28 */ 29 public abstract class InternalFutureFailureAccess { 30 /** Constructor for use by subclasses. */ InternalFutureFailureAccess()31 protected InternalFutureFailureAccess() {} 32 33 /** 34 * Usually returns {@code null} but, if this {@code Future} has failed, may <i>optionally</i> 35 * return the cause of the failure. "Failure" means specifically "completed with an exception"; it 36 * does not include "was cancelled." To be explicit: If this method returns a non-null value, 37 * then: 38 * 39 * <ul> 40 * <li>{@code isDone()} must return {@code true} 41 * <li>{@code isCancelled()} must return {@code false} 42 * <li>{@code get()} must not block, and it must throw an {@code ExecutionException} with the 43 * return value of this method as its cause 44 * </ul> 45 * 46 * <p>This method is {@code protected} so that classes like {@code 47 * com.google.common.util.concurrent.SettableFuture} do not expose it to their users as an 48 * instance method. In the unlikely event that you need to call this method, call {@link 49 * InternalFutures#tryInternalFastPathGetFailure(InternalFutureFailureAccess)}. 50 */ tryInternalFastPathGetFailure()51 protected abstract Throwable tryInternalFastPathGetFailure(); 52 } 53