|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
A thread-safe connection pool for managing reusable database client connections. More...
#include <ConnectionPool.hpp>


Public Types | |
| using | ClientFactory = std::function< std::shared_ptr< ClientType >()> |
| using | Connector = std::function< void(std::shared_ptr< ClientType >, std::function< void(bool)>)> |
Public Member Functions | |
| ConnectionPool (size_t max_size, ClientFactory factory, PoolOptions< ClientType > options={}) | |
| Constructs a new ConnectionPool. | |
| void | init (Connector connector, std::function< void(bool success)> on_ready) |
| Initializes the pool by establishing the initial set of connections. | |
| void | acquire (std::function< void(std::shared_ptr< ClientType >)> callback) |
| Acquires a database connection asynchronously from the pool. | |
| void | release (std::shared_ptr< ClientType > client) |
| Releases a connection back to the pool. | |
| size_t | idle_count () |
| Idle clients ready to be acquired. | |
| size_t | waiting_count () |
| Acquirers waiting for a client. | |
| size_t | reconnecting_count () |
| Replacements being connected (or waiting out a backoff). | |
Private Member Functions | |
| void | replace (std::chrono::milliseconds delay) |
Private Attributes | |
| size_t | max_size_ |
| ClientFactory | factory_ |
| PoolOptions< ClientType > | options_ |
| std::mutex | mutex_ |
| Connector | connector_ |
| size_t | reconnecting_ = 0 |
| std::queue< std::shared_ptr< ClientType > > | idle_connections_ |
| std::queue< std::function< void(std::shared_ptr< ClientType >)> > | wait_queue_ |
A thread-safe connection pool for managing reusable database client connections.
| ClientType | The type of database client to manage. |
| using orbit::database::ConnectionPool< ClientType >::ClientFactory = std::function<std::shared_ptr<ClientType>()> |
| using orbit::database::ConnectionPool< ClientType >::Connector = std::function<void(std::shared_ptr<ClientType>, std::function<void(bool)>)> |
|
inline |
Constructs a new ConnectionPool.
| max_size | The maximum number of connections to maintain in the pool. |
| factory | A callable that creates new instances of ClientType. |
| options | Health checking and reconnecting (off by default). |
|
inline |
Acquires a database connection asynchronously from the pool.
With a health check, an idle client that is no longer usable is dropped (and replaced in the background) rather than handed out.
| callback | Callback invoked with a shared pointer to a ready client when available. |
|
inline |
Idle clients ready to be acquired.
|
inline |
Initializes the pool by establishing the initial set of connections.
| connector | A function used to connect a client asynchronously. |
| on_ready | Callback invoked when the pool is initialized. The parameter is true if initialization was successful. With a health check, connections that failed are retried in the background. |
|
inline |
Replacements being connected (or waiting out a backoff).
|
inline |
Releases a connection back to the pool.
With a health check, a client that is no longer usable is dropped and a replacement is connected in the background.
| client | The client to return to the pool. |
|
inlineprivate |
|
inline |
Acquirers waiting for a client.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |