Class ResilienceDecorator
java.lang.Object
com.sap.cloud.sdk.cloudplatform.resilience.ResilienceDecorator
Accessor class for decorating functions with resilient properties.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearAllCacheEntries(ResilienceConfiguration configuration) Clears the entire cache associated with the givenResilienceConfigurationif any exists, independent of the specifiedResilienceIsolationModeand defined parameters.static voidclearCache(ResilienceConfiguration configuration) Clears the cache associated with the givenResilienceConfigurationif any exists.static voidclearCache(ResilienceConfiguration configuration, CacheFilter filter) Clears the cache associated with the givenResilienceConfigurationif any exists.static <T> Callable<T>decorateCallable(Callable<T> callable, ResilienceConfiguration configuration) Decorate an instance of a callable function.static <T> Callable<T>decorateCallable(Callable<T> callable, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a callable function.static <T> Supplier<T>decorateSupplier(Supplier<T> supplier, ResilienceConfiguration configuration) Decorate an instance of a supplier function.static <T> Supplier<T>decorateSupplier(Supplier<T> supplier, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a supplier function.static <T> TexecuteCallable(Callable<T> callable, ResilienceConfiguration configuration) Decorate and execute an instance of a callable function.static <T> TexecuteCallable(Callable<T> callable, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate and execute an instance of a callable function.static <T> TexecuteSupplier(Supplier<T> supplier, ResilienceConfiguration configuration) Decorate and execute an instance of a supplier function.static <T> TexecuteSupplier(Supplier<T> supplier, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate and execute an instance of a supplier function.static ResilienceDecorationStrategyThe current instance ofResilienceDecorationStrategyto be used to guarantee resilient function properties.static <T> CompletableFuture<T>queueCallable(Callable<T> callable, ResilienceConfiguration configuration) Decorate an instance of a callable function.static <T> CompletableFuture<T>queueCallable(Callable<T> callable, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a callable function.static <T> CompletableFuture<T>queueSupplier(Supplier<T> supplier, ResilienceConfiguration configuration) Decorate an instance of a supplier function.static <T> CompletableFuture<T>queueSupplier(Supplier<T> supplier, ResilienceConfiguration configuration, Function<? super Throwable, T> fallbackFunction) Decorate an instance of a supplier function.static voidResets the decoration strategy to its default.static voidsetDecorationStrategy(ResilienceDecorationStrategy decorationStrategy) The current instance ofResilienceDecorationStrategyto be used to guarantee resilient function properties.
-
Constructor Details
-
ResilienceDecorator
public ResilienceDecorator()
-
-
Method Details
-
resetDecorationStrategy
public static void resetDecorationStrategy()Resets the decoration strategy to its default. -
clearCache
Clears the cache associated with the givenResilienceConfigurationif any exists. This method respects tenant/principal isolation according to theResilienceIsolationModeas well as parameter isolation.
To clear all cache entries for all tenants, principals, and parameters, useclearAllCacheEntries(ResilienceConfiguration)instead.- Parameters:
configuration- TheResilienceConfigurationthe cache is attached to.
-
clearCache
public static void clearCache(@Nonnull ResilienceConfiguration configuration, @Nonnull CacheFilter filter) Clears the cache associated with the givenResilienceConfigurationif any exists. Cache entries to clear are determined by applying the givenfilter. Each cache entry for which the cache filter matches, gets cleared from the cache.- Parameters:
configuration- TheResilienceConfigurationthe cache is attached to.filter- ACacheFilterto apply in order to select entries that should be cleared from the cache.
-
clearAllCacheEntries
Clears the entire cache associated with the givenResilienceConfigurationif any exists, independent of the specifiedResilienceIsolationModeand defined parameters. Be aware that this operation affects all tenants and principals.
UseclearCache(ResilienceConfiguration)to respect the tenant/principal and parameter isolation.- Parameters:
configuration- TheResilienceConfigurationthe cache is attached to.
-
decorateSupplier
@Nonnull public static <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 public static <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 public static <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 public static <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 public static <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 public static <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 public static <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 public static <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.- 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 public static <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.
-
queueCallable
@Nonnull public static <T> CompletableFuture<T> queueCallable(@Nonnull Callable<T> callable, @Nonnull ResilienceConfiguration configuration) 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.- Returns:
- An instance of Future being executed asynchronously.
-
queueSupplier
@Nonnull public static <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.
-
queueSupplier
@Nonnull public static <T> CompletableFuture<T> queueSupplier(@Nonnull Supplier<T> supplier, @Nonnull ResilienceConfiguration configuration) 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.- Returns:
- An instance of Future being executed asynchronously.
-
getDecorationStrategy
The current instance ofResilienceDecorationStrategyto be used to guarantee resilient function properties. -
setDecorationStrategy
The current instance ofResilienceDecorationStrategyto be used to guarantee resilient function properties.
-