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 * A future that, if it fails, may <i>optionally</i> provide access to the cause of the failure.
019 *
020 * <p>This class is used only for micro-optimization. Standard {@code Future} utilities benefit from
021 * this optimization, so there is no need to specialize methods to return or accept this type
022 * instead of {@code ListenableFuture}.
023 *
024 * <p>This class is GWT-compatible.
025 *
026 * @since {@code com.google.guava:failureaccess:1.0}, which was added as a dependency of Guava in
027 *     Guava 27.0
028 */
029public abstract class InternalFutureFailureAccess {
030  /** Constructor for use by subclasses. */
031  protected InternalFutureFailureAccess() {}
032
033  /**
034   * Usually returns {@code null} but, if this {@code Future} has failed, may <i>optionally</i>
035   * return the cause of the failure. "Failure" means specifically "completed with an exception"; it
036   * does not include "was cancelled." To be explicit: If this method returns a non-null value,
037   * then:
038   *
039   * <ul>
040   *   <li>{@code isDone()} must return {@code true}
041   *   <li>{@code isCancelled()} must return {@code false}
042   *   <li>{@code get()} must not block, and it must throw an {@code ExecutionException} with the
043   *       return value of this method as its cause
044   * </ul>
045   *
046   * <p>This method is {@code protected} so that classes like {@code
047   * com.google.common.util.concurrent.SettableFuture} do not expose it to their users as an
048   * instance method. In the unlikely event that you need to call this method, call {@link
049   * InternalFutures#tryInternalFastPathGetFailure(InternalFutureFailureAccess)}.
050   */
051  protected abstract Throwable tryInternalFastPathGetFailure();
052}