Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
rpc::WorkQueue Class Reference

An asynchronous, thread-safe queue for RPC requests. More...

#include <WorkQueue.hpp>

Public Member Functions

 WorkQueue (std::uint32_t numWorkers, uint32_t maxSize=0)
 Create an we instance of the work queue.
 
void stop (std::function< void()> onQueueEmpty)
 Put the work queue into a stopping state. This will prevent new jobs from being queued.
 
template<typename FnType >
bool postCoro (FnType &&func, bool isWhiteListed)
 Submit a job to the work queue.
 
boost::json::object report () const
 Generate a report of the work queue state.
 
void join ()
 Wait until all the jobs in the queue are finished.
 
size_t size () const
 Get the size of the queue.
 

Static Public Member Functions

static WorkQueue makeWorkQueue (util::config::ClioConfigDefinition const &config)
 A factory function that creates the work queue based on a config.
 

Detailed Description

An asynchronous, thread-safe queue for RPC requests.

Constructor & Destructor Documentation

◆ WorkQueue()

rpc::WorkQueue::WorkQueue ( std::uint32_t numWorkers,
uint32_t maxSize = 0 )

Create an we instance of the work queue.

Parameters
numWorkersThe amount of threads to spawn in the pool
maxSizeThe maximum capacity of the queue; 0 means unlimited

Member Function Documentation

◆ makeWorkQueue()

WorkQueue rpc::WorkQueue::makeWorkQueue ( util::config::ClioConfigDefinition const & config)
static

A factory function that creates the work queue based on a config.

Parameters
configThe Clio config to use
Returns
The work queue

◆ postCoro()

template<typename FnType >
bool rpc::WorkQueue::postCoro ( FnType && func,
bool isWhiteListed )
inline

Submit a job to the work queue.

The job will be rejected if isWhiteListed is set to false and the current size of the queue reached capacity.

Template Parameters
FnTypeThe function object type
Parameters
funcThe function object to queue as a job
isWhiteListedWhether the queue capacity applies to this job
Returns
true if the job was successfully queued; false otherwise

◆ report()

boost::json::object rpc::WorkQueue::report ( ) const

Generate a report of the work queue state.

Returns
The report as a JSON object.

◆ size()

size_t rpc::WorkQueue::size ( ) const

Get the size of the queue.

Returns
The numver of jobs in the queue.

◆ stop()

void rpc::WorkQueue::stop ( std::function< void()> onQueueEmpty)

Put the work queue into a stopping state. This will prevent new jobs from being queued.

Parameters
onQueueEmptyA callback to run when the last task in the queue is completed

The documentation for this class was generated from the following files: