|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Priority-ordered queue of pending RequestReply objects (per executor connection). More...
#include <RequestClient.h>
Public Member Functions | |
| RequestQueue () | |
| virtual | ~RequestQueue () |
| bool | init (uint32 id) |
| Initialise the queue. | |
| uint32 | getCount () |
| bool | addRequest (RequestReply *req, double priority=0) |
Insert a request, ordered by priority (higher = closer to the front). | |
| RequestReply * | getNextRequest () |
| Pop the next request to dispatch. | |
| RequestReply * | getNextTimedoutRequest () |
| Find and remove the next request whose deadline has passed. | |
| bool | completeRequest (RequestReply *req) |
| Mark a request as done and remove it from tracking. | |
| uint32 | removeStaleRequests (uint32 ttlMS) |
Fail and remove requests older than ttlMS milliseconds. | |
| std::list< RequestReply * > | takeQueue () |
| Atomically take all queued requests (used to redistribute a dead executor's backlog). | |
| std::string | toXML () |
| std::string | toJSON () |
Static Public Member Functions | |
| static bool | UnitTest () |
| Self-test of queue ordering/priority behaviour. | |
Protected Attributes | |
| std::list< RequestReply * > | requestQ |
| The ordered pending requests. | |
| utils::Mutex | mutex |
| Guards ::requestQ. | |
| uint32 | id |
| Owner id for logging. | |
Priority-ordered queue of pending RequestReply objects (per executor connection).
Used by RequestGateway to hold requests destined for one executor, separately for short and long requests. Supports priority insertion, timeout scanning and bulk take-over when an executor dies (its queue is redistributed to the survivors). Implemented in RequestGateway.cpp.
Definition at line 241 of file RequestClient.h.
| cmlabs::RequestQueue::RequestQueue | ( | ) |
Definition at line 17 of file RequestGateway.cpp.
Referenced by UnitTest().
|
virtual |
Definition at line 21 of file RequestGateway.cpp.
| bool cmlabs::RequestQueue::addRequest | ( | RequestReply * | req, |
| double | priority = 0 ) |
Insert a request, ordered by priority (higher = closer to the front).
| req | Request (queue does not take ownership of the pooled object). |
| priority | Ordering key; 0 appends in FIFO order. |
Definition at line 32 of file RequestGateway.cpp.
References cmlabs::RequestReply::gatewayRef, mutex, cmlabs::RequestReply::origin, and requestQ.
Referenced by cmlabs::RequestGateway::addRequestReplyToRequestQueue(), and UnitTest().
| bool cmlabs::RequestQueue::completeRequest | ( | RequestReply * | req | ) |
Mark a request as done and remove it from tracking.
| req | The completed request. |
Definition at line 137 of file RequestGateway.cpp.
References mutex, and requestQ.
Referenced by UnitTest().
|
inline |
Definition at line 253 of file RequestClient.h.
References requestQ.
Referenced by cmlabs::RequestGateway::addRequestReplyToRequestQueue(), and UnitTest().
| RequestReply * cmlabs::RequestQueue::getNextRequest | ( | ) |
Pop the next request to dispatch.
Definition at line 74 of file RequestGateway.cpp.
References cmlabs::RequestReply::getStatus(), cmlabs::LOCALERROR, mutex, cmlabs::PROCESSING, cmlabs::QUEUED, requestQ, and cmlabs::RequestReply::setStatus().
Referenced by UnitTest().
| RequestReply * cmlabs::RequestQueue::getNextTimedoutRequest | ( | ) |
Find and remove the next request whose deadline has passed.
Definition at line 100 of file RequestGateway.cpp.
References cmlabs::RequestReply::getStatus(), mutex, requestQ, and cmlabs::TIMEOUT.
| bool cmlabs::RequestQueue::init | ( | uint32 | id | ) |
Initialise the queue.
| id | Owner id used for logging. |
Definition at line 27 of file RequestGateway.cpp.
| uint32 cmlabs::RequestQueue::removeStaleRequests | ( | uint32 | ttlMS | ) |
Fail and remove requests older than ttlMS milliseconds.
| ttlMS | Age limit. |
Definition at line 155 of file RequestGateway.cpp.
References cmlabs::RequestReply::getStatus(), cmlabs::GetTimeAgeMS(), mutex, cmlabs::PROCESSING, requestQ, cmlabs::SENT, cmlabs::RequestReply::setStatus(), cmlabs::RequestReply::startTime, and cmlabs::TIMEOUT.
| std::list< RequestReply * > cmlabs::RequestQueue::takeQueue | ( | ) |
Atomically take all queued requests (used to redistribute a dead executor's backlog).
Definition at line 145 of file RequestGateway.cpp.
References mutex, and requestQ.
Referenced by UnitTest().
| std::string cmlabs::RequestQueue::toJSON | ( | ) |
Definition at line 193 of file RequestGateway.cpp.
References cmlabs::GetTimeAgeMS(), mutex, requestQ, and cmlabs::utils::StringFormat().
| std::string cmlabs::RequestQueue::toXML | ( | ) |
Definition at line 177 of file RequestGateway.cpp.
References cmlabs::GetTimeAgeMS(), mutex, requestQ, and cmlabs::utils::StringFormat().
|
static |
Self-test of queue ordering/priority behaviour.
Definition at line 226 of file RequestGateway.cpp.
References addRequest(), cmlabs::RequestReply::clientRef, completeRequest(), cmlabs::unittest::detail(), cmlabs::unittest::fail(), cmlabs::RequestReply::gatewayRef, getCount(), getNextRequest(), cmlabs::RequestReply::getStatus(), cmlabs::GetTimeNow(), cmlabs::RequestReply::giveRequestMessage(), cmlabs::unittest::metric(), cmlabs::RequestReply::origin, cmlabs::PROCESSING, cmlabs::unittest::progress(), cmlabs::QUEUED, RequestQueue(), cmlabs::RequestReply::setStatus(), and takeQueue().
Referenced by cmlabs::Register_RequestGateway_Tests().
|
protected |
Owner id for logging.
Definition at line 286 of file RequestClient.h.
|
protected |
Guards ::requestQ.
Definition at line 285 of file RequestClient.h.
Referenced by addRequest(), completeRequest(), getNextRequest(), getNextTimedoutRequest(), removeStaleRequests(), takeQueue(), toJSON(), toXML(), and ~RequestQueue().
|
protected |
The ordered pending requests.
Definition at line 284 of file RequestClient.h.
Referenced by addRequest(), completeRequest(), getCount(), getNextRequest(), getNextTimedoutRequest(), removeStaleRequests(), takeQueue(), toJSON(), toXML(), and ~RequestQueue().