Package dev.failsafe
Class SyncExecutionImpl<R>
java.lang.Object
dev.failsafe.ExecutionImpl<R>
dev.failsafe.SyncExecutionImpl<R>
- Type Parameters:
R
- result type
- All Implemented Interfaces:
Execution<R>
,ExecutionContext<R>
,ExecutionInternal<R>
,SyncExecutionInternal<R>
SyncExecution and SyncExecutionInternal implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
private final Thread
private final FailsafeExecutor
<R> private final AtomicBoolean
private final AtomicBoolean
private Function
<SyncExecutionInternal<R>, ExecutionResult<R>> Fields inherited from class dev.failsafe.ExecutionImpl
attemptRecorded, cancelCallback, cancelledIndex, completed, policyExecutors, result
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
SyncExecutionImpl
(FailsafeExecutor<R> executor, Scheduler scheduler, CallImpl<R> call, Function<SyncExecutionInternal<R>, ExecutionResult<R>> innerFn) Create a sync execution for theexecutor
.private
SyncExecutionImpl
(SyncExecutionImpl<R> execution) Create a sync execution for a new attempt.(package private)
SyncExecutionImpl
(List<? extends Policy<R>> policies) Create a standalone sync execution for thepolicies
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
complete()
Records and completes the execution successfully.copy()
Returns a new copy of the SyncExecutionInternal if it is not standalone, else returnsthis
since standalone executions are referenced externally and cannot be replaced.(package private) R
Performs a synchronous execution.getDelay()
Returns the time to delay before the next execution attempt.void
Interrupts the execution.boolean
Returns whether the execution is complete or if it can be retried.boolean
Returns whether the execution is currently interrupted.private boolean
(package private) ExecutionResult
<R> postExecute
(ExecutionResult<R> result) Externally called.void
Called when execution of the user's supplier is about to begin.void
Records an executionresult
orexception
which triggers failure handling, if needed, by the configured policies.void
recordException
(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
setInterruptable
(boolean interruptable) Sets whether the execution is currentlyinterruptable
.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, 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, record, recordAttempt
-
Field Details
-
executor
-
call
-
outerFn
-
executionThread
-
interruptable
-
interrupted
-
delayNanos
private volatile long delayNanos
-
-
Constructor Details
-
SyncExecutionImpl
Create a standalone sync execution for thepolicies
. -
SyncExecutionImpl
SyncExecutionImpl(FailsafeExecutor<R> executor, Scheduler scheduler, CallImpl<R> call, Function<SyncExecutionInternal<R>, ExecutionResult<R>> innerFn) Create a sync execution for theexecutor
. -
SyncExecutionImpl
Create a sync execution for a new attempt.
-
-
Method Details
-
complete
public void complete()Description copied from interface:Execution
Records and completes the execution successfully. -
isComplete
public boolean isComplete()Description copied from interface:Execution
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 interfaceExecution<R>
-
getDelay
Description copied from interface:Execution
Returns the time to delay before the next execution attempt. Returns0
if an execution has not yet occurred. -
record
Description copied from interface:Execution
Records an executionresult
orexception
which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed. -
recordResult
Description copied from interface:Execution
Records an executionresult
which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed.- Specified by:
recordResult
in interfaceExecution<R>
-
recordException
Description copied from interface:Execution
Records anexception
which triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed.- Specified by:
recordException
in interfaceExecution<R>
-
preExecute
public void preExecute()Description copied from interface:ExecutionInternal
Called when execution of the user's supplier is about to begin.- Specified by:
preExecute
in interfaceExecutionInternal<R>
- Overrides:
preExecute
in classExecutionImpl<R>
-
postExecute
Description copied from class:ExecutionImpl
Externally called. Records an execution and performs post-execution handling for theresult
against all configured policy executors. Returns whether the result is complete for all policies.- Overrides:
postExecute
in classExecutionImpl<R>
-
isInterrupted
public boolean isInterrupted()Description copied from interface:SyncExecutionInternal
Returns whether the execution is currently interrupted.- Specified by:
isInterrupted
in interfaceSyncExecutionInternal<R>
-
setInterruptable
public void setInterruptable(boolean interruptable) Description copied from interface:SyncExecutionInternal
Sets whether the execution is currentlyinterruptable
.- Specified by:
setInterruptable
in interfaceSyncExecutionInternal<R>
-
interrupt
public void interrupt()Description copied from interface:SyncExecutionInternal
Interrupts the execution.- Specified by:
interrupt
in interfaceSyncExecutionInternal<R>
-
isStandalone
private boolean isStandalone() -
copy
Description copied from interface:SyncExecutionInternal
Returns a new copy of the SyncExecutionInternal if it is not standalone, else returnsthis
since standalone executions are referenced externally and cannot be replaced.- Specified by:
copy
in interfaceSyncExecutionInternal<R>
-
executeSync
R executeSync()Performs a synchronous execution.
-