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 the supplier
Direct Known Subclasses:
Resilience4jRetryWithRecovery

@API(status=INTERNAL) public abstract class RetryWithRecovery<T> extends Object
Abstract class to implement a retry mechanism with recovery strategies, e.g. refresh a session in a case of session expiration.
  • Constructor Details

  • 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 by RetryWithRecoveryBuilder.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 - 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.
      Returns:
      the object returned by the supplier
      Throws:
      com.symphony.bdk.http.api.ApiRuntimeException - if a non-handled ApiException thrown or if the max number of retries has been reached.
      RuntimeException - if any other exception thrown.
    • execute

      public abstract T execute() throws Throwable
      Method called by client which should implement the retry. This should call executeOnce() 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

      protected T executeOnce() throws Throwable
      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. This should be called by any implementation of execute().
      Returns:
      the object returned by the supplier.
      Throws:
      Throwable - in case an exception has been thrown by the supplier or by the recovery functions.
    • networkIssueMessageError

      public 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.
      Parameters:
      t - exception found
      address - that the retry is trying to reach
      Returns:
      error message