Class RetryWithRecoveryBuilder<T>

java.lang.Object
com.symphony.bdk.core.retry.RetryWithRecoveryBuilder<T>
Type Parameters:
T - the type to be returned by RetryWithRecovery.execute().

@API(status=INTERNAL) public class RetryWithRecoveryBuilder<T> extends Object
Builder class to facilitate the instantiation of a RetryWithRecovery.
  • Constructor Details

  • Method Details

    • from

      public static <T> RetryWithRecoveryBuilder<T> from(RetryWithRecoveryBuilder<?> from)
      Copies all fields of an existing builder except the supplier.
      Type Parameters:
      T - the target parametrized type.
      Parameters:
      from - the RetryWithRecovery to be copied.
      Returns:
      a copy of the builder passed as parameter.
    • copyWithoutRecoveryStrategies

      public static <T> RetryWithRecoveryBuilder<T> copyWithoutRecoveryStrategies(RetryWithRecoveryBuilder<?> from)
    • isNetworkIssueOrMinorError

      public static boolean isNetworkIssueOrMinorError(Throwable t)
      Checks if a throwable is a network issue or a ApiException 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, a SocketException, a ConnectException, a UnknownHostException or if it's am ApiException that verifies ApiException.isServerError(), ApiException.isUnauthorized() or ApiException.isTooManyRequestsError().
    • isNetworkIssueOrMinorErrorOrClientError

      public static boolean isNetworkIssueOrMinorErrorOrClientError(Throwable t)
      Checks if a throwable is a network issue or a ApiException minor error or client error.
      Parameters:
      t - the throwable to be checked.
      Returns:
      true if passed throwable verifies isNetworkIssueOrMinorError(java.lang.Throwable) and also ApiException.isClientError()
    • name

      public RetryWithRecoveryBuilder<T> name(String name)
      Sets the name and returns the modified builder.
      Parameters:
      name - the name of the RetryWithRecovery
      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

      public RetryWithRecoveryBuilder<T> basePath(String address)
      Sets the address and returns the modified builder.
      Parameters:
      address - that we are trying to reach.
      Returns:
      the modified builder instance.
    • supplier

      public RetryWithRecoveryBuilder<T> supplier(SupplierWithApiException<T> supplier)
      Sets the retry configuration and returns the modified builder.
      Parameters:
      supplier - the function to be called by the RetryWithRecovery which returns the desired object and which may fail.
      Returns:
      the modified builder instance.
    • retryOnException

      public RetryWithRecoveryBuilder<T> retryOnException(Predicate<Throwable> retryOnExceptionPredicate)
      Sets the conditions on which we should retry the call to the provided supplier.
      Parameters:
      retryOnExceptionPredicate - the condition when we should retry the call when the supplier 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 an ApiException thrown by the supplier and return null in RetryWithRecovery.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 thrown ApiException 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 specific Exception 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 class
      recovery - the recovery function to be executed when condition is fulfilled.
      Returns:
      the modified builder instance.
    • clearRecoveryStrategies

      public RetryWithRecoveryBuilder<T> clearRecoveryStrategies()
      Removes all the recovery strategies from the builder instance.
      Returns:
      the modified builder instance.
    • build

      public RetryWithRecovery<T> build()
      Builds a RetryWithRecovery based on provided fields.
      Returns:
      a new instance of RetryWithRecovery based on the provided fields.