NCBI C++ ToolKit
|
Search Toolkit Book for CPSG_Queue
A queue to retrieve data (accession resolution info; bio-sequence; annotation blobs) from the storage. More...
#include <objtools/pubseq_gateway/client/psg_client.hpp>
Classes | |
struct | SImpl |
Public Types | |
using | TApiLock = shared_ptr< void > |
Get an API lock. More... | |
Public Member Functions | |
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 &&) |
Static Public Member Functions | |
static TApiLock | GetApiLock () |
Private Attributes | |
unique_ptr< SImpl > | m_Impl |
A queue to retrieve data (accession resolution info; bio-sequence; annotation blobs) from the storage.
Call SendRequest() to schedule retrievals (by their bio-ids or blob-ids). Then, call GetNextReply() to get the next reply whose data has started coming in.
All methods are MT-safe. Data from different replies can be read in parallel.
The queue object can be used from more than one thread, either to push requests or to get the incoming ready-to-be-retrieved replies.
Results for the requests which were pushed into a given instance of the queue will be available for retrieval using this (and only this) queue instance regardless of which threads were used to push the request to the queue.
If more than one request was pushed into the queue, then the replies to all of the requests may come, in any order.
Definition at line 1144 of file psg_client.hpp.
using CPSG_Queue::TApiLock = shared_ptr<void> |
Get an API lock.
Holding this API lock is essential if numerous short-lived queue instances are used. It prevents an internal I/O implementation (threads, TCP connections, HTTP sessions, etc) from being destroyed (on destroying last remaining queue instance) and then re-created (with new queue instance).
Definition at line 1248 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.
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. |
Definition at line 1446 of file psg_client.cpp.
|
default |
|
default |
|
static |
Definition at line 1519 of file psg_client.cpp.
References CPSG_Queue::SImpl::GetApiLock().
Referenced by CPsgCgiApp::Init(), and CPubseqGatewayApp::x_InitialzeZEndPointData().
shared_ptr< CPSG_Reply > CPSG_Queue::GetNextReply | ( | CDeadline | deadline | ) |
Get the next reply which has started arriving from the server.
deadline | Until what time to wait for the next reply to start coming in. |
If | an error has been detected. |
Definition at line 1457 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by CPSG_EventLoop::RunOnce().
bool CPSG_Queue::IsEmpty | ( | void | ) | const |
Check whether the queue was stopped/reset and is now empty.
Definition at line 1492 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by CPSG_EventLoop::IsEmpty().
|
inline |
Check whether the queue has been initialized.
Definition at line 1224 of file psg_client.hpp.
References m_Impl.
|
default |
bool CPSG_Queue::RejectsRequests | ( | ) | const |
Is the queue in a state (possibly temporary) when requests get immediately rejected.
Definition at line 1499 of file psg_client.cpp.
void CPSG_Queue::Reset | ( | void | ) |
Stop accepting new requests and cancel all requests whose replies have not been returned yet.
No requests are accepted and no replies are returned after the reset.
Definition at line 1485 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by CPSGL_Queue::~CPSGL_Queue().
bool CPSG_Queue::SendRequest | ( | shared_ptr< CPSG_Request > | request, |
CDeadline | deadline | ||
) |
Push request into the queue.
request | The request (containing either bio- or blob-id to retrieve) to send. |
deadline | For how long to try to push the request into the queue. |
CPSG_Exception | If any (non-timeout) error condition occures. |
Definition at line 1451 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by EventLoop(), CProcessing::OneRequest(), and CPSGL_Queue::SendRequest().
shared_ptr< CPSG_Reply > CPSG_Queue::SendRequestAndGetReply | ( | shared_ptr< CPSG_Request > | request, |
CDeadline | deadline | ||
) |
Push request into the queue and get corresponding reply.
request | The request to send. |
deadline | For how long to try to push the request into the queue. |
CPSG_Exception | If any (non-timeout) error condition occures. |
Definition at line 1466 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by CProcessing::Performance(), Queue(), CPSG_Queue::SImpl::SendRequest(), and CPubseqGatewayApp::x_SelfZEndPointCheckImpl().
void CPSG_Queue::SetRequestFlags | ( | CPSG_Request::TFlags | request_flags | ) |
Set request flags.
Definition at line 1506 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by CPSGDataLoader_Impl::CPSGDataLoader_Impl().
void CPSG_Queue::SetUserArgs | ( | SPSG_UserArgs | user_args | ) |
Set arbitrary URL arguments to add to every request.
Definition at line 1513 of file psg_client.cpp.
References m_Impl.
Referenced by CPSGDataLoader_Impl::CPSGDataLoader_Impl().
void CPSG_Queue::Stop | ( | void | ) |
Stop accepting new requests.
All already accepted requests will be processed as usual. No requests are accepted after the stop.
Definition at line 1472 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by EventLoop(), and CProcessing::OneRequest().
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.
deadline | For how long to wait for events in the queue. |
Definition at line 1479 of file psg_client.cpp.
References _ASSERT, and m_Impl.
Referenced by CPSG_EventLoop::RunOnce().
|
private |
Definition at line 1257 of file psg_client.hpp.
Referenced by CPSG_ReplyItem::GetNextMessage(), GetNextReply(), CPSG_ReplyItem::GetStatus(), IsEmpty(), IsInitialized(), RejectsRequests(), Reset(), SendRequest(), SendRequestAndGetReply(), SetRequestFlags(), SetUserArgs(), Stop(), and WaitForEvents().