com.baidubce.http
Class DefaultRetryPolicy

java.lang.Object
  extended by com.baidubce.http.DefaultRetryPolicy
All Implemented Interfaces:
RetryPolicy

public class DefaultRetryPolicy
extends Object
implements RetryPolicy

Retry policy that can be configured on a specific service client using BceClientConfiguration. This class is immutable, therefore safe to be shared by multiple clients.

See Also:
BceClientConfiguration

Field Summary
 
Fields inherited from interface com.baidubce.http.RetryPolicy
DEFAULT_MAX_DELAY_IN_MILLIS, DEFAULT_MAX_ERROR_RETRY, DEFAULT_RETRY_POLICY
 
Constructor Summary
DefaultRetryPolicy()
          Constructs a new DefaultRetryPolicy.
DefaultRetryPolicy(int maxErrorRetry, long maxDelayInMillis)
          Constructs a new retry policy.
 
Method Summary
 long getDelayBeforeNextRetryInMillis(BceClientException exception, int retriesAttempted)
          Returns the delay (in milliseconds) before next retry attempt.
 long getMaxDelayInMillis()
          Returns the maximum delay time (in milliseconds) before retrying a request.
 int getMaxErrorRetry()
          Returns the maximum number of retry attempts.
protected  boolean shouldRetry(BceClientException exception, int retriesAttempted)
          Returns whether a failed request should be retried according to the given request context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultRetryPolicy

public DefaultRetryPolicy()
Constructs a new DefaultRetryPolicy.


DefaultRetryPolicy

public DefaultRetryPolicy(int maxErrorRetry,
                          long maxDelayInMillis)
Constructs a new retry policy.

Parameters:
maxErrorRetry - Maximum number of retry attempts for failed requests.
maxDelayInMillis - Maximum delay time (in milliseconds) before next retry attempt.
See Also:
BceClientConfiguration
Method Detail

getMaxErrorRetry

public int getMaxErrorRetry()
Returns the maximum number of retry attempts.

Specified by:
getMaxErrorRetry in interface RetryPolicy
Returns:
The maximum number of retry attempts.

getMaxDelayInMillis

public long getMaxDelayInMillis()
Returns the maximum delay time (in milliseconds) before retrying a request.

Specified by:
getMaxDelayInMillis in interface RetryPolicy
Returns:
the maximum delay time (in milliseconds) before retrying a request.

getDelayBeforeNextRetryInMillis

public long getDelayBeforeNextRetryInMillis(BceClientException exception,
                                            int retriesAttempted)
Returns the delay (in milliseconds) before next retry attempt. A negative value indicates that no more retries should be made.

Specified by:
getDelayBeforeNextRetryInMillis in interface RetryPolicy
Parameters:
exception - the exception from the failed request, represented as an BceClientException object.
retriesAttempted - the number of times the current request has been attempted (not including the next attempt after the delay).
Returns:
the delay (in milliseconds) before next retry attempt.A negative value indicates that no more retries should be made.

shouldRetry

protected boolean shouldRetry(BceClientException exception,
                              int retriesAttempted)
Returns whether a failed request should be retried according to the given request context. In the following circumstances, the request will fail directly without consulting this method:

Parameters:
exception - the exception from the failed request, represented as a BceClientException object.
retriesAttempted - the number of times the current request has been attempted.
Returns:
true if the failed request should be retried.


Copyright © 2018. All rights reserved.