Package com.symphony.bdk.core.retry
Class RetryWithRecoveryBuilder<T>
java.lang.Object
com.symphony.bdk.core.retry.RetryWithRecoveryBuilder<T>
- Type Parameters:
T
- the type to be returned byRetryWithRecovery.execute()
.
Builder class to facilitate the instantiation of a
RetryWithRecovery
.-
Constructor Summary
ConstructorDescriptionDefault constructor which ignores no exception and retries exceptions fulfillingisNetworkIssueOrMinorError(java.lang.Throwable)
. -
Method Summary
Modifier and TypeMethodDescriptionSets the address and returns the modified builder.build()
Builds aRetryWithRecovery
based on provided fields.Removes all the recovery strategies from the builder instance.static <T> RetryWithRecoveryBuilder<T>
static <T> RetryWithRecoveryBuilder<T>
from
(RetryWithRecoveryBuilder<?> from) Copies all fields of an existing builder except thesupplier
.ignoreException
(Predicate<com.symphony.bdk.http.api.ApiException> ignoreException) Sets the condition on which we should ignore anApiException
thrown by thesupplier
and return null inRetryWithRecovery.execute()
.static boolean
Checks if a throwable is a network issue or aApiException
minor error.static boolean
Checks if a throwable is a network issue or aApiException
minor error or client error.Sets the name and returns the modified builder.<E extends Exception>
RetryWithRecoveryBuilder<T>recoveryStrategy
(Class<? extends E> exceptionType, ConsumerWithThrowable recovery) Sets one recovery strategy which consists of a specificException
type and of a corresponding recovery function to be executed when exception is of the given provided type.recoveryStrategy
(Predicate<com.symphony.bdk.http.api.ApiException> condition, ConsumerWithThrowable recovery) Sets one recovery strategy which consists of a predicate on a thrownApiException
and of a corresponding recovery function to be executed when condition is met.retryConfig
(com.symphony.bdk.core.config.model.BdkRetryConfig retryConfig) Sets the retry configuration and returns the modified builder.retryOnException
(Predicate<Throwable> retryOnExceptionPredicate) Sets the conditions on which we should retry the call to the providedsupplier
.supplier
(SupplierWithApiException<T> supplier) Sets the retry configuration and returns the modified builder.
-
Constructor Details
-
RetryWithRecoveryBuilder
public RetryWithRecoveryBuilder()Default constructor which ignores no exception and retries exceptions fulfillingisNetworkIssueOrMinorError(java.lang.Throwable)
.
-
-
Method Details
-
from
Copies all fields of an existing builder except thesupplier
.- Type Parameters:
T
- the target parametrized type.- Parameters:
from
- theRetryWithRecovery
to be copied.- Returns:
- a copy of the builder passed as parameter.
-
copyWithoutRecoveryStrategies
public static <T> RetryWithRecoveryBuilder<T> copyWithoutRecoveryStrategies(RetryWithRecoveryBuilder<?> from) -
isNetworkIssueOrMinorError
Checks if a throwable is a network issue or aApiException
minor error.This is the default function used in
RetryWithRecovery
to check if a given exception thrown should lead to a retry or not.- Parameters:
t
- the throwable to be checked.- Returns:
- true if a given throwable is either a
SocketTimeoutException
, aSocketException
, aConnectException
, aUnknownHostException
or if it's amApiException
that verifiesApiException.isServerError()
,ApiException.isUnauthorized()
orApiException.isTooManyRequestsError()
.
-
isNetworkIssueOrMinorErrorOrClientError
Checks if a throwable is a network issue or aApiException
minor error or client error.- Parameters:
t
- the throwable to be checked.- Returns:
- true if passed throwable verifies
isNetworkIssueOrMinorError(java.lang.Throwable)
and alsoApiException.isClientError()
-
name
Sets the name and returns the modified builder.- Parameters:
name
- the name of theRetryWithRecovery
- Returns:
- the modified builder instance.
-
retryConfig
public RetryWithRecoveryBuilder<T> retryConfig(com.symphony.bdk.core.config.model.BdkRetryConfig retryConfig) Sets the retry configuration and returns the modified builder.- Parameters:
retryConfig
- the retry configuration to be used.- Returns:
- the modified builder instance.
-
basePath
Sets the address and returns the modified builder.- Parameters:
address
- that we are trying to reach.- Returns:
- the modified builder instance.
-
supplier
Sets the retry configuration and returns the modified builder.- Parameters:
supplier
- the function to be called by theRetryWithRecovery
which returns the desired object and which may fail.- Returns:
- the modified builder instance.
-
retryOnException
Sets the conditions on which we should retry the call to the providedsupplier
.- Parameters:
retryOnExceptionPredicate
- the condition when we should retry the call when thesupplier
throws an exception.- Returns:
- the modified builder instance.
-
ignoreException
public RetryWithRecoveryBuilder<T> ignoreException(Predicate<com.symphony.bdk.http.api.ApiException> ignoreException) Sets the condition on which we should ignore anApiException
thrown by thesupplier
and return null inRetryWithRecovery.execute()
.- Parameters:
ignoreException
- the condition when we should ignore a given exception- Returns:
- the modified builder instance.
-
recoveryStrategy
public RetryWithRecoveryBuilder<T> recoveryStrategy(Predicate<com.symphony.bdk.http.api.ApiException> condition, ConsumerWithThrowable recovery) Sets one recovery strategy which consists of a predicate on a thrownApiException
and of a corresponding recovery function to be executed when condition is met.- Parameters:
condition
- the predicate to check if the exception should lead to the execution of the recovery function.recovery
- the recovery function to be executed when condition is fulfilled.- Returns:
- the modified builder instance.
-
recoveryStrategy
public <E extends Exception> RetryWithRecoveryBuilder<T> recoveryStrategy(Class<? extends E> exceptionType, ConsumerWithThrowable recovery) Sets one recovery strategy which consists of a specificException
type and of a corresponding recovery function to be executed when exception is of the given provided type.- Type Parameters:
E
- the actual exception class- Parameters:
exceptionType
- the actual exception classrecovery
- the recovery function to be executed when condition is fulfilled.- Returns:
- the modified builder instance.
-
clearRecoveryStrategies
Removes all the recovery strategies from the builder instance.- Returns:
- the modified builder instance.
-
build
Builds aRetryWithRecovery
based on provided fields.- Returns:
- a new instance of
RetryWithRecovery
based on the provided fields.
-