/// <summary> /// 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). /// </summary> /// <param name="executionContext">Request context containing the state of the request.</param> public override void NotifySuccess(IExecutionContext executionContext) { if (executionContext.RequestContext.ClientConfig.ThrottleRetries && RetryCapacity != null) { var requestContext = executionContext.RequestContext; CapacityManagerInstance.ReleaseCapacity(requestContext.LastCapacityType, RetryCapacity); } }
/// <summary> /// Constructor for StandardRetryPolicy. /// </summary> /// <param name="config">The 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.</param> public StandardRetryPolicy(IClientConfig config) { this.MaxRetries = config.MaxErrorRetry; if (config.ThrottleRetries) { string serviceURL = config.DetermineServiceURL(); RetryCapacity = CapacityManagerInstance.GetRetryCapacity(serviceURL); } }
/// <summary> /// 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. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> /// <param name="bypassAcquireCapacity">true to bypass any attempt to acquire capacity on a retry</param> /// <param name="isThrottlingError">true if the error that will be retried is a throtting error</param> public override bool OnRetry(IExecutionContext executionContext, bool bypassAcquireCapacity, bool isThrottlingError) { if (!bypassAcquireCapacity && executionContext.RequestContext.ClientConfig.ThrottleRetries && RetryCapacity != null) { return(CapacityManagerInstance.TryAcquireCapacity(RetryCapacity, executionContext.RequestContext.LastCapacityType)); } else { return(true); } }