/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
package dev.failsafe;

import java.time.Duration;

/**
 * Contextual execution information.
 *
 * @param <R> result type
 * @author Jonathan Halterman
 */
public interface ExecutionContext<R> {
  /**
   * Returns the elapsed time since initial execution began.
   */
  Duration getElapsedTime();

  /**
   * Returns the elapsed time since the last execution attempt began.
   */
  Duration getElapsedAttemptTime();

  /**
   * Gets the number of execution attempts so far, including attempts that are blocked before being executed, such as
   * when a {@link CircuitBreaker CircuitBreaker} is open. Will return {@code 0} when the first
   * attempt is in progress or has yet to begin.
   */
  int getAttemptCount();

  /**
   * Gets the number of completed executions so far. Executions that are blocked, such as when a {@link
   * CircuitBreaker CircuitBreaker} is open, are not counted. Will return {@code 0} when the first
   * attempt is in progress or has yet to begin.
   */
  int getExecutionCount();

  /**
   * Returns the last failure that was recorded else {@code null}.
   */
  <T extends Throwable> T getLastFailure();

  /**
   * Returns the last result that was recorded else {@code null}.
   */
  R getLastResult();

  /**
   * Returns the last result that was recorded else the {@code defaultValue}.
   */
  R getLastResult(R defaultValue);

  /**
   * Returns the time that the initial execution started.
   */
  Duration getStartTime();

  /**
   * Returns whether the execution has been cancelled. In this case the implementor should attempt to stop execution.
   */
  boolean isCancelled();

  /**
   * Returns {@code true} when {@link #getAttemptCount()} is {@code 0} meaning this is the first execution attempt.
   */
  boolean isFirstAttempt();

  /**
   * Returns {@code true} when {@link #getAttemptCount()} is {@code > 0} meaning the execution is being retried.
   */
  boolean isRetry();
}

@@ -1162,31 +1162,16 @@
  %7B@link 
-CircuitBreaker 
 CircuitB
@@ -1215,37 +1215,32 @@
 %7D when the first
-%0A   *
  attempt is in p
@@ -1252,32 +1252,37 @@
 ss or has yet to
+%0A   *
  begin.%0A   */%0A  
@@ -1418,28 +1418,8 @@
 link
-%0A   * CircuitBreaker
  Cir
@@ -1422,32 +1422,37 @@
  CircuitBreaker%7D
+%0A   *
  is open, are no
@@ -1498,21 +1498,16 @@
 he first
-%0A   *
  attempt
@@ -2222,47 +2222,54 @@
 hen 
-%7B@link #getAttemptCount()%7D is %7B@
+an execution result has not yet been re
 co
+r
 de
- 0%7D
+d,
  mea
@@ -2292,32 +2292,37 @@
  first execution
+%0A   *
  attempt.%0A   */%0A
@@ -2391,49 +2391,54 @@
 hen 
-%7B@link #getAttemptCount()%7D is %7B@
+an execution result has already been re
 co
+r
 de
- %3E 0%7D
+d,
  mea

Clarify ExecutionContext javadocs.