Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
database::ConnectionPool< ClientType > Class Template Reference

A thread-safe connection pool for managing reusable database client connections. More...

#include <ConnectionPool.hpp>

Inheritance diagram for database::ConnectionPool< ClientType >:
Collaboration diagram for database::ConnectionPool< ClientType >:

Public Types

using ClientFactory = std::function< std::shared_ptr< ClientType >()>
 

Public Member Functions

 ConnectionPool (size_t max_size, ClientFactory factory)
 Constructs a new ConnectionPool.
 
void init (std::function< void(std::shared_ptr< ClientType >, std::function< void(bool)>)> 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.
 

Detailed Description

template<typename ClientType>
class database::ConnectionPool< ClientType >

A thread-safe connection pool for managing reusable database client connections.

Template Parameters
ClientTypeThe type of database client to manage.

Member Typedef Documentation

◆ ClientFactory

template<typename ClientType >
using database::ConnectionPool< ClientType >::ClientFactory = std::function<std::shared_ptr<ClientType>()>

Constructor & Destructor Documentation

◆ ConnectionPool()

template<typename ClientType >
database::ConnectionPool< ClientType >::ConnectionPool ( size_t  max_size,
ClientFactory  factory 
)
inline

Constructs a new ConnectionPool.

Parameters
max_sizeThe maximum number of connections to maintain in the pool.
factoryA callable that creates new instances of ClientType.

Member Function Documentation

◆ acquire()

template<typename ClientType >
void database::ConnectionPool< ClientType >::acquire ( std::function< void(std::shared_ptr< ClientType >)>  callback)
inline

Acquires a database connection asynchronously from the pool.

Parameters
callbackCallback invoked with a shared pointer to a ready client when available.

◆ init()

template<typename ClientType >
void database::ConnectionPool< ClientType >::init ( std::function< void(std::shared_ptr< ClientType >, std::function< void(bool)>)>  connector,
std::function< void(bool success)>  on_ready 
)
inline

Initializes the pool by establishing the initial set of connections.

Parameters
connectorA function used to connect a client asynchronously.
on_readyCallback invoked when the pool is initialized. The parameter is true if initialization was successful.

◆ release()

template<typename ClientType >
void database::ConnectionPool< ClientType >::release ( std::shared_ptr< ClientType >  client)
inline

Releases a connection back to the pool.

Parameters
clientThe client to return to the pool.

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