NCBI C++ ToolKit
|
Search Toolkit Book for CPSG_EventLoop
A class derived from the queue class that additionally allows to run event loop. More...
#include <objtools/pubseq_gateway/client/psg_client.hpp>
Public Types | |
using | TItemComplete = function< void(EPSG_Status, const shared_ptr< CPSG_ReplyItem > &)> |
using | TReplyComplete = function< void(EPSG_Status, const shared_ptr< CPSG_Reply > &)> |
using | TNewItem = function< void(const shared_ptr< CPSG_ReplyItem > &)> |
Public Types inherited from CPSG_Queue | |
using | TApiLock = shared_ptr< void > |
Get an API lock. More... | |
Public Member Functions | |
CPSG_EventLoop () | |
Creates an uninitialized instance. More... | |
CPSG_EventLoop (const string &service, TItemComplete item_complete, TReplyComplete reply_complete, TNewItem new_item=nullptr) | |
bool | IsEmpty () const |
Check whether the queue was stopped/reset, is now empty and all processing is complete. More... | |
bool | RunOnce (CDeadline deadline) |
Wait once for events in the queue and process any. More... | |
bool | Run (CDeadline deadline) |
Process everything in the queue until it's empty or times out. More... | |
CPSG_EventLoop (CPSG_EventLoop &&) | |
CPSG_EventLoop & | operator= (CPSG_EventLoop &&) |
Public Member Functions inherited from CPSG_Queue | |
CPSG_Queue () | |
Creates an uninitialized instance. More... | |
CPSG_Queue (const string &service) | |
~CPSG_Queue () | |
bool | SendRequest (shared_ptr< CPSG_Request > request, CDeadline deadline) |
Push request into the queue. More... | |
shared_ptr< CPSG_Reply > | GetNextReply (CDeadline deadline) |
Get the next reply which has started arriving from the server. More... | |
shared_ptr< CPSG_Reply > | SendRequestAndGetReply (shared_ptr< CPSG_Request > request, CDeadline deadline) |
Push request into the queue and get corresponding reply. More... | |
bool | WaitForEvents (CDeadline deadline) |
Wait for events on this queue, on replies returned by this queue and/or on reply items returned by the replies returned by this queue. More... | |
void | Stop () |
Stop accepting new requests. More... | |
void | Reset () |
Stop accepting new requests and cancel all requests whose replies have not been returned yet. More... | |
bool | IsEmpty () const |
Check whether the queue was stopped/reset and is now empty. More... | |
bool | IsInitialized () const |
Check whether the queue has been initialized. More... | |
bool | RejectsRequests () const |
Is the queue in a state (possibly temporary) when requests get immediately rejected. More... | |
void | SetRequestFlags (CPSG_Request::TFlags request_flags) |
Set request flags. More... | |
void | SetUserArgs (SPSG_UserArgs user_args) |
Set arbitrary URL arguments to add to every request. More... | |
CPSG_Queue (CPSG_Queue &&) | |
CPSG_Queue & | operator= (CPSG_Queue &&) |
Private Attributes | |
TItemComplete | m_ItemComplete |
TReplyComplete | m_ReplyComplete |
TNewItem | m_NewItem |
list< pair< shared_ptr< CPSG_Reply >, list< shared_ptr< CPSG_ReplyItem > > > > | m_Replies |
Additional Inherited Members | |
Static Public Member Functions inherited from CPSG_Queue | |
static TApiLock | GetApiLock () |
A class derived from the queue class that additionally allows to run event loop.
Call SendRequest() (possibly from other threads) to add requests to the queue. Call RunOnce() to run the event loop once, use IsEmpty() to check if all processing is complete. Or, call Run() to run the event loop until all processing is complete.
NOTE: Requests can be added to the queue at any time, including in parallel with calling Run() and RunOnce() methods of the event loop. However, do remember to call Stop() once all required requests have been added to the queue as this will help the event loop to stop promptly, as soon as all submitted requests have been processed.
Derived (the event loop) part of the instance is not MT-safe, one event loop cannot be run by multiple threads. Base class methods are MT-safe.
The queue base can be used by more than one thread, usually to add requests and stop the queue after. If needed, it can also be used to wait for events and to manually retrieve replies. Manually retrieved replies will not be processed by the event loop though.
Results for the requests which were pushed into a given instance will be processed using this (and only this) instance regardless of which threads were used to push the requests.
If more than one request was pushed into the instance, then the replies to all of the requests may come, in any order.
Definition at line 1292 of file psg_client.hpp.
using CPSG_EventLoop::TItemComplete = function<void(EPSG_Status, const shared_ptr<CPSG_ReplyItem>&)> |
Definition at line 1295 of file psg_client.hpp.
using CPSG_EventLoop::TNewItem = function<void(const shared_ptr<CPSG_ReplyItem>&)> |
Definition at line 1297 of file psg_client.hpp.
using CPSG_EventLoop::TReplyComplete = function<void(EPSG_Status, const shared_ptr<CPSG_Reply>&)> |
Definition at line 1296 of file psg_client.hpp.
|
default |
Creates an uninitialized instance.
It allows to postpone queue initialization until later. The uninitialized instances can then be initialized using regular constructor and move assignment operator.
CPSG_EventLoop::CPSG_EventLoop | ( | const string & | service, |
TItemComplete | item_complete, | ||
TReplyComplete | reply_complete, | ||
TNewItem | new_item = nullptr |
||
) |
service | Either a name of service (which can be resolved into a set of PSG servers) or a single fixed PSG server (in format "host:port") or empty value to use one from configuration file/environment/default. |
item_complete | Mandatory user callback to call when an item is complete (i.e. not eInProgress) |
reply_complete | Mandatory user callback to call when a reply and all its items are complete |
new_item | Optional user callback to call when new item arrives |
Definition at line 1529 of file psg_client.cpp.
References m_ItemComplete, m_ReplyComplete, and NCBI_THROW.
|
default |
|
inline |
Check whether the queue was stopped/reset, is now empty and all processing is complete.
Definition at line 1321 of file psg_client.hpp.
References CPSG_Queue::IsEmpty(), and m_Replies.
Referenced by Run().
|
default |
Process everything in the queue until it's empty or times out.
deadline | For how long to process events in the queue. |
Definition at line 1356 of file psg_client.hpp.
References IsEmpty(), and RunOnce().
Referenced by CParallelProcessing< TParams >::CParallelProcessing(), EventLoop(), and CProcessing::OneRequest().
Wait once for events in the queue and process any.
deadline | For how long to wait for events in the queue. |
Definition at line 1544 of file psg_client.cpp.
References CPSG_ReplyItem::eEndOfReply, eInProgress, CDeadline::eNoWait, CPSG_Queue::GetNextReply(), i, m_ItemComplete, m_NewItem, m_Replies, m_ReplyComplete, and CPSG_Queue::WaitForEvents().
Referenced by Run().
|
private |
Definition at line 1343 of file psg_client.hpp.
Referenced by CPSG_EventLoop(), and RunOnce().
|
private |
Definition at line 1345 of file psg_client.hpp.
Referenced by RunOnce().
|
private |
Definition at line 1346 of file psg_client.hpp.
|
private |
Definition at line 1344 of file psg_client.hpp.
Referenced by CPSG_EventLoop(), and RunOnce().