NCBI C++ ToolKit
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
CPSG_Queue Class Reference

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>

+ Inheritance diagram for CPSG_Queue:

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_ReplyGetNextReply (CDeadline deadline)
 Get the next reply which has started arriving from the server. More...
 
shared_ptr< CPSG_ReplySendRequestAndGetReply (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_Queueoperator= (CPSG_Queue &&)
 

Static Public Member Functions

static TApiLock GetApiLock ()
 

Private Attributes

unique_ptr< SImplm_Impl
 

Detailed Description

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.

Member Typedef Documentation

◆ TApiLock

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.

Constructor & Destructor Documentation

◆ CPSG_Queue() [1/3]

CPSG_Queue::CPSG_Queue ( )
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_Queue() [2/3]

CPSG_Queue::CPSG_Queue ( const string service)
Parameters
serviceEither 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.

◆ ~CPSG_Queue()

CPSG_Queue::~CPSG_Queue ( )
default

◆ CPSG_Queue() [3/3]

CPSG_Queue::CPSG_Queue ( CPSG_Queue &&  )
default

Member Function Documentation

◆ GetApiLock()

CPSG_Queue::TApiLock CPSG_Queue::GetApiLock ( )
static

◆ GetNextReply()

shared_ptr< CPSG_Reply > CPSG_Queue::GetNextReply ( CDeadline  deadline)

Get the next reply which has started arriving from the server.

Parameters
deadlineUntil what time to wait for the next reply to start coming in.
Returns
  • Reply object from which you can obtain particular items.
  • On expired timeout, the returned pointer will be empty (nullptr).
Exceptions
Ifan error has been detected.

Definition at line 1457 of file psg_client.cpp.

References _ASSERT, and m_Impl.

Referenced by CPSG_EventLoop::RunOnce().

◆ IsEmpty()

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().

◆ IsInitialized()

bool CPSG_Queue::IsInitialized ( void  ) const
inline

Check whether the queue has been initialized.

Definition at line 1224 of file psg_client.hpp.

References m_Impl.

◆ operator=()

CPSG_Queue & CPSG_Queue::operator= ( CPSG_Queue &&  )
default

◆ RejectsRequests()

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.

References _ASSERT, and m_Impl.

◆ Reset()

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().

◆ SendRequest()

bool CPSG_Queue::SendRequest ( shared_ptr< CPSG_Request request,
CDeadline  deadline 
)

Push request into the queue.

Parameters
requestThe request (containing either bio- or blob-id to retrieve) to send.
deadlineFor how long to try to push the request into the queue.
Returns
  • TRUE if it succeeds in pushing the request into the queue
  • FALSE on timeout (ie. if cannot do it before the specified deadline)
Exceptions
CPSG_ExceptionIf any (non-timeout) error condition occures.
See also
Get()

Definition at line 1451 of file psg_client.cpp.

References _ASSERT, and m_Impl.

Referenced by EventLoop(), CProcessing::OneRequest(), and CPSGL_Queue::SendRequest().

◆ SendRequestAndGetReply()

shared_ptr< CPSG_Reply > CPSG_Queue::SendRequestAndGetReply ( shared_ptr< CPSG_Request request,
CDeadline  deadline 
)

Push request into the queue and get corresponding reply.

Parameters
requestThe request to send.
deadlineFor how long to try to push the request into the queue.
Returns
  • Reply object from which you can obtain particular items.
  • On expired timeout, the returned pointer will be empty (nullptr).
Exceptions
CPSG_ExceptionIf 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().

◆ SetRequestFlags()

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().

◆ SetUserArgs()

void CPSG_Queue::SetUserArgs ( SPSG_UserArgs  user_args)

Set arbitrary URL arguments to add to every request.

queue.SetUserArgs("param1=value1&param1=value2&param2=value3");
queue.SetUserArgs({{ "param1", { "value1", "value2" }}, { "param2", { "value3" }}});

Definition at line 1513 of file psg_client.cpp.

References m_Impl.

Referenced by CPSGDataLoader_Impl::CPSGDataLoader_Impl().

◆ Stop()

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().

◆ WaitForEvents()

bool CPSG_Queue::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.

Parameters
deadlineFor 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().

Member Data Documentation

◆ m_Impl

unique_ptr<SImpl> CPSG_Queue::m_Impl
private

The documentation for this class was generated from the following files:
Modified on Fri Sep 20 14:57:24 2024 by modify_doxy.py rev. 669887