Package com.symphony.bdk.core.retry
Class RetryWithRecovery<T>
java.lang.Object
com.symphony.bdk.core.retry.RetryWithRecovery<T>
- Type Parameters:
T
- the type of the object to be eventually returned by thesupplier
- Direct Known Subclasses:
Resilience4jRetryWithRecovery
Abstract class to implement a retry mechanism with recovery strategies,
e.g. refresh a session in a case of session expiration.
-
Constructor Summary
ConstructorDescriptionRetryWithRecovery
(SupplierWithApiException<T> supplier, Predicate<Exception> ignoreException, List<RecoveryStrategy> recoveryStrategies, String address) -
Method Summary
Modifier and TypeMethodDescriptionabstract T
execute()
Method called by client which should implement the retry.static <T> T
executeAndRetry
(RetryWithRecoveryBuilder<?> baseRetryBuilder, String name, String address, SupplierWithApiException<T> supplier) This is a helper function designed to cover most of the retry cases.protected T
This implements the logic corresponding to one retry: calls thesupplier
, catches the potentialException
, return null if it satisfiesignoreException
and runs the recovery functions if it matches its corresponding condition.static String
networkIssueMessageError
(Throwable t, String address) This methods check the type of exception thrown in the retry and depending on that it created a clear error message suggesting the possible cause of the issue.
-
Constructor Details
-
RetryWithRecovery
public RetryWithRecovery(SupplierWithApiException<T> supplier, Predicate<Exception> ignoreException, List<RecoveryStrategy> recoveryStrategies, String address)
-
-
Method Details
-
executeAndRetry
public static <T> T executeAndRetry(RetryWithRecoveryBuilder<?> baseRetryBuilder, String name, String address, SupplierWithApiException<T> supplier) This is a helper function designed to cover most of the retry cases. It retries on the conditions defined byRetryWithRecoveryBuilder.isNetworkIssueOrMinorError(java.lang.Throwable)
and refreshes the authSession if we get an unauthorized error.- Type Parameters:
T
- the type of the object to be returned by the supplier.- Parameters:
baseRetryBuilder
- theRetryWithRecoveryBuilder
containing the base settings for the retry mechanism.name
- the name of the retry, can be any string but should specific to the function being retried.supplier
- the supplier returning the desired object which may fail with an exception.- Returns:
- the object returned by the supplier
- Throws:
com.symphony.bdk.http.api.ApiRuntimeException
- if a non-handledApiException
thrown or if the max number of retries has been reached.RuntimeException
- if any other exception thrown.
-
execute
Method called by client which should implement the retry. This should callexecuteOnce()
which executes one actual call to the supplier, runs potential recovery actions and potentially throws an exception.- Returns:
- the object returned by the supplier.
- Throws:
Throwable
- in case the max number of retries exhausted or if any other exception thrown by the supplier or the recovery functions.
-
executeOnce
This implements the logic corresponding to one retry: calls thesupplier
, catches the potentialException
, return null if it satisfiesignoreException
and runs the recovery functions if it matches its corresponding condition. This should be called by any implementation ofexecute()
.- Returns:
- the object returned by the
supplier
. - Throws:
Throwable
- in case an exception has been thrown by thesupplier
or by the recovery functions.
-
networkIssueMessageError
This methods check the type of exception thrown in the retry and depending on that it created a clear error message suggesting the possible cause of the issue.- Parameters:
t
- exception foundaddress
- that the retry is trying to reach- Returns:
- error message
-