T
- the type of the object to be eventually returned by the supplier
@API(status=INTERNAL)
public abstract class RetryWithRecovery<T>
extends java.lang.Object
Constructor and Description |
---|
RetryWithRecovery(SupplierWithApiException<T> supplier,
java.util.function.Predicate<java.lang.Exception> ignoreException,
java.util.List<RecoveryStrategy> recoveryStrategies,
java.lang.String address) |
Modifier and Type | Method and Description |
---|---|
abstract T |
execute()
Method called by client which should implement the retry.
|
static <T> T |
executeAndRetry(RetryWithRecoveryBuilder baseRetryBuilder,
java.lang.String name,
java.lang.String address,
SupplierWithApiException<T> supplier)
This is a helper function designed to cover most of the retry cases.
|
protected T |
executeOnce()
This implements the logic corresponding to one retry:
calls the
supplier , catches the potential Exception ,
return null if it satisfies ignoreException
and runs the recovery functions if it matches its corresponding condition. |
static java.lang.String |
networkIssueMessageError(java.lang.Throwable t,
java.lang.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.
|
public RetryWithRecovery(SupplierWithApiException<T> supplier, java.util.function.Predicate<java.lang.Exception> ignoreException, java.util.List<RecoveryStrategy> recoveryStrategies, java.lang.String address)
public static <T> T executeAndRetry(RetryWithRecoveryBuilder baseRetryBuilder, java.lang.String name, java.lang.String address, SupplierWithApiException<T> supplier)
RetryWithRecoveryBuilder.isNetworkOrMinorError(java.lang.Throwable)
and refreshes the authSession if we get an unauthorized error.T
- the type of the object to be returned by the supplier.baseRetryBuilder
- the RetryWithRecoveryBuilder
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.com.symphony.bdk.http.api.ApiRuntimeException
- if a non-handled ApiException
thrown or if the max number of retries has been reached.java.lang.RuntimeException
- if any other exception thrown.public abstract T execute() throws java.lang.Throwable
executeOnce()
which executes one actual call to the supplier, runs potential recovery
actions and potentially throws an exception.java.lang.Throwable
- in case the max number of retries exhausted
or if any other exception thrown by the supplier or the recovery functions.protected T executeOnce() throws java.lang.Throwable
supplier
, catches the potential Exception
,
return null if it satisfies ignoreException
and runs the recovery functions if it matches its corresponding condition.
This should be called by any implementation of execute()
.public static java.lang.String networkIssueMessageError(java.lang.Throwable t, java.lang.String address)
t
- exception foundaddress
- that the retry is trying to reach