proxygen
|
#include <NotificationQueue.h>
Public Types | |
enum | : uint16_t { kDefaultMaxReadAtOnce = 10 } |
Public Member Functions | |
Consumer () | |
virtual void | messageAvailable (MessageT &&message) noexcept=0 |
void | startConsuming (EventBase *eventBase, NotificationQueue *queue) |
void | startConsumingInternal (EventBase *eventBase, NotificationQueue *queue) |
void | stopConsuming () |
bool | consumeUntilDrained (size_t *numConsumed=nullptr) noexcept |
NotificationQueue * | getCurrentQueue () const |
void | setMaxReadAtOnce (uint32_t maxAtOnce) |
uint32_t | getMaxReadAtOnce () const |
EventBase * | getEventBase () |
void | handlerReady (uint16_t events) noexceptoverride |
template<typename TCallback > | |
std::unique_ptr< typename NotificationQueue< MessageT >::Consumer, DelayedDestruction::Destructor > | make (TCallback &&callback) |
Public Member Functions inherited from folly::DelayedDestruction | |
bool | getDestroyPending () const |
Public Member Functions inherited from folly::DelayedDestructionBase | |
virtual | ~DelayedDestructionBase ()=default |
Static Public Member Functions | |
template<typename TCallback > | |
static std::unique_ptr< Consumer, DelayedDestruction::Destructor > | make (TCallback &&callback) |
Protected Member Functions | |
void | destroy () override |
~Consumer () 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 | |
void | consumeMessages (bool isDrain, size_t *numConsumed=nullptr) noexcept |
void | setActive (bool active, bool shouldLock=false) |
void | init (EventBase *eventBase, NotificationQueue *queue) |
Private Member Functions inherited from folly::EventHandler | |
EventHandler (EventBase *eventBase, int fd) | |
EventHandler (EventBase *eventBase=nullptr, NetworkSocket fd=NetworkSocket()) | |
virtual | ~EventHandler () |
bool | registerHandler (uint16_t events) |
void | unregisterHandler () |
bool | isHandlerRegistered () const |
void | attachEventBase (EventBase *eventBase) |
void | detachEventBase () |
void | changeHandlerFD (int fd) |
void | changeHandlerFD (NetworkSocket fd) |
void | initHandler (EventBase *eventBase, int fd) |
void | initHandler (EventBase *eventBase, NetworkSocket fd) |
uint16_t | getRegisteredEvents () const |
bool | registerInternalHandler (uint16_t events) |
bool | isPending () const |
Private Attributes | |
NotificationQueue * | queue_ |
bool * | destroyedFlagPtr_ |
uint32_t | maxReadAtOnce_ |
EventBase * | base_ |
bool | active_ {false} |
Additional Inherited Members | |
Private Types inherited from folly::EventHandler | |
enum | EventFlags { NONE = 0, READ = EV_READ, WRITE = EV_WRITE, READ_WRITE = (READ | WRITE), PERSIST = EV_PERSIST } |
A callback interface for consuming messages from the queue as they arrive.
Definition at line 83 of file NotificationQueue.h.
anonymous enum : uint16_t |
|
inline |
Definition at line 87 of file NotificationQueue.h.
References folly::pushmi::__adl::noexcept().
|
inlineoverrideprotected |
Definition at line 184 of file NotificationQueue.h.
References folly::pushmi::__adl::noexcept().
|
privatenoexcept |
Consume messages off the the queue until
(1) Well, maybe. See logic/comments around "wasEmpty" in implementation.
Definition at line 691 of file NotificationQueue.h.
References folly::data(), folly::gen::move, folly::NotificationQueue< MessageT >::queue_, SCOPE_EXIT, uint32_t, and UNLIKELY.
|
noexcept |
Consume messages off the queue until it is empty. No messages may be added to the queue while it is draining, so that the process is bounded. To that end, putMessage/tryPutMessage will throw an std::runtime_error, and tryPutMessageNoThrow will return false.
Definition at line 848 of file NotificationQueue.h.
References g(), and folly::NotificationQueue< MessageT >::queue_.
Referenced by TEST().
|
overrideprotectedvirtual |
destroy() requests destruction of the object.
This method will destroy the object after it has no more functions running higher up on the stack. (i.e., No more DestructorGuard objects exist for this object.) This method must be used instead of the destructor.
Reimplemented from folly::DelayedDestruction.
Definition at line 672 of file NotificationQueue.h.
References folly::DelayedDestruction::destroy().
|
inline |
Get the NotificationQueue that this consumer is currently consuming messages from. Returns nullptr if the consumer is not currently consuming events from any queue.
Definition at line 154 of file NotificationQueue.h.
References folly::NotificationQueue< MessageT >::queue_.
|
inline |
Definition at line 175 of file NotificationQueue.h.
References base_, destroy(), and uint16_t.
Referenced by folly::EventBase::FunctionRunner::messageAvailable().
|
inline |
Definition at line 171 of file NotificationQueue.h.
|
overridevirtualnoexcept |
handlerReady() is invoked when the handler is ready.
events | A bitset indicating the events that are ready. |
Implements folly::EventHandler.
Definition at line 685 of file NotificationQueue.h.
|
private |
Definition at line 803 of file NotificationQueue.h.
References base_, folly::EventBase::dcheckIsInEventBaseThread(), g(), and folly::NotificationQueue< MessageT >::queue_.
|
static |
std::unique_ptr< typename NotificationQueue<MessageT>::Consumer, DelayedDestruction::Destructor> folly::NotificationQueue< MessageT >::Consumer::make | ( | TCallback && | callback | ) |
|
pure virtualnoexcept |
messageAvailable() will be invoked whenever a new message is available from the pipe.
Implemented in folly::detail::notification_queue_consumer_wrapper< MessageT, TCallback >.
|
inlineprivate |
Definition at line 199 of file NotificationQueue.h.
References folly::init(), and folly::NotificationQueue< MessageT >::queue_.
|
inline |
Set a limit on how many messages this consumer will read each iteration around the event loop.
This helps rate-limit how much work the Consumer will do each event loop iteration, to prevent it from starving other event handlers.
A limit of 0 means no limit will be enforced. If unset, the limit defaults to kDefaultMaxReadAtOnce (defined to 10 above).
Definition at line 168 of file NotificationQueue.h.
Referenced by QueueTest::maxReadAtOnce(), folly::AsyncServerSocket::RemoteAcceptor::start(), and TEST().
|
inline |
Begin consuming messages from the specified queue.
messageAvailable() will be called whenever a message is available. This consumer will continue to consume messages until stopConsuming() is called.
A Consumer may only consume messages from a single NotificationQueue at a time. startConsuming() should not be called if this consumer is already consuming.
Definition at line 114 of file NotificationQueue.h.
References folly::init().
Referenced by QueueTest::maxReadAtOnce(), QueueTest::multiConsumer(), QueueTest::putMessages(), QueueTest::sendOne(), and TEST().
|
inline |
Same as above but registers this event handler as internal so that it doesn't count towards the pending reader count for the IOLoop.
Definition at line 123 of file NotificationQueue.h.
References folly::init(), and folly::pushmi::__adl::noexcept().
void folly::NotificationQueue< MessageT >::Consumer::stopConsuming | ( | ) |
Stop consuming messages.
startConsuming() may be called again to resume consumption of messages at a later point in time.
Definition at line 829 of file NotificationQueue.h.
References g(), and folly::NotificationQueue< MessageT >::queue_.
Referenced by QueueTest::multiConsumer(), QueueTest::putMessages(), and QueueTest::sendOne().
|
private |
Definition at line 223 of file NotificationQueue.h.
|
private |
Definition at line 222 of file NotificationQueue.h.
|
private |
Definition at line 220 of file NotificationQueue.h.
|
private |
Definition at line 221 of file NotificationQueue.h.
|
private |
Definition at line 219 of file NotificationQueue.h.