Class B2DefaultRetryPolicy

  • All Implemented Interfaces:
    B2RetryPolicy

    public class B2DefaultRetryPolicy
    extends java.lang.Object
    implements B2RetryPolicy
    B2DefaultRetryPolicy implements the retry policy described in the B2 documentation. It should be reasonable and sufficient for almost every use of B2. Each attempted operation should have a unique instance of this class because it stores state about retries between calls. Use an instance of Supplier<B2RetryPolicy> which provides a new instance on each call.
    • Constructor Detail

      • B2DefaultRetryPolicy

        public B2DefaultRetryPolicy()
    • Method Detail

      • supplier

        public static java.util.function.Supplier<B2RetryPolicy> supplier()
        Returns:
        a supplier to create new instances of this class.
      • gotRetryableAfterDelay

        public java.lang.Integer gotRetryableAfterDelay​(java.lang.String operation,
                                                        int attemptsSoFar,
                                                        long tookMillis,
                                                        B2Exception e)
        Description copied from interface: B2RetryPolicy
        Callable.call() threw a retryable B2Exception but we have to wait a while before retrying. If the guide decides we've tried enough times, it should return null. Otherwise, it should return the number of seconds to sleep before trying again.

        if e.getRetryAfterSecondsOrNull() is not null, it's the number of seconds the server suggests that you wait before trying again.

        WARNING: if we only hit retryable errors and this never returns null, we will keep retrying indefinitely. You have been warned.

        Specified by:
        gotRetryableAfterDelay in interface B2RetryPolicy
        Parameters:
        operation - the name of what is being retried. *usually* the name of a b2 operation.
        attemptsSoFar - how many times have we called callable.call() so far?
        tookMillis - how long did this attempt take?
        e - the retryable exception.
        Returns:
        null to stop trying OR the number of seconds to sleep before trying again.
      • gotRetryableImmediately

        public boolean gotRetryableImmediately​(java.lang.String operation,
                                               int attemptsSoFar,
                                               long tookMillis,
                                               B2Exception e)
        Description copied from interface: B2RetryPolicy
        Callable.call() threw a retryable B2Exception. We will retry immediately.
        Specified by:
        gotRetryableImmediately in interface B2RetryPolicy
        Parameters:
        operation - the name of what is being retried. *usually* the name of a b2 operation.
        attemptsSoFar - how many times have we called callable.call() so far?
        tookMillis - how long did this attempt take?
        e - the retryable exception.
        Returns:
        true iff we should try again.