failsafe v3.0 Release Notes
-
API Changes
๐ This release introduces some breaking changes to the API:
General
- โก๏ธ The maven group id for Failsafe has changed to
dev.failsafe
. Be sure to update your build config. - โก๏ธ All files have been moved to the
dev.failsafe
package. Be sure to update your imports.
Policies
- ๐ All policies now use a builder API. Using the builder API mostly requires inserting
builder()
andbuild()
methods into the call chain for constructing a policy since the actualwith
configuration methods are mostly the same as in 2.x policies, with a few changes described below. Some notes:- A policy builder can be created via
builder()
, ex:RetryPolicy.builder()
. RetryPolicy
andCircuitBreaker
can also be constructed with default values usingofDefaults()
.Fallback
andTimeout
offer additional factory methods for creating a a policy with only their required arguments, without using a builder, ex:Timeout.of(Duration.ofSeconds(10))
. Optional arguments must be specified through a builder, ex:Timeout.builder(duration).withInterrupt().build()
.- Policy configuration is now accessible via a
policy.getConfig()
.
- A policy builder can be created via
RetryPolicy and CircuitBreaker
- In
RetryPolicyBuilder
andCircuitBreakerBuilder
:withDelay
has been renamed towithDelayFn
.withDelayOn
has been renamed towithDelayFnOn
.withDelayWhen
has been renamed towithDelayFnWhen
.- The above method signatures have also been changed to accept a
ContextualSupplier
instead of aDelayFunction
, since it provides access to the same information.
CircuitBreaker
onOpen
,onClose
, andonHalfOpen
methods now accept aCircuitBreakerStateChangedEvent
argument.- ๐
allowsExecution()
was removed in favor ofacquirePermit()
andtryAcquirePermit()
, which are meant for standalone CircuitBreaker usage.
Fallback
- ๐ The
Fallback
async factory methods have been removed in favor of aFallbackBuilder.withAsync()
option.
โฑ Timeout
- โฑ
Timeout.withInterrupt(boolean)
is nowTimeoutBuilder.withInterrupt()
.
Execution and AsyncExecution
- The standalone
Execution
API, and theAsyncExecution
API created via theFailsafeExecutor.runAsyncExecution
andgetAsyncExecution
methods, have been unified to include:record(R, Throwable)
recordResult(R)
recordException(Throwable)
complete()
- ๐ The previously supported
Execution
andAsyncExecution
methods for recording a result have been removed. The methods for performing a retry have also been removed. ForExecution
,isComplete
will indicate whether the execution is complete else if retries can be performed. ForAsyncExecution
retries will automatically be performed, if possible, immediately after a result or failure is recorded. - The
Execution
constructor is no longer visible.Execution
instances must now be constructed viaExecution.of(policies)
. Execution.getWaitTime()
was renamed togetDelay()
.
Failsafe class
- ๐
Failsafe.with(P[] policies)
was removed in favor ofFailsafe.with(P, P...)
. This should only affect users who were explicitly passing an array toFailsafe.with
.
SPI Changes
โฑ The following changes effect the SPI classes, for users who are extending Failsafe with custom schedulers or policies:
- โฑ
Scheduler
andDefauledScheduledFuture
were moved to thespi
package. - ๐ฆ
Policy
andPolicyExecutor
were moved to thespi
package and some method signatures changed. - ๐ฆ
ExecutionResult
was moved to thespi
package and made generic. - ๐ฆ Several new classes were added to the
spi
package to contain internal execution APIs includingExecutionInternal
,SyncExecutionInternal
, andAsyncExecutionInternal
. - ๐ฆ
FailsafeFuture
was moved to the SPI package and some method signatures changed.
๐ Bug Fixes
- ๐ Improved the reliability of async executions, cancellations, and Timeouts.
๐ Improvements
- ๐ Issue #47 - All policies and policy config classes are now threadsafe. Policy builders are not threadsafe.
- ๐ Issue #201 - Thread safety is clearly documented in policy, policy config, and policy builder classes.
- Issue #292 - Created an extensible Policy SPI.
- Issue #254 - Added an explicit
compose
method toFailsafeExecutor
. - Issue #293 - Added
RetryPolicyBuilder.withBackoff(Duration, Duration)
and.withDelay(Duration, Duration)
. - โฑ Issue #221 -
Executor
instances configured viaFailsafeExecutor.with(Executor)
are now used on all executions, including sync executions, and can be used in conjunction with a separately configuredExecutorService
orScheduler
for async executions. - โ Added
FailsafeExecutor.getPolicies()
. - โ Added
isFirstAttempt()
andisRetry()
toExecutionAttempt
, which is available via a few event listeners.
- โก๏ธ The maven group id for Failsafe has changed to