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

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>

+ Inheritance diagram for CPSG_EventLoop:
+ Collaboration diagram for CPSG_EventLoop:

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_EventLoopoperator= (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_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 &&)
 

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

Detailed Description

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.

Member Typedef Documentation

◆ TItemComplete

using CPSG_EventLoop::TItemComplete = function<void(EPSG_Status, const shared_ptr<CPSG_ReplyItem>&)>

Definition at line 1295 of file psg_client.hpp.

◆ TNewItem

using CPSG_EventLoop::TNewItem = function<void(const shared_ptr<CPSG_ReplyItem>&)>

Definition at line 1297 of file psg_client.hpp.

◆ TReplyComplete

using CPSG_EventLoop::TReplyComplete = function<void(EPSG_Status, const shared_ptr<CPSG_Reply>&)>

Definition at line 1296 of file psg_client.hpp.

Constructor & Destructor Documentation

◆ CPSG_EventLoop() [1/3]

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

CPSG_EventLoop::CPSG_EventLoop ( const string service,
TItemComplete  item_complete,
TReplyComplete  reply_complete,
TNewItem  new_item = nullptr 
)
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.
item_completeMandatory user callback to call when an item is complete (i.e. not eInProgress)
reply_completeMandatory user callback to call when a reply and all its items are complete
new_itemOptional 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.

◆ CPSG_EventLoop() [3/3]

CPSG_EventLoop::CPSG_EventLoop ( CPSG_EventLoop &&  )
default

Member Function Documentation

◆ IsEmpty()

bool CPSG_EventLoop::IsEmpty ( void  ) const
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().

◆ operator=()

CPSG_EventLoop & CPSG_EventLoop::operator= ( CPSG_EventLoop &&  )
default

◆ Run()

bool CPSG_EventLoop::Run ( CDeadline  deadline)
inline

Process everything in the queue until it's empty or times out.

Parameters
deadlineFor how long to process events in the queue.
Returns
  • TRUE if everything has been processed
  • FALSE on timeout (i.e. if it's still not empty before the specified deadline)

Definition at line 1356 of file psg_client.hpp.

References IsEmpty(), and RunOnce().

Referenced by CParallelProcessing< TParams >::CParallelProcessing(), EventLoop(), and CProcessing::OneRequest().

◆ RunOnce()

bool CPSG_EventLoop::RunOnce ( CDeadline  deadline)

Wait once for events in the queue and process any.

Parameters
deadlineFor how long to wait for events in the queue.
Returns
  • TRUE if there have been some events
  • FALSE on timeout (i.e. if there have been no events before the specified deadline)

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

Member Data Documentation

◆ m_ItemComplete

TItemComplete CPSG_EventLoop::m_ItemComplete
private

Definition at line 1343 of file psg_client.hpp.

Referenced by CPSG_EventLoop(), and RunOnce().

◆ m_NewItem

TNewItem CPSG_EventLoop::m_NewItem
private

Definition at line 1345 of file psg_client.hpp.

Referenced by RunOnce().

◆ m_Replies

list<pair<shared_ptr<CPSG_Reply>, list<shared_ptr<CPSG_ReplyItem> > > > CPSG_EventLoop::m_Replies
private

Definition at line 1346 of file psg_client.hpp.

Referenced by IsEmpty(), and RunOnce().

◆ m_ReplyComplete

TReplyComplete CPSG_EventLoop::m_ReplyComplete
private

Definition at line 1344 of file psg_client.hpp.

Referenced by CPSG_EventLoop(), and RunOnce().


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