Interface ExecutionContext<R>
- Type Parameters:
R- result type
- All Known Subinterfaces:
AsyncExecution<R>, AsyncExecutionInternal<R>, Execution<R>, ExecutionInternal<R>, SyncExecutionInternal<R>
- All Known Implementing Classes:
AsyncExecutionImpl, ExecutionImpl, SyncExecutionImpl
public interface ExecutionContext<R>
Contextual execution information.
-
Method Summary
Modifier and TypeMethodDescriptionintGets the number of execution attempts so far, including attempts that are blocked before being executed, such as when aCircuitBreakeris open.Returns the elapsed time since the last execution attempt began.Returns the elapsed time since initial execution began.intGets the number of completed executions so far.<T extends Throwable>
TReturns the last exception that was recorded elsenull.Returns the last result that was recorded elsenull.getLastResult(R defaultValue) Returns the last result that was recorded else thedefaultValue.Returns the time that the initial execution started.booleanReturns whether the execution has been cancelled.booleanReturnstruewhen an execution result has not yet been recorded, meaning this is the first execution attempt.booleanisRetry()Returnstruewhen an execution result has already been recorded, meaning the execution is being retried.voidonCancel(CheckedRunnable cancelCallback) Sets thecancelCallbackto be called if the execution is cancelled, such as by the resultingCallorCompletableFuture, or aTimeout.
-
Method Details
-
onCancel
Sets thecancelCallbackto be called if the execution is cancelled, such as by the resultingCallorCompletableFuture, or aTimeout. Any exception thrown by thecancelCallbackis ignored. -
getElapsedTime
Duration getElapsedTime()Returns the elapsed time since initial execution began. -
getElapsedAttemptTime
Duration getElapsedAttemptTime()Returns the elapsed time since the last execution attempt began. -
getAttemptCount
int getAttemptCount()Gets the number of execution attempts so far, including attempts that are blocked before being executed, such as when aCircuitBreakeris open. Will return0when the first attempt is in progress or has yet to begin. -
getExecutionCount
int getExecutionCount()Gets the number of completed executions so far. Executions that are blocked, such as when aCircuitBreakeris open, are not counted. Will return0when the first attempt is in progress or has yet to begin. -
getLastException
Returns the last exception that was recorded elsenull. -
getLastResult
R getLastResult()Returns the last result that was recorded elsenull. -
getLastResult
-
getStartTime
Instant getStartTime()Returns the time that the initial execution started. -
isCancelled
boolean isCancelled()Returns whether the execution has been cancelled. In this case the implementor should attempt to stop execution. -
isFirstAttempt
boolean isFirstAttempt()Returnstruewhen an execution result has not yet been recorded, meaning this is the first execution attempt. -
isRetry
boolean isRetry()Returnstruewhen an execution result has already been recorded, meaning the execution is being retried.
-