proxygen
folly::TimeoutManager Class Referenceabstract

#include <TimeoutManager.h>

Inheritance diagram for folly::TimeoutManager:
folly::EventBase folly::test::MockTimeoutManager folly::VirtualEventBase

Classes

struct  CobTimeouts
 

Public Types

enum  InternalEnum { InternalEnum::INTERNAL, InternalEnum::NORMAL }
 
typedef std::chrono::milliseconds timeout_type
 
using Func = folly::Function< void()>
 

Public Member Functions

 TimeoutManager ()
 
virtual ~TimeoutManager ()
 
virtual void attachTimeoutManager (AsyncTimeout *obj, InternalEnum internal)=0
 
virtual void detachTimeoutManager (AsyncTimeout *obj)=0
 
virtual bool scheduleTimeout (AsyncTimeout *obj, timeout_type timeout)=0
 
virtual void cancelTimeout (AsyncTimeout *obj)=0
 
virtual void bumpHandlingTime ()=0
 
virtual bool isInTimeoutManagerThread ()=0
 
void runAfterDelay (Func cob, uint32_t milliseconds, InternalEnum internal=InternalEnum::NORMAL)
 
bool tryRunAfterDelay (Func cob, uint32_t milliseconds, InternalEnum internal=InternalEnum::NORMAL)
 

Protected Member Functions

void clearCobTimeouts ()
 

Private Attributes

std::unique_ptr< CobTimeoutscobTimeouts_
 

Detailed Description

Base interface to be implemented by all classes expecting to manage timeouts. AsyncTimeout will use implementations of this interface to schedule/cancel timeouts.

Definition at line 33 of file TimeoutManager.h.

Member Typedef Documentation

Definition at line 36 of file TimeoutManager.h.

typedef std::chrono::milliseconds folly::TimeoutManager::timeout_type

Definition at line 35 of file TimeoutManager.h.

Member Enumeration Documentation

Enumerator
INTERNAL 
NORMAL 

Definition at line 38 of file TimeoutManager.h.

38 { INTERNAL, NORMAL };

Constructor & Destructor Documentation

folly::TimeoutManager::TimeoutManager ( )

Definition at line 70 of file TimeoutManager.cpp.

71  : cobTimeouts_(std::make_unique<CobTimeouts>()) {}
std::unique_ptr< CobTimeouts > cobTimeouts_
folly::TimeoutManager::~TimeoutManager ( )
virtual

Definition at line 113 of file TimeoutManager.cpp.

References clearCobTimeouts().

113  {
115 }

Member Function Documentation

virtual void folly::TimeoutManager::attachTimeoutManager ( AsyncTimeout obj,
InternalEnum  internal 
)
pure virtual
virtual void folly::TimeoutManager::bumpHandlingTime ( )
pure virtual

This is used to mark the beginning of a new loop cycle by the first handler fired within that cycle.

Implemented in folly::EventBase, and folly::VirtualEventBase.

Referenced by folly::AsyncTimeout::libeventCallback().

virtual void folly::TimeoutManager::cancelTimeout ( AsyncTimeout obj)
pure virtual

Cancels the AsyncTimeout, if scheduled

Implemented in folly::EventBase, and folly::VirtualEventBase.

Referenced by folly::AsyncTimeout::cancelTimeout().

void folly::TimeoutManager::clearCobTimeouts ( )
protected

Definition at line 100 of file TimeoutManager.cpp.

References cobTimeouts_, and folly::detail::timeout.

Referenced by folly::VirtualEventBase::destroyImpl(), folly::EventBase::~EventBase(), and ~TimeoutManager().

100  {
101  if (!cobTimeouts_) {
102  return;
103  }
104 
105  // Delete any unfired callback objects, so that we don't leak memory
106  // Note that we don't fire them.
107  while (!cobTimeouts_->list.empty()) {
108  auto* timeout = &cobTimeouts_->list.front();
109  delete timeout;
110  }
111 }
std::unique_ptr< CobTimeouts > cobTimeouts_
virtual void folly::TimeoutManager::detachTimeoutManager ( AsyncTimeout obj)
pure virtual
virtual bool folly::TimeoutManager::isInTimeoutManagerThread ( )
pure virtual

Helper method to know whether we are running in the timeout manager thread

Implemented in folly::EventBase, and folly::VirtualEventBase.

Referenced by folly::AsyncTimeout::attachTimeoutManager().

void folly::TimeoutManager::runAfterDelay ( Func  cob,
uint32_t  milliseconds,
InternalEnum  internal = InternalEnum::NORMAL 
)

Runs the given Cob at some time after the specified number of milliseconds. (No guarantees exactly when.)

Throws a std::system_error if an error occurs.

Definition at line 73 of file TimeoutManager.cpp.

References folly::gen::move, folly::throwSystemError(), and tryRunAfterDelay().

Referenced by TEST().

76  {
77  if (!tryRunAfterDelay(std::move(cob), milliseconds, internal)) {
79  "error in TimeoutManager::runAfterDelay(), failed to schedule timeout");
80  }
81 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool tryRunAfterDelay(Func cob, uint32_t milliseconds, InternalEnum internal=InternalEnum::NORMAL)
void throwSystemError(Args &&...args)
Definition: Exception.h:76
virtual bool folly::TimeoutManager::scheduleTimeout ( AsyncTimeout obj,
timeout_type  timeout 
)
pure virtual

Schedules AsyncTimeout to fire after timeout milliseconds

Implemented in folly::EventBase, and folly::VirtualEventBase.

Referenced by folly::AsyncTimeout::scheduleTimeout().

bool folly::TimeoutManager::tryRunAfterDelay ( Func  cob,
uint32_t  milliseconds,
InternalEnum  internal = InternalEnum::NORMAL 
)
See also
tryRunAfterDelay for more details
Returns
true iff the cob was successfully registered.

Definition at line 83 of file TimeoutManager.cpp.

References cobTimeouts_, folly::gen::move, and folly::detail::timeout.

Referenced by folly::HandshakeTimeoutCallback::connAccepted(), folly::TestSSLAsyncCacheServer::getSessionCallback(), TestClientPipelineFactory::newPipeline(), runAfterDelay(), scheduleEvents(), TEST(), and folly::fibers::EventBaseLoopController::timedSchedule().

86  {
87  if (!cobTimeouts_) {
88  return false;
89  }
90 
91  auto timeout =
92  std::make_unique<CobTimeouts::CobTimeout>(this, std::move(cob), internal);
93  if (!timeout->scheduleTimeout(milliseconds)) {
94  return false;
95  }
96  cobTimeouts_->list.push_back(*timeout.release());
97  return true;
98 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< CobTimeouts > cobTimeouts_

Member Data Documentation

std::unique_ptr<CobTimeouts> folly::TimeoutManager::cobTimeouts_
private

Definition at line 99 of file TimeoutManager.h.

Referenced by clearCobTimeouts(), and tryRunAfterDelay().


The documentation for this class was generated from the following files: