C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
PollingOptions.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3
4namespace AnalyzeRe
5{
8 public class PollingOptions
9 {
11 public static PollingOptions Default => new PollingOptions();
12
15 public int MinPollInterval { get; } = 0;
16
19 public int MaxPollInterval { get; } = 10 * 1000;
20
23 public int MaxPollTotalTime { get; } = Int32.MaxValue;
24
28 public double BackoffRate { get; } = 2.0d;
29
33
50 int? minPollInterval = null,
51 int? maxPollInterval = null,
52 int? maxPollTotalTime = null,
53 double? backoffRate = null,
54 CancellationToken? cancellationToken = null)
55 {
56 if (minPollInterval.HasValue)
57 MinPollInterval = minPollInterval.Value;
58 if (maxPollInterval.HasValue)
59 MaxPollInterval = maxPollInterval.Value;
60 if (maxPollTotalTime.HasValue)
61 MaxPollTotalTime = maxPollTotalTime.Value;
62 if (backoffRate.HasValue)
63 BackoffRate = backoffRate.Value;
64 if (MinPollInterval < 0)
65 throw new ArgumentOutOfRangeException(nameof(minPollInterval),
66 "Value must be greater than or equal to zero.");
67 if (BackoffRate < 1d)
68 throw new ArgumentOutOfRangeException(nameof(backoffRate),
69 "Value must be greater than or equal to 1.");
71 throw new ArgumentOutOfRangeException(nameof(minPollInterval),
72 "Value must be less than or equal to " + nameof(maxPollInterval) + ".");
73 if (MaxPollTotalTime < 0)
74 throw new ArgumentOutOfRangeException(nameof(maxPollTotalTime),
75 "Value must be greater than or equal to zero.");
76 CancellationToken = cancellationToken;
77 }
78
84 public int GetNextPollTime(int lastTimeWaited, int totalTimeWaited)
85 {
86 int nextTime = lastTimeWaited == 0 ? 1 : lastTimeWaited;
87 // Round up so that even small back-off rates result in a minimum 1 ms increase.
88 nextTime = (int)Math.Ceiling(nextTime * BackoffRate);
89 // If this would be greater than the amount of time left before we
90 // time out, make the next request sooner.
91 if (nextTime + totalTimeWaited > MaxPollTotalTime)
92 nextTime = MaxPollTotalTime - totalTimeWaited;
93 // Bound the wait time between the min and max intervals specified.
94 return nextTime > MaxPollInterval ? MaxPollInterval :
95 nextTime < MinPollInterval ? MinPollInterval : nextTime;
96 }
97 }
98
99 public static partial class API
100 {
102 [Obsolete("This class has moved to the AnalyzeRe namespace. " +
103 "You should remove the `API` prefix.")]
105 {
112 [Obsolete("This class has moved to the AnalyzeRe namespace. " +
113 "You should remove the `API` prefix.")]
115 int? minPollInterval = null,
116 int? maxPollInterval = null,
117 int? maxPollTotalTime = null,
118 double? backoffRate = null,
119 CancellationToken? cancellationToken = null)
120 : base(minPollInterval, maxPollInterval, maxPollTotalTime,
121 backoffRate, cancellationToken)
122 {
123 }
124 }
125 }
126}
A duplicate of the AnalyzeRe.PollingOptions class.
PollingOptions(int? minPollInterval=null, int? maxPollInterval=null, int? maxPollTotalTime=null, double? backoffRate=null, CancellationToken? cancellationToken=null)
AnalyzeRe.PollingOptions
Determines the behaviour of the API when automatically retrying a request whose result is not yet rea...
PollingOptions(int? minPollInterval=null, int? maxPollInterval=null, int? maxPollTotalTime=null, double? backoffRate=null, CancellationToken? cancellationToken=null)
Construct a set of Polling Arguments.
CancellationToken? CancellationToken
A cancellation token (if available) supplied to the polling method to allow the polling task to be ca...
int MaxPollTotalTime
The maximum time (in milliseconds) to poll the request before raising a NotWaitingException....
int MaxPollInterval
The maximum time (in milliseconds) to wait between retrying the request. (Default is a maximum of 10 ...
int MinPollInterval
The minimum time (in milliseconds) to wait between retrying the request. (Default is no minimum time....
int GetNextPollTime(int lastTimeWaited, int totalTimeWaited)
Compute the next amount of time we should wait before polling again, based on the previous time waite...
double BackoffRate
The rate at which the polling interval is increased after repeated attempts. The interval will not be...
static PollingOptions Default
The default PollingArguments used when none are specified.