Class 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 execution
      private long delayNanos
      The amount of time to wait prior to the next execution, according to the policy
      private java.lang.Throwable exception
      The execution exception, if any
      private static ExecutionResult<?> NONE  
      private boolean nonResult
      Whether the result represents a non result rather than a null result
      private static java.util.concurrent.CompletableFuture<?> NULL_FUTURE  
      private R result
      The execution result, if any
      private boolean success
      Whether a policy determined the execution to be a success
      private 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 with complete true and success set to true if exception is not null.
      private ExecutionResult​(R result, java.lang.Throwable exception, boolean nonResult, long delayNanos, boolean complete, boolean success, java.lang.Boolean successAll)  
    • Field Detail

      • NULL_FUTURE

        private static final java.util.concurrent.CompletableFuture<?> NULL_FUTURE
      • 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 a null 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 with complete true and success set to true if exception 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 with null. Uses an intern'ed value to avoid new object creation.
      • success

        public static <R> ExecutionResult<R> success​(R result)
        Returns an ExecutionResult with the result set, complete true and success true.
      • exception

        public static <R> ExecutionResult<R> exception​(java.lang.Throwable exception)
        Returns an ExecutionResult with the exception set, complete true and success 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()
        Returns a copy of the ExecutionResult with a non-result, and complete and success set to true. Returns this if success and result are unchanged.
      • withResult

        public ExecutionResult<R> withResult​(R result)
        Returns a copy of the ExecutionResult with the result value, and complete and success set to true. Returns this if success and result are unchanged.
      • withNotComplete

        public ExecutionResult<R> withNotComplete()
        Returns a copy of the ExecutionResult with complete 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 the complete and success values of true.
      • withDelay

        public ExecutionResult<R> withDelay​(long delayNanos)
        Returns a copy of the ExecutionResult with the delayNanos value.
      • with

        public ExecutionResult<R> with​(long delayNanos,
                                       boolean complete,
                                       boolean success)
        Returns a copy of the ExecutionResult with the delayNanos, complete and success values.
      • getSuccessAll

        public boolean getSuccessAll()
        Returns whether the execution was successful for all policies.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object