Package com.backblaze.b2.client
Class B2DefaultRetryPolicy
- java.lang.Object
-
- com.backblaze.b2.client.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 Summary
Constructors Constructor Description B2DefaultRetryPolicy()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Integer
gotRetryableAfterDelay(java.lang.String operation, int attemptsSoFar, long tookMillis, B2Exception e)
Callable.call() threw a retryable B2Exception but we have to wait a while before retrying.boolean
gotRetryableImmediately(java.lang.String operation, int attemptsSoFar, long tookMillis, B2Exception e)
Callable.call() threw a retryable B2Exception.static java.util.function.Supplier<B2RetryPolicy>
supplier()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.backblaze.b2.client.B2RetryPolicy
gotUnexpectedUnretryable, gotUnretryable, succeeded
-
-
-
-
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 interfaceB2RetryPolicy
- 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 interfaceB2RetryPolicy
- 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.
-
-