Package dev.failsafe
Class AsyncExecutionImpl<R>
- java.lang.Object
-
- dev.failsafe.ExecutionImpl<R>
-
- dev.failsafe.AsyncExecutionImpl<R>
-
- Type Parameters:
R
- result type
- All Implemented Interfaces:
AsyncExecution<R>
,ExecutionContext<R>
,AsyncExecutionInternal<R>
,ExecutionInternal<R>
final class AsyncExecutionImpl<R> extends ExecutionImpl<R> implements AsyncExecutionInternal<R>
AsyncExecution and AsyncExecutionInternal implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
asyncExecution
private FailsafeFuture<R>
future
private java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>>
outerFn
private boolean[]
policyPostExecuted
private boolean
recorded
-
Fields inherited from class dev.failsafe.ExecutionImpl
attemptRecorded, cancelCallback, cancelledIndex, completed, policyExecutors, result
-
-
Constructor Summary
Constructors Modifier Constructor Description private
AsyncExecutionImpl(AsyncExecutionImpl<R> execution)
Create an async execution for a new attempt.(package private)
AsyncExecutionImpl(java.util.List<Policy<R>> policies, Scheduler scheduler, FailsafeFuture<R> future, boolean asyncExecution, java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
complete()
Completes the execution and the associatedCompletableFuture
.private void
complete(ExecutionResult<R> result, java.lang.Throwable error)
AsyncExecutionInternal<R>
copy()
Returns a new copy of the AsyncExecutionInternal.(package private) void
executeAsync()
Performs an asynchronous execution.boolean
isAsyncExecution()
Returns whether the execution is an async integration execution.boolean
isComplete()
Returns whether the execution is complete or if it can be retried.boolean
isPostExecuted(int policyIndex)
Returns whether the PolicyExecutor corresponding to thepolicyIndex
has already post-executed.boolean
isRecorded()
Returns whether one of the publicAsyncExecution
record or complete methods have been called.void
record(R result, java.lang.Throwable exception)
Records an executionresult
orexception
which triggers failure handling, if needed, by the configured policies.void
recordException(java.lang.Throwable exception)
Records anexception
which triggers failure handling, if needed, by the configured policies.void
recordResult(R result)
Records an executionresult
which triggers failure handling, if needed, by the configured policies.void
setPostExecuted(int policyIndex)
Sets the PolicyExecutor corresponding to thepolicyIndex
as having post-executed.-
Methods inherited from class dev.failsafe.ExecutionImpl
cancel, cancel, getAttemptCount, getElapsedAttemptTime, getElapsedTime, getExecutionCount, getLastException, getLastResult, getLastResult, getLatest, getLock, getResult, getStartTime, isCancelled, isCancelled, isFirstAttempt, isPreExecuted, isRetry, onCancel, postExecute, preExecute, record, recordAttempt, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface dev.failsafe.ExecutionContext
getAttemptCount, getElapsedAttemptTime, getElapsedTime, getExecutionCount, getLastException, getLastResult, getLastResult, getStartTime, isCancelled, isFirstAttempt, isRetry, onCancel
-
Methods inherited from interface dev.failsafe.spi.ExecutionInternal
cancel, cancel, getLatest, getLock, getResult, isCancelled, isPreExecuted, preExecute, record, recordAttempt
-
-
-
-
Field Detail
-
future
private final FailsafeFuture<R> future
-
asyncExecution
private final boolean asyncExecution
-
outerFn
private java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> outerFn
-
policyPostExecuted
private final boolean[] policyPostExecuted
-
recorded
private volatile boolean recorded
-
-
Constructor Detail
-
AsyncExecutionImpl
AsyncExecutionImpl(java.util.List<Policy<R>> policies, Scheduler scheduler, FailsafeFuture<R> future, boolean asyncExecution, java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn)
-
AsyncExecutionImpl
private AsyncExecutionImpl(AsyncExecutionImpl<R> execution)
Create an async execution for a new attempt.
-
-
Method Detail
-
complete
public void complete()
Description copied from interface:AsyncExecution
Completes the execution and the associatedCompletableFuture
.- Specified by:
complete
in interfaceAsyncExecution<R>
-
isComplete
public boolean isComplete()
Description copied from interface:AsyncExecution
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.- Specified by:
isComplete
in interfaceAsyncExecution<R>
-
record
public void record(R result, java.lang.Throwable exception)
Description copied from interface:AsyncExecution
Records an executionresult
orexception
which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or already complete, the resultingCompletableFuture
is completed.- Specified by:
record
in interfaceAsyncExecution<R>
-
recordResult
public void recordResult(R result)
Description copied from interface:AsyncExecution
Records an executionresult
which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or already complete, the resultingCompletableFuture
is completed.- Specified by:
recordResult
in interfaceAsyncExecution<R>
-
recordException
public void recordException(java.lang.Throwable exception)
Description copied from interface:AsyncExecution
Records anexception
which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or already complete, the resultingCompletableFuture
is completed.- Specified by:
recordException
in interfaceAsyncExecution<R>
-
isAsyncExecution
public boolean isAsyncExecution()
Description copied from interface:AsyncExecutionInternal
Returns whether the execution is an async integration execution.- Specified by:
isAsyncExecution
in interfaceAsyncExecutionInternal<R>
-
isRecorded
public boolean isRecorded()
Description copied from interface:AsyncExecutionInternal
Returns whether one of the publicAsyncExecution
record or complete methods have been called.- Specified by:
isRecorded
in interfaceAsyncExecutionInternal<R>
-
setPostExecuted
public void setPostExecuted(int policyIndex)
Description copied from interface:AsyncExecutionInternal
Sets the PolicyExecutor corresponding to thepolicyIndex
as having post-executed.- Specified by:
setPostExecuted
in interfaceAsyncExecutionInternal<R>
-
isPostExecuted
public boolean isPostExecuted(int policyIndex)
Description copied from interface:AsyncExecutionInternal
Returns whether the PolicyExecutor corresponding to thepolicyIndex
has already post-executed.- Specified by:
isPostExecuted
in interfaceAsyncExecutionInternal<R>
-
copy
public AsyncExecutionInternal<R> copy()
Description copied from interface:AsyncExecutionInternal
Returns a new copy of the AsyncExecutionInternal.- Specified by:
copy
in interfaceAsyncExecutionInternal<R>
-
executeAsync
void executeAsync()
Performs an asynchronous execution.
-
complete
private void complete(ExecutionResult<R> result, java.lang.Throwable error)
-
-