pub trait ConnectionPool {
type NewConnectionConfig: NewConnectionConfig;
type BaseClientConnection: BaseClientConnection;
// Required methods
fn add_connection(
&mut self,
config: &Self::NewConnectionConfig,
addr: &SocketAddr
);
fn num_connections(&self) -> usize;
fn get(
&self,
index: usize
) -> Result<Arc<Self::BaseClientConnection>, ConnectionPoolError>;
fn create_pool_entry(
&self,
config: &Self::NewConnectionConfig,
addr: &SocketAddr
) -> Arc<Self::BaseClientConnection>;
// Provided methods
fn borrow_connection(&self) -> Arc<Self::BaseClientConnection> { ... }
fn need_new_connection(&self, required_pool_size: usize) -> bool { ... }
}
Required Associated Types§
type NewConnectionConfig: NewConnectionConfig
type BaseClientConnection: BaseClientConnection
Required Methods§
sourcefn add_connection(
&mut self,
config: &Self::NewConnectionConfig,
addr: &SocketAddr
)
fn add_connection( &mut self, config: &Self::NewConnectionConfig, addr: &SocketAddr )
Add a connection to the pool
sourcefn num_connections(&self) -> usize
fn num_connections(&self) -> usize
Get the number of current connections in the pool
sourcefn get(
&self,
index: usize
) -> Result<Arc<Self::BaseClientConnection>, ConnectionPoolError>
fn get( &self, index: usize ) -> Result<Arc<Self::BaseClientConnection>, ConnectionPoolError>
Get a connection based on its index in the pool, without checking if the
fn create_pool_entry( &self, config: &Self::NewConnectionConfig, addr: &SocketAddr ) -> Arc<Self::BaseClientConnection>
Provided Methods§
sourcefn borrow_connection(&self) -> Arc<Self::BaseClientConnection>
fn borrow_connection(&self) -> Arc<Self::BaseClientConnection>
Get a connection from the pool. It must have at least one connection in the pool. This randomly picks a connection in the pool.
sourcefn need_new_connection(&self, required_pool_size: usize) -> bool
fn need_new_connection(&self, required_pool_size: usize) -> bool
Check if we need to create a new connection. If the count of the connections is smaller than the pool size.