public static RetryPolicy RetryExponential(int retryCount, TimeSpan minBackoff, TimeSpan maxBackoff, TimeSpan deltaBackoff) { CommonUtils.AssertInBounds("currentRetryCount", retryCount, 0, int.MaxValue); CommonUtils.AssertInBounds("minBackoff", minBackoff, TimeSpan.Zero, TimeSpan.MaxValue); CommonUtils.AssertInBounds("maxBackoff", maxBackoff, TimeSpan.Zero, TimeSpan.MaxValue); CommonUtils.AssertInBounds("deltaBackoff", deltaBackoff, TimeSpan.Zero, TimeSpan.MaxValue); return(() => { return (int currentRetryCount, Exception lastException, out TimeSpan retryInterval) => { if (currentRetryCount < retryCount) { Random r = new Random(); int increment = (int)((Math.Pow(2, currentRetryCount) - 1) * r.Next((int)(deltaBackoff.TotalMilliseconds * 0.8), (int)(deltaBackoff.TotalMilliseconds * 1.2))); int timeToSleepMsec = (int)Math.Min(minBackoff.TotalMilliseconds + increment, maxBackoff.TotalMilliseconds); retryInterval = TimeSpan.FromMilliseconds(timeToSleepMsec); return true; } retryInterval = TimeSpan.Zero; return false; }; }); }
/// <summary> /// Initializes a new instance of the <see cref="ResultPagination"/> class. /// </summary> /// <param name="maxResults">Number of results to be returned as a page. /// maxResults of 0 or less means no paging.</param> public ResultPagination(int maxResults) { CommonUtils.AssertInBounds("maxResults", maxResults, 0, Int32.MaxValue); this.maxResults = maxResults <= 0 ? 0 : maxResults; if (this.maxResults > 0) { this.remainingResultsInPage = this.maxResults; } }
/// <summary> /// Initializes a new instance of the BlobReadStream class. /// </summary> /// <param name="blob">The blob used for downloads.</param> /// <param name="options">Modifiers to be applied to the blob. After first request, the ETag is always applied.</param> /// <param name="readAheadInBytes">The number of bytes to read ahead.</param> /// <param name="verifyBlocks">Controls whether block's signatures are verified.</param> internal BlobReadStream(CloudBlob blob, BlobRequestOptions options, long readAheadInBytes, bool verifyBlocks) { CommonUtils.AssertNotNull("blob", blob); CommonUtils.AssertNotNull("options", options); CommonUtils.AssertInBounds("readAheadInBytes", readAheadInBytes, 0, Protocol.Constants.MaxBlobSize); this.Blob = blob; this.IntegrityControlVerificationEnabled = verifyBlocks; this.options = options; this.ReadAheadSize = readAheadInBytes; this.downloadedBlocksList = new DownloadedBlockCollection(); }
/// <summary> /// Returns a retry policy that retries a specified number of times, with a specified fixed time interval between retries. /// </summary> /// <param name="retryCount">A non-negative number indicating the number of times to retry.</param> /// <param name="intervalBetweenRetries">The time interval between retries. Use <see cref="System.TimeSpan.Zero"/> to specify that the operation /// should be retried immediately.</param> /// <returns>The retry policy.</returns> public static RetryPolicy Retry(int retryCount, TimeSpan intervalBetweenRetries) { CommonUtils.AssertInBounds("currentRetryCount", retryCount, 0, int.MaxValue); CommonUtils.AssertInBounds("intervalBetweenRetries", intervalBetweenRetries, TimeSpan.Zero, TimeSpan.MaxValue); return(() => { return (int currentRetryCount, Exception lastException, out TimeSpan retryInterval) => { retryInterval = intervalBetweenRetries; return currentRetryCount < retryCount; }; }); }
/// <summary> /// Checks that the given timeout in within allowed bounds. /// </summary> /// <param name="timeout">The timeout to check.</param> /// <exception cref="ArgumentOutOfRangeException">The timeout is not within allowed bounds.</exception> internal static void CheckTimeoutBounds(TimeSpan timeout) { CommonUtils.AssertInBounds("Timeout", timeout, TimeSpan.FromSeconds(1), Constants.MaximumAllowedTimeout); }