Class StandardRetryPolicy
The default implementation of the standard retry policy.
public class StandardRetryPolicy : RetryPolicy
- Inheritance
-
StandardRetryPolicy
- Derived
- Inherited Members
Constructors
StandardRetryPolicy(IClientConfig)
Constructor for StandardRetryPolicy.
public StandardRetryPolicy(IClientConfig config)
Parameters
config
IClientConfigThe Client config object. This is used to retrieve the maximum number of retries before throwing back a exception(This does not count the initial request) and the service URL for the request.
StandardRetryPolicy(int)
Constructor for StandardRetryPolicy.
public StandardRetryPolicy(int maxRetries)
Parameters
maxRetries
intThe maximum number of retries before throwing back a exception. This does not count the initial request.
Properties
CapacityManagerInstance
protected static CapacityManager CapacityManagerInstance { get; set; }
Property Value
MaxBackoffInMilliseconds
The maximum value of exponential backoff in milliseconds, which will be used to wait before retrying a request. The default is 20000 milliseconds.
public int MaxBackoffInMilliseconds { get; set; }
Property Value
Methods
CalculateRetryDelay(int, int)
protected static int CalculateRetryDelay(int retries, int maxBackoffInMilliseconds)
Parameters
Returns
CanRetry(IExecutionContext)
Returns true if the request is in a state where it can be retried, else false.
public override bool CanRetry(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextRequest context containing the state of the request.
Returns
- bool
Returns true if the request is in a state where it can be retried, else false.
NotifySuccess(IExecutionContext)
Virtual method that gets called on a success Response. If its a retry success response, the entire retry acquired capacity is released(default is 5). If its just a success response a lesser value capacity is released(default is 1).
public override void NotifySuccess(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextRequest context containing the state of the request.
OnRetry(IExecutionContext)
Virtual method that gets called when a retry request is initiated. If retry throttling is enabled, the value returned is true if the required capacity is retured, false otherwise. If retry throttling is disabled, true is returned.
public override bool OnRetry(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
Returns
OnRetry(IExecutionContext, bool)
Virtual method that gets called when a retry request is initiated. If retry throttling is enabled, the value returned is true if the required capacity is retured, false otherwise. If retry throttling is disabled, true is returned.
public override bool OnRetry(IExecutionContext executionContext, bool bypassAcquireCapacity)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
bypassAcquireCapacity
booltrue to bypass any attempt to acquire capacity on a retry
Returns
OnRetry(IExecutionContext, bool, bool)
Virtual method that gets called when a retry request is initiated. If retry throttling is enabled, the value returned is true if the required capacity is retured, false otherwise. If retry throttling is disabled, true is returned.
public override bool OnRetry(IExecutionContext executionContext, bool bypassAcquireCapacity, bool isThrottlingError)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
bypassAcquireCapacity
booltrue to bypass any attempt to acquire capacity on a retry
isThrottlingError
booltrue if the error that will be retried is a throtting error
Returns
RetryForException(IExecutionContext, Exception)
Return true if the request should be retried.
public override bool RetryForException(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextRequest context containing the state of the request.
exception
ExceptionThe exception thrown by the previous request.
Returns
- bool
Return true if the request should be retried.
RetryForExceptionAsync(IExecutionContext, Exception)
Return true if the request should be retried.
public override Task<bool> RetryForExceptionAsync(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextRequest context containing the state of the request.
exception
ExceptionThe exception thrown by the previous request.
Returns
RetryForExceptionSync(Exception)
Perform the processor-bound portion of the RetryForException logic. This is shared by the sync, async, and APM versions of the RetryForException method.
protected bool RetryForExceptionSync(Exception exception)
Parameters
exception
ExceptionThe exception thrown by the previous request.
Returns
- bool
Return true if the request should be retried.
RetryForExceptionSync(Exception, IExecutionContext)
Perform the processor-bound portion of the RetryForException logic. This is shared by the sync, async, and APM versions of the RetryForException method.
protected bool RetryForExceptionSync(Exception exception, IExecutionContext executionContext)
Parameters
exception
ExceptionThe exception thrown by the previous request.
executionContext
IExecutionContextRequest context containing the state of the request.
Returns
- bool
Return true if the request should be retried.
RetryLimitReached(IExecutionContext)
Checks if the retry limit is reached.
public override bool RetryLimitReached(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextRequest context containing the state of the request.
Returns
- bool
Return false if the request can be retried, based on number of retries.
WaitBeforeRetry(IExecutionContext)
Waits before retrying a request. The default policy implements a exponential backoff with jitter algorithm.
public override void WaitBeforeRetry(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextRequest context containing the state of the request.
WaitBeforeRetry(int, int)
Waits for an amount of time using an exponential backoff with jitter algorithm.
public static void WaitBeforeRetry(int retries, int maxBackoffInMilliseconds)
Parameters
retries
intThe request retry index. The first request is expected to be 0 while the first retry will be 1.
maxBackoffInMilliseconds
intThe max number of milliseconds to wait
WaitBeforeRetryAsync(IExecutionContext)
Waits before retrying a request.
public override Task WaitBeforeRetryAsync(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.