Package dev.failsafe.spi
Class ExecutionResult<R>
- java.lang.Object
-
- dev.failsafe.spi.ExecutionResult<R>
-
- Type Parameters:
R
- result type
public final class ExecutionResult<R> extends java.lang.Object
This class represents the internal result of an execution attempt for zero or more policies, before or after the policy has handled the result. If a policy is done handling a result or is no longer able to handle a result, such as when retries are exceeded, the ExecutionResult should be marked as complete.This class is immutable.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
complete
Whether a policy has completed handling of the executionprivate long
delayNanos
The amount of time to wait prior to the next execution, according to the policyprivate java.lang.Throwable
exception
The execution exception, if anyprivate static ExecutionResult<?>
NONE
private boolean
nonResult
Whether the result represents a non result rather than anull
resultprivate static java.util.concurrent.CompletableFuture<?>
NULL_FUTURE
private R
result
The execution result, if anyprivate boolean
success
Whether a policy determined the execution to be a successprivate java.lang.Boolean
successAll
Whether all policies determined the execution to be a success
-
Constructor Summary
Constructors Modifier Constructor Description ExecutionResult(R result, java.lang.Throwable exception)
Records an initial execution result withcomplete
true andsuccess
set to true ifexception
is not null.private
ExecutionResult(R result, java.lang.Throwable exception, boolean nonResult, long delayNanos, boolean complete, boolean success, java.lang.Boolean successAll)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
static <R> ExecutionResult<R>
exception(java.lang.Throwable exception)
Returns an ExecutionResult with theexception
set,complete
true andsuccess
false.long
getDelay()
java.lang.Throwable
getException()
R
getResult()
boolean
getSuccessAll()
Returns whether the execution was successful for all policies.int
hashCode()
boolean
isComplete()
boolean
isNonResult()
boolean
isSuccess()
static <R> ExecutionResult<R>
none()
Returns an execution that was completed with a non-result.static <R> java.util.concurrent.CompletableFuture<ExecutionResult<R>>
nullFuture()
Returns a CompletableFuture that is completed withnull
.static <R> ExecutionResult<R>
success(R result)
Returns an ExecutionResult with theresult
set,complete
true andsuccess
true.java.lang.String
toString()
ExecutionResult<R>
with(long delayNanos, boolean complete, boolean success)
Returns a copy of the ExecutionResult with thedelayNanos
,complete
andsuccess
values.ExecutionResult<R>
withDelay(long delayNanos)
Returns a copy of the ExecutionResult with thedelayNanos
value.ExecutionResult<R>
withException()
Returns a copy of the ExecutionResult with success value of {code false}.ExecutionResult<R>
withNonResult()
Returns a copy of the ExecutionResult with a non-result, and complete and success set to true.ExecutionResult<R>
withNotComplete()
Returns a copy of the ExecutionResult withcomplete
set to false, else this if nothing has changed.ExecutionResult<R>
withResult(R result)
Returns a copy of the ExecutionResult with theresult
value, and complete and success set to true.ExecutionResult<R>
withSuccess()
Returns a copy of the ExecutionResult with thecomplete
andsuccess
values oftrue
.
-
-
-
Field Detail
-
NULL_FUTURE
private static final java.util.concurrent.CompletableFuture<?> NULL_FUTURE
-
NONE
private static final ExecutionResult<?> NONE
-
result
private final R result
The execution result, if any
-
exception
private final java.lang.Throwable exception
The execution exception, if any
-
nonResult
private final boolean nonResult
Whether the result represents a non result rather than anull
result
-
delayNanos
private final long delayNanos
The amount of time to wait prior to the next execution, according to the policy
-
complete
private final boolean complete
Whether a policy has completed handling of the execution
-
success
private final boolean success
Whether a policy determined the execution to be a success
-
successAll
private final java.lang.Boolean successAll
Whether all policies determined the execution to be a success
-
-
Constructor Detail
-
ExecutionResult
public ExecutionResult(R result, java.lang.Throwable exception)
Records an initial execution result withcomplete
true andsuccess
set to true ifexception
is not null.
-
ExecutionResult
private ExecutionResult(R result, java.lang.Throwable exception, boolean nonResult, long delayNanos, boolean complete, boolean success, java.lang.Boolean successAll)
-
-
Method Detail
-
nullFuture
public static <R> java.util.concurrent.CompletableFuture<ExecutionResult<R>> nullFuture()
Returns a CompletableFuture that is completed withnull
. Uses an intern'ed value to avoid new object creation.
-
success
public static <R> ExecutionResult<R> success(R result)
Returns an ExecutionResult with theresult
set,complete
true andsuccess
true.
-
exception
public static <R> ExecutionResult<R> exception(java.lang.Throwable exception)
Returns an ExecutionResult with theexception
set,complete
true andsuccess
false.
-
none
public static <R> ExecutionResult<R> none()
Returns an execution that was completed with a non-result. Uses an intern'ed value to avoid new object creation.
-
getResult
public R getResult()
-
getException
public java.lang.Throwable getException()
-
getDelay
public long getDelay()
-
isComplete
public boolean isComplete()
-
isNonResult
public boolean isNonResult()
-
isSuccess
public boolean isSuccess()
-
withNonResult
public ExecutionResult<R> withNonResult()
-
withResult
public ExecutionResult<R> withResult(R result)
-
withNotComplete
public ExecutionResult<R> withNotComplete()
Returns a copy of the ExecutionResult withcomplete
set to false, else this if nothing has changed.
-
withException
public ExecutionResult<R> withException()
Returns a copy of the ExecutionResult with success value of {code false}.
-
withSuccess
public ExecutionResult<R> withSuccess()
Returns a copy of the ExecutionResult with thecomplete
andsuccess
values oftrue
.
-
withDelay
public ExecutionResult<R> withDelay(long delayNanos)
Returns a copy of the ExecutionResult with thedelayNanos
value.
-
with
public ExecutionResult<R> with(long delayNanos, boolean complete, boolean success)
Returns a copy of the ExecutionResult with thedelayNanos
,complete
andsuccess
values.
-
getSuccessAll
public boolean getSuccessAll()
Returns whether the execution was successful for all policies.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-