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>callprivate longdelayNanosprivate java.lang.ThreadexecutionThreadprivate FailsafeExecutor<R>executorprivate java.util.concurrent.atomic.AtomicBooleaninterruptableprivate java.util.concurrent.atomic.AtomicBooleaninterruptedprivate 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.privateSyncExecutionImpl(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 voidcomplete()Records and completes the execution successfully.SyncExecutionImpl<R>copy()Returns a new copy of the SyncExecutionInternal if it is not standalone, else returnsthissince standalone executions are referenced externally and cannot be replaced.(package private) RexecuteSync()Performs a synchronous execution.java.time.DurationgetDelay()Returns the time to delay before the next execution attempt.voidinterrupt()Interrupts the execution.booleanisComplete()Returns whether the execution is complete or if it can be retried.booleanisInterrupted()Returns whether the execution is currently interrupted.private booleanisStandalone()(package private) ExecutionResult<R>postExecute(ExecutionResult<R> result)Externally called.voidpreExecute()Called when execution of the user's supplier is about to begin.voidrecord(R result, java.lang.Throwable exception)Records an executionresultorexceptionwhich triggers failure handling, if needed, by the configured policies.voidrecordException(java.lang.Throwable exception)Records anexceptionwhich triggers failure handling, if needed, by the configured policies.voidrecordResult(R result)Records an executionresultwhich triggers failure handling, if needed, by the configured policies.voidsetInterruptable(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:ExecutionRecords and completes the execution successfully.
-
isComplete
public boolean isComplete()
Description copied from interface:ExecutionReturns 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:
isCompletein interfaceExecution<R>
-
getDelay
public java.time.Duration getDelay()
Description copied from interface:ExecutionReturns the time to delay before the next execution attempt. Returns0if an execution has not yet occurred.
-
record
public void record(R result, java.lang.Throwable exception)
Description copied from interface:ExecutionRecords an executionresultorexceptionwhich 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:ExecutionRecords an executionresultwhich triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed.- Specified by:
recordResultin interfaceExecution<R>
-
recordException
public void recordException(java.lang.Throwable exception)
Description copied from interface:ExecutionRecords anexceptionwhich triggers failure handling, if needed, by the configured policies. If policy handling is not possible or completed, the execution is completed.- Specified by:
recordExceptionin interfaceExecution<R>
-
preExecute
public void preExecute()
Description copied from interface:ExecutionInternalCalled when execution of the user's supplier is about to begin.- Specified by:
preExecutein interfaceExecutionInternal<R>- Overrides:
preExecutein classExecutionImpl<R>
-
postExecute
ExecutionResult<R> postExecute(ExecutionResult<R> result)
Description copied from class:ExecutionImplExternally called. Records an execution and performs post-execution handling for theresultagainst all configured policy executors. Returns whether the result is complete for all policies.- Overrides:
postExecutein classExecutionImpl<R>
-
isInterrupted
public boolean isInterrupted()
Description copied from interface:SyncExecutionInternalReturns whether the execution is currently interrupted.- Specified by:
isInterruptedin interfaceSyncExecutionInternal<R>
-
setInterruptable
public void setInterruptable(boolean interruptable)
Description copied from interface:SyncExecutionInternalSets whether the execution is currentlyinterruptable.- Specified by:
setInterruptablein interfaceSyncExecutionInternal<R>
-
interrupt
public void interrupt()
Description copied from interface:SyncExecutionInternalInterrupts the execution.- Specified by:
interruptin interfaceSyncExecutionInternal<R>
-
isStandalone
private boolean isStandalone()
-
copy
public SyncExecutionImpl<R> copy()
Description copied from interface:SyncExecutionInternalReturns a new copy of the SyncExecutionInternal if it is not standalone, else returnsthissince standalone executions are referenced externally and cannot be replaced.- Specified by:
copyin interfaceSyncExecutionInternal<R>
-
executeSync
R executeSync()
Performs a synchronous execution.
-
-