Package dev.failsafe

Interface Execution<R>

Type Parameters:
R - result type
All Superinterfaces:
ExecutionContext<R>
All Known Subinterfaces:
SyncExecutionInternal<R>
All Known Implementing Classes:
SyncExecutionImpl

public interface Execution<R> extends ExecutionContext<R>
Tracks synchronous executions and handles failures according to one or more policies. Execution results must be explicitly recorded via one of the record methods.
  • Method Details

    • of

      @SafeVarargs static <R> Execution<R> of(Policy<R> outerPolicy, Policy<R>... policies)
      Creates a new Execution that will use the outerPolicy and innerPolicies to handle failures. Policies are applied in reverse order, with the last policy being applied first.
      Throws:
      NullPointerException - if outerPolicy is null
    • complete

      void complete()
      Records and completes the execution successfully.
      Throws:
      IllegalStateException - if the execution is already complete
    • isComplete

      boolean isComplete()
      Returns whether the execution is complete or if it can be retried. An execution is considered complete only when all configured policies consider the execution complete.
    • getDelay

      Duration getDelay()
      Returns the time to delay before the next execution attempt. Returns 0 if an execution has not yet occurred.
    • record

      void record(R result, Throwable exception)
      Records an execution result or exception which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed.
      Throws:
      IllegalStateException - if the execution is already complete
    • recordResult

      void recordResult(R result)
      Records an execution result which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed.
      Throws:
      IllegalStateException - if the execution is already complete
    • recordException

      void recordException(Throwable exception)
      Records an exception which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed.
      Throws:
      IllegalStateException - if the execution is already complete