001/* 002 * Copyright (C) 2018 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.common.util.concurrent.internal; 016 017 018/** 019 * A future that, if it fails, may <i>optionally</i> provide access to the cause of the failure. 020 * 021 * <p>This class is used only for micro-optimization. Standard {@code Future} utilities benefit from 022 * this optimization, so there is no need to specialize methods to return or accept this type 023 * instead of {@code ListenableFuture}. 024 * 025 * <p>This class is GWT-compatible. 026 * 027 * @since {@code com.google.guava:failureaccess:1.0}, which was added as a dependency of Guava in 028 * Guava 27.0 029 */ 030public abstract class InternalFutureFailureAccess { 031 /** Constructor for use by subclasses. */ 032 protected InternalFutureFailureAccess() {} 033 034 /** 035 * Usually returns {@code null} but, if this {@code Future} has failed, may <i>optionally</i> 036 * return the cause of the failure. "Failure" means specifically "completed with an exception"; it 037 * does not include "was cancelled." To be explicit: If this method returns a non-null value, 038 * then: 039 * 040 * <ul> 041 * <li>{@code isDone()} must return {@code true} 042 * <li>{@code isCancelled()} must return {@code false} 043 * <li>{@code get()} must not block, and it must throw an {@code ExecutionException} with the 044 * return value of this method as its cause 045 * </ul> 046 * 047 * <p>This method is {@code protected} so that classes like {@code 048 * com.google.common.util.concurrent.SettableFuture} do not expose it to their users as an 049 * instance method. In the unlikely event that you need to call this method, call {@link 050 * InternalFutures#tryInternalFastPathGetFailure(InternalFutureFailureAccess)}. 051 */ 052 protected abstract 053 Throwable tryInternalFastPathGetFailure(); 054}