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>
final class SyncExecutionImpl<R> extends ExecutionImpl<R> implements SyncExecutionInternal<R>
SyncExecution and SyncExecutionInternal implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private CallImpl<R>
call
private long
delayNanos
private java.lang.Thread
executionThread
private FailsafeExecutor<R>
executor
private java.util.concurrent.atomic.AtomicBoolean
interruptable
private java.util.concurrent.atomic.AtomicBoolean
interrupted
private java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>>
outerFn
-
Fields inherited from class dev.failsafe.ExecutionImpl
attemptRecorded, cancelCallback, cancelledIndex, completed, policyExecutors, result
-
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
SyncExecutionImpl(FailsafeExecutor<R> executor, Scheduler scheduler, CallImpl<R> call, java.util.function.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(java.util.List<? extends Policy<R>> policies)
Create a standalone sync execution for thepolicies
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
complete()
Records and completes the execution successfully.SyncExecutionImpl<R>
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
executeSync()
Performs a synchronous execution.java.time.Duration
getDelay()
Returns the time to delay before the next execution attempt.void
interrupt()
Interrupts the execution.boolean
isComplete()
Returns whether the execution is complete or if it can be retried.boolean
isInterrupted()
Returns whether the execution is currently interrupted.private boolean
isStandalone()
(package private) ExecutionResult<R>
postExecute(ExecutionResult<R> result)
Externally called.void
preExecute()
Called when execution of the user's supplier is about to begin.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
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 Detail
-
executor
private final FailsafeExecutor<R> executor
-
outerFn
private java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>> outerFn
-
executionThread
private final java.lang.Thread executionThread
-
interruptable
private final java.util.concurrent.atomic.AtomicBoolean interruptable
-
interrupted
private final java.util.concurrent.atomic.AtomicBoolean interrupted
-
delayNanos
private volatile long delayNanos
-
-
Constructor Detail
-
SyncExecutionImpl
SyncExecutionImpl(java.util.List<? extends Policy<R>> policies)
Create a standalone sync execution for thepolicies
.
-
SyncExecutionImpl
SyncExecutionImpl(FailsafeExecutor<R> executor, Scheduler scheduler, CallImpl<R> call, java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>> innerFn)
Create a sync execution for theexecutor
.
-
SyncExecutionImpl
private SyncExecutionImpl(SyncExecutionImpl<R> execution)
Create a sync execution for a new attempt.
-
-
Method Detail
-
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
public java.time.Duration 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
public void record(R result, java.lang.Throwable exception)
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
public void recordResult(R result)
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
public void recordException(java.lang.Throwable exception)
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
ExecutionResult<R> postExecute(ExecutionResult<R> result)
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
public SyncExecutionImpl<R> 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.
-
-