Interface ResilienceDecorationStrategy
- All Known Implementing Classes:
NoResilienceDecorationStrategy
,Resilience4jDecorationStrategy
public interface ResilienceDecorationStrategy
Generic interface to decorate functions with non-functional requirements.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
clearAllCacheEntries
(ResilienceConfiguration configuration) Clears the entire cache associated with the givenResilienceConfiguration
if any exists, independent of the specifiedResilienceIsolationMode
and defined parameters.default void
clearCache
(ResilienceConfiguration configuration) Clears the cache associated with the givenResilienceConfiguration
if any exists.default void
clearCache
(ResilienceConfiguration configuration, CacheFilter filter) Clears the cache associated with the givenResilienceConfiguration
by respecting the providedCacheFilter
.default <T> Callable<T>
decorateCallable
(Callable<T> callable, ResilienceConfiguration configuration) Decorate an instance of a callable function.<T> Callable<T>
decorateCallable
(Callable<T> callable, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a callable function.default <T> Supplier<T>
decorateSupplier
(Supplier<T> supplier, ResilienceConfiguration configuration) Decorate an instance of a supplier function.<T> Supplier<T>
decorateSupplier
(Supplier<T> supplier, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a supplier function.default <T> T
executeCallable
(Callable<T> callable, ResilienceConfiguration configuration) Decorate and execute an instance of a callable function.default <T> T
executeCallable
(Callable<T> callable, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate and execute an instance of a callable function.default <T> T
executeSupplier
(Supplier<T> supplier, ResilienceConfiguration configuration) Decorate and execute an instance of a supplier function.default <T> T
executeSupplier
(Supplier<T> supplier, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate and execute an instance of a supplier function.default <T> CompletableFuture<T>
queueCallable
(Callable<T> callable, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a callable function.default <T> CompletableFuture<T>
queueSupplier
(Supplier<T> supplier, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a supplier function.
-
Method Details
-
clearCache
Clears the cache associated with the givenResilienceConfiguration
if any exists. This method respects tenant/principal isolation according to theResilienceIsolationMode
as well as parameter isolation.
To clear all cache entries for all tenants, principals, and parameters,clearAllCacheEntries(ResilienceConfiguration)
can be used instead.- Parameters:
configuration
- TheResilienceConfiguration
the cache is attached to.
-
clearCache
default void clearCache(@Nonnull ResilienceConfiguration configuration, @Nonnull CacheFilter filter) Clears the cache associated with the givenResilienceConfiguration
by respecting the providedCacheFilter
.- Parameters:
configuration
- TheResilienceConfiguration
the cache is attached to.filter
- ACacheFilter
to apply in order to select entries that should be cleared from the cache.
-
clearAllCacheEntries
Clears the entire cache associated with the givenResilienceConfiguration
if any exists, independent of the specifiedResilienceIsolationMode
and defined parameters. Be aware that this operation affects all tenants and principals.
UseclearCache(ResilienceConfiguration)
to respect the tenant/principal and parameter isolation.- Parameters:
configuration
- TheResilienceConfiguration
the cache is attached to.
-
decorateSupplier
@Nonnull default <T> Supplier<T> decorateSupplier(@Nonnull Supplier<T> supplier, @Nonnull ResilienceConfiguration configuration) Decorate an instance of a supplier function.- Type Parameters:
T
- The return type of the call.- Parameters:
supplier
- The supplier.configuration
- The configuration of the resilient call.- Returns:
- A decorated supplier.
-
executeSupplier
@Nullable default <T> T executeSupplier(@Nonnull Supplier<T> supplier, @Nonnull ResilienceConfiguration configuration) Decorate and execute an instance of a supplier function.- Type Parameters:
T
- The return type of the call.- Parameters:
supplier
- The supplier.configuration
- The configuration of the resilient call.- Returns:
- The value of the supplier.
-
decorateSupplier
@Nonnull <T> Supplier<T> decorateSupplier(@Nonnull Supplier<T> supplier, @Nonnull ResilienceConfiguration configuration, @Nullable Function<? super Throwable, T> fallbackFunction) Decorate an instance of a supplier function.- Type Parameters:
T
- The return type of the call.- Parameters:
supplier
- The supplier.configuration
- The configuration of the resilient call.fallbackFunction
- In case of failure, execute this function.- Returns:
- A decorated supplier.
-
executeSupplier
@Nullable default <T> T executeSupplier(@Nonnull Supplier<T> supplier, @Nonnull ResilienceConfiguration configuration, @Nullable Function<? super Throwable, T> fallbackFunction) Decorate and execute an instance of a supplier function.- Type Parameters:
T
- The return type of the call.- Parameters:
supplier
- The supplier.configuration
- The configuration of the resilient call.fallbackFunction
- In case of failure, execute this function.- Returns:
- The value of the supplier.
-
decorateCallable
@Nonnull default <T> Callable<T> decorateCallable(@Nonnull Callable<T> callable, @Nonnull ResilienceConfiguration configuration) Decorate an instance of a callable function.- Type Parameters:
T
- The return type of the call.- Parameters:
callable
- The callable.configuration
- The configuration of the resilient call.- Returns:
- A decorated callable.
-
executeCallable
@Nullable default <T> T executeCallable(@Nonnull Callable<T> callable, @Nonnull ResilienceConfiguration configuration) throws Exception Decorate and execute an instance of a callable function.- Type Parameters:
T
- The return type of the call.- Parameters:
callable
- The callable.configuration
- The configuration of the resilient call.- Returns:
- The value returned by the callable.
- Throws:
Exception
- Exception that can be thrown by the callable.
-
decorateCallable
@Nonnull <T> Callable<T> decorateCallable(@Nonnull Callable<T> callable, @Nonnull ResilienceConfiguration configuration, @Nullable Function<? super Throwable, T> fallbackFunction) Decorate an instance of a callable function.- Type Parameters:
T
- The return type of the call.- Parameters:
callable
- The callable.configuration
- The configuration of the resilient call.fallbackFunction
- In case of failure, execute this function.- Returns:
- A decorated callable.
-
executeCallable
@Nullable default <T> T executeCallable(@Nonnull Callable<T> callable, @Nonnull ResilienceConfiguration configuration, @Nullable Function<? super Throwable, T> fallbackFunction) Decorate and execute an instance of a callable function. This method assumes thatfallbackFunction
handles any exceptions thrown bycallable
, andfallbackFunction
does not throw any exceptions itself. IffallbackFunction
throws any exception, then it will be wrapped in aResilienceRuntimeException
.- Type Parameters:
T
- The return type of the call.- Parameters:
callable
- The callable.configuration
- The configuration of the resilient call.fallbackFunction
- (Optional) In case of failure, execute this function.- Returns:
- The value returned by the callable.
-
queueCallable
@Nonnull default <T> CompletableFuture<T> queueCallable(@Nonnull Callable<T> callable, @Nonnull ResilienceConfiguration configuration, @Nullable Function<? super Throwable, T> fallbackFunction) Decorate an instance of a callable function. Automatically schedule the asynchronous execution.- Type Parameters:
T
- The return type of the call.- Parameters:
callable
- The callable.configuration
- The configuration of the resilient call.fallbackFunction
- (Optional) In case of failure, execute this function.- Returns:
- An instance of Future being executed asynchronously with the static
ThreadContextExecutors
executor.
-
queueSupplier
@Nonnull default <T> CompletableFuture<T> queueSupplier(@Nonnull Supplier<T> supplier, @Nonnull ResilienceConfiguration configuration, @Nullable Function<? super Throwable, T> fallbackFunction) Decorate an instance of a supplier function. Automatically schedule the asynchronous execution.- Type Parameters:
T
- The return type of the call.- Parameters:
supplier
- The supplier.configuration
- The configuration of the resilient call.fallbackFunction
- (Optional) In case of failure, execute this function.- Returns:
- An instance of Future being executed asynchronously with the static
ThreadContextExecutors
executor.
-