8#ifndef INCLUDED_BALB_LEAKYBUCKET
9#define INCLUDED_BALB_LEAKYBUCKET
365#include <balscm_version.h>
371#include <bsl_climits.h>
657 if (numUnits > d_unitsReserved) {
661 d_unitsReserved -= numUnits;
674 d_unitsInBucket <= ULLONG_MAX - d_unitsReserved - numUnits);
676 d_unitsReserved += numUnits;
684 d_lastUpdateTime = currentTime;
693 d_statisticsCollectionStartTime = d_lastUpdateTime;
694 d_statSubmittedUnits = 0;
695 d_statSubmittedUnitsAtLastUpdate = 0;
707 d_unitsReserved <= ULLONG_MAX - d_unitsInBucket - numUnits);
709 d_unitsInBucket += numUnits;
710 d_statSubmittedUnits += numUnits;
718 d_unitsReserved -= numUnits;
739 return d_lastUpdateTime;
745 return d_statisticsCollectionStartTime;
751 return d_unitsInBucket;
757 return d_unitsReserved;
Definition balb_leakybucket.h:421
void submitReserved(bsls::Types::Uint64 numUnits)
Definition balb_leakybucket.h:714
~LeakyBucket()
Destroy this object.
Definition balb_leakybucket.h:645
bsls::Types::Uint64 unitsInBucket() const
Return the number of submitted units in this leaky bucket.
Definition balb_leakybucket.h:749
void submit(bsls::Types::Uint64 numUnits)
Definition balb_leakybucket.h:699
void setRateAndCapacity(bsls::Types::Uint64 newRate, bsls::Types::Uint64 newCapacity)
void reserve(bsls::Types::Uint64 numUnits)
Definition balb_leakybucket.h:666
LeakyBucket(bsls::Types::Uint64 drainRate, bsls::Types::Uint64 capacity, const bsls::TimeInterval ¤tTime)
bsls::TimeInterval lastUpdateTime() const
Return the time interval when this leaky bucket was last updated.
Definition balb_leakybucket.h:737
static bsls::Types::Uint64 calculateCapacity(bsls::Types::Uint64 drainRate, const bsls::TimeInterval &timeWindow)
void reset(const bsls::TimeInterval ¤tTime)
Definition balb_leakybucket.h:680
void getStatistics(bsls::Types::Uint64 *submittedUnits, bsls::Types::Uint64 *unusedUnits) const
bool wouldOverflow(const bsls::TimeInterval ¤tTime)
bsls::TimeInterval statisticsCollectionStartTime() const
Definition balb_leakybucket.h:743
void updateState(const bsls::TimeInterval ¤tTime)
bsls::TimeInterval calculateTimeToSubmit(const bsls::TimeInterval ¤tTime)
static bsls::TimeInterval calculateTimeWindow(bsls::Types::Uint64 drainRate, bsls::Types::Uint64 capacity)
bsls::Types::Uint64 unitsReserved() const
Return the number of reserved units in this leaky bucket.
Definition balb_leakybucket.h:755
bsls::Types::Uint64 drainRate() const
Return the drain rate of this leaky bucket.
Definition balb_leakybucket.h:731
bsls::Types::Uint64 capacity() const
Return the capacity of this leaky bucket.
Definition balb_leakybucket.h:725
void cancelReserved(bsls::Types::Uint64 numUnits)
Definition balb_leakybucket.h:653
static bsls::TimeInterval calculateDrainTime(bsls::Types::Uint64 numUnits, bsls::Types::Uint64 drainRate, bool ceilFlag)
void resetStatistics()
Definition balb_leakybucket.h:691
Definition bsls_timeinterval.h:301
BSLS_KEYWORD_CONSTEXPR bsls::Types::Int64 seconds() const
Definition bsls_timeinterval.h:1354
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balb_controlmanager.h:133
unsigned long long Uint64
Definition bsls_types.h:137