proxygen
|
#include <AsyncTimeoutSet.h>
Classes | |
class | Callback |
class | TimeoutClock |
Public Types | |
using | UniquePtr = std::unique_ptr< AsyncTimeoutSet, Destructor > |
Public Member Functions | |
AsyncTimeoutSet (folly::TimeoutManager *timeoutManager, std::chrono::milliseconds intervalMS, std::chrono::milliseconds atMostEveryN=std::chrono::milliseconds(0), TimeoutClock *timeoutClock=nullptr) | |
AsyncTimeoutSet (folly::TimeoutManager *timeoutManager, InternalEnum internal, std::chrono::milliseconds intervalMS, std::chrono::milliseconds atMostEveryN=std::chrono::milliseconds(0)) | |
void | destroy () override |
std::chrono::milliseconds | getInterval () const |
void | scheduleTimeout (Callback *callback) |
void | fireAtMostEvery (const std::chrono::milliseconds &ms) |
Callback * | front () |
const Callback * | front () const |
Public Member Functions inherited from folly::DelayedDestruction | |
bool | getDestroyPending () const |
Public Member Functions inherited from folly::DelayedDestructionBase | |
virtual | ~DelayedDestructionBase ()=default |
Protected Member Functions | |
~AsyncTimeoutSet () override | |
Protected Member Functions inherited from folly::DelayedDestruction | |
~DelayedDestruction () override=default | |
DelayedDestruction () | |
Protected Member Functions inherited from folly::DelayedDestructionBase | |
DelayedDestructionBase () | |
uint32_t | getDestructorGuardCount () const |
Private Member Functions | |
AsyncTimeoutSet (AsyncTimeoutSet const &)=delete | |
AsyncTimeoutSet & | operator= (AsyncTimeoutSet const &)=delete |
void | headChanged () |
void | timeoutExpired () noexceptoverride |
Private Member Functions inherited from folly::AsyncTimeout | |
AsyncTimeout (TimeoutManager *timeoutManager) | |
AsyncTimeout (EventBase *eventBase) | |
AsyncTimeout (TimeoutManager *timeoutManager, InternalEnum internal) | |
AsyncTimeout (EventBase *eventBase, InternalEnum internal) | |
AsyncTimeout () | |
virtual | ~AsyncTimeout () |
bool | scheduleTimeout (uint32_t milliseconds) |
bool | scheduleTimeout (TimeoutManager::timeout_type timeout) |
void | cancelTimeout () |
bool | isScheduled () const |
void | attachTimeoutManager (TimeoutManager *timeoutManager, InternalEnum internal=InternalEnum::NORMAL) |
void | attachEventBase (EventBase *eventBase, InternalEnum internal=InternalEnum::NORMAL) |
void | detachTimeoutManager () |
void | detachEventBase () |
const TimeoutManager * | getTimeoutManager () |
struct event * | getEvent () |
Private Attributes | |
TimeoutClock & | timeoutClock_ |
Callback * | head_ |
Callback * | tail_ |
std::chrono::milliseconds | interval_ |
std::chrono::milliseconds | atMostEveryN_ |
bool | inTimeoutExpired_ {false} |
Additional Inherited Members | |
Private Types inherited from folly::AsyncTimeout | |
typedef TimeoutManager::InternalEnum | InternalEnum |
Static Private Member Functions inherited from folly::AsyncTimeout | |
template<typename TCallback > | |
static std::unique_ptr< AsyncTimeout > | make (TimeoutManager &manager, TCallback &&callback) |
template<typename TCallback > | |
static std::unique_ptr< AsyncTimeout > | schedule (TimeoutManager::timeout_type timeout, TimeoutManager &manager, TCallback &&callback) |
AsyncTimeoutSet exists for efficiently managing a group of timeouts events that always have the same timeout interval.
AsyncTimeoutSet takes advantage of the fact that the timeouts are always scheduled in sorted order. (Since each timeout has the same interval, when a new timeout is scheduled it will always be the last timeout in the set.) This avoids the need to perform any additional sorting of the timeouts within a single AsyncTimeoutSet.
AsyncTimeoutSet is useful whenever you have a large group of objects that each need their own timeout, but with the same interval for each object. For example, managing idle timeouts for thousands of connection, or scheduling health checks for a large group of servers.
Note, this class may not be needed given libevent's event_base_init_common_timeout(). We should look into using that.
Definition at line 40 of file AsyncTimeoutSet.h.
using proxygen::AsyncTimeoutSet::UniquePtr = std::unique_ptr<AsyncTimeoutSet, Destructor> |
Definition at line 43 of file AsyncTimeoutSet.h.
proxygen::AsyncTimeoutSet::AsyncTimeoutSet | ( | folly::TimeoutManager * | timeoutManager, |
std::chrono::milliseconds | intervalMS, | ||
std::chrono::milliseconds | atMostEveryN = std::chrono::milliseconds(0) , |
||
TimeoutClock * | timeoutClock = nullptr |
||
) |
Create a new AsyncTimeoutSet with the specified interval.
If timeout clock is unspecified, it will use the default (system clock)
Referenced by proxygen::AsyncTimeoutSet::Callback::cancelTimeoutImpl().
proxygen::AsyncTimeoutSet::AsyncTimeoutSet | ( | folly::TimeoutManager * | timeoutManager, |
InternalEnum | internal, | ||
std::chrono::milliseconds | intervalMS, | ||
std::chrono::milliseconds | atMostEveryN = std::chrono::milliseconds(0) |
||
) |
Create a new AsyncTimeoutSet with the given 'internal' settting. For details on what the InternalEnum specifies, see the documentation in AsyncTimeout.h
|
overrideprotected |
Protected destructor.
Use destroy() instead. See the comments in DelayedDestruction for more details.
Definition at line 100 of file AsyncTimeoutSet.cpp.
Referenced by front().
|
privatedelete |
|
overridevirtual |
Destroy the AsyncTimeoutSet.
Normally a AsyncTimeoutSet should only be destroyed when there are no more callbacks pending in the set. If there are timeout callbacks pending for this set, destroying the AsyncTimeoutSet will automatically cancel them. If you destroy a AsyncTimeoutSet with callbacks pending, your callback code needs to be aware that the callbacks will never be invoked.
Reimplemented from folly::DelayedDestruction.
Definition at line 112 of file AsyncTimeoutSet.cpp.
References destroy().
Referenced by proxygen::AsyncTimeoutSet::TimeoutClock::~TimeoutClock().
|
inline |
Limit how frequently this AsyncTimeoutSet will fire.
Definition at line 179 of file AsyncTimeoutSet.h.
References atMostEveryN_.
|
inline |
Get a pointer to the next Callback scheduled to be invoked (may be null).
Definition at line 186 of file AsyncTimeoutSet.h.
References head_.
Referenced by TestTimeout::_scheduleNext().
|
inline |
Definition at line 187 of file AsyncTimeoutSet.h.
References proxygen::AsyncTimeoutSet::Callback::AsyncTimeoutSet, head_, headChanged(), folly::pushmi::__adl::noexcept(), operator=(), proxygen::AsyncTimeoutSet::Callback::timeoutExpired(), and ~AsyncTimeoutSet().
|
inline |
Get the interval for this AsyncTimeoutSet.
Returns the timeout interval in milliseconds. All callbacks scheduled with scheduleTimeout() will be invoked after this amount of time has passed since the call to scheduleTimeout().
Definition at line 163 of file AsyncTimeoutSet.h.
References interval_, and scheduleTimeout().
|
private |
Definition at line 158 of file AsyncTimeoutSet.cpp.
References folly::AsyncTimeout::cancelTimeout(), and folly::AsyncTimeout::scheduleTimeout().
Referenced by front().
|
privatedelete |
Referenced by front().
void proxygen::AsyncTimeoutSet::scheduleTimeout | ( | Callback * | callback | ) |
Schedule the specified Callback to be invoked after the AsyncTimeoutSet's specified timeout interval.
If the callback is already scheduled, this cancels the existing timeout before scheduling the new timeout.
Definition at line 128 of file AsyncTimeoutSet.cpp.
References proxygen::AsyncTimeoutSet::Callback::cancelTimeout(), proxygen::AsyncTimeoutSet::Callback::context_, proxygen::AsyncTimeoutSet::Callback::next_, proxygen::AsyncTimeoutSet::Callback::prev_, folly::RequestContext::saveContext(), folly::AsyncTimeout::scheduleTimeout(), and proxygen::AsyncTimeoutSet::Callback::setScheduled().
Referenced by TestTimeout::_scheduleNext(), and getInterval().
|
overrideprivatevirtualnoexcept |
timeoutExpired() is invoked when the timeout period has expired.
Implements folly::AsyncTimeout.
Definition at line 175 of file AsyncTimeoutSet.cpp.
References proxygen::AsyncTimeoutSet::Callback::cancelTimeout(), proxygen::AsyncTimeoutSet::Callback::context_, now(), folly::AsyncTimeout::scheduleTimeout(), SCOPE_EXIT, folly::RequestContext::setContext(), and proxygen::AsyncTimeoutSet::Callback::timeoutExpired().
|
private |
Definition at line 213 of file AsyncTimeoutSet.h.
Referenced by fireAtMostEvery().
|
private |
Definition at line 210 of file AsyncTimeoutSet.h.
Referenced by front().
|
private |
Definition at line 212 of file AsyncTimeoutSet.h.
Referenced by getInterval().
|
private |
Definition at line 214 of file AsyncTimeoutSet.h.
|
private |
Definition at line 211 of file AsyncTimeoutSet.h.
|
private |
Definition at line 209 of file AsyncTimeoutSet.h.
Referenced by proxygen::AsyncTimeoutSet::Callback::setScheduled().