1 #ifndef CORELIB___REQUEST_CONTROL__HPP
2 #define CORELIB___REQUEST_CONTROL__HPP
64 eMinTimeBetweenRequests
130 (
unsigned int num_requests_allowed,
133 EThrottleAction throttle_action =
eDefault,
134 EThrottleMode throttle_mode = eContinuous);
157 void Reset(
unsigned int num_requests_allowed,
160 EThrottleAction throttle_action =
eDefault,
161 EThrottleMode throttle_mode = eContinuous);
175 bool Approve(EThrottleAction action =
eDefault);
202 void Lock() { Approve(eSleep); }
206 bool IsEnabled(
void)
const {
return m_NumRequestsAllowed != kNoLimit; }
215 void x_CleanTimeLine(
TTime now);
CRequestRateControlException –.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
EErrCode
Error types that an application can generate.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
unsigned int m_NumRequests
Num requests per period.
EThrottleAction
What to do if exceeded the rate limits.
bool IsEnabled(void) const
Check if throttling is enabled.
EThrottleMode
Throttle mode.
TTime m_MinTimeBetweenRequests
EThrottleAction m_ThrottleAction
CStopWatch m_StopWatch
Stopwatch to measure elapsed time.
CTimeSpan ApproveTime(void)
Get a time span in which request can be approved.
unsigned int m_NumRequestsAllowed
TTimeLine m_TimeLine
Vector of times of approvals.
void Lock()
Lock/unlock functions for use by generic RAII guard CGuard.
bool Approve(EThrottleAction action=eDefault)
Approve a request.
NCBI_EXCEPTION_DEFAULT(CRequestRateControlException, CCoreException)
bool x_Approve(EThrottleAction action, CTimeSpan *sleeptime)
TTime m_LastApproved
Last approve time.
@ eSleep
Sleep till the rate requirements are met & return.
@ eException
Throw an exception.
@ eErrCode
Return immediately with err code == FALSE.
@ eContinuous
Uses float time frame to check number of requests.
@ eNumRequestsPerPeriod
Number of requests per period exceeded;.
@ eNumRequestsMax
Maximum number of requests exceeded;.
#define NCBI_XNCBI_EXPORT
Defines: CTimeFormat - storage class for time format.