pub struct DeadpoolConnectionProvider {
pub health_check_metrics: Arc<HealthCheckMetrics>,
/* private fields */
}Expand description
Connection provider using deadpool for connection pooling
Fields§
§health_check_metrics: Arc<HealthCheckMetrics>Metrics for health check operations (lock-free)
Implementations§
Source§impl DeadpoolConnectionProvider
impl DeadpoolConnectionProvider
Sourcepub fn builder(host: impl Into<String>, port: u16) -> Builder
pub fn builder(host: impl Into<String>, port: u16) -> Builder
Create a builder for constructing a connection provider
§Examples
use nntp_proxy::pool::DeadpoolConnectionProvider;
let provider = DeadpoolConnectionProvider::builder("news.example.com", 119)
.name("Example")
.max_connections(15)
.build()
.unwrap();Sourcepub fn simple(host: impl Into<String>, port: u16) -> Result<Self>
pub fn simple(host: impl Into<String>, port: u16) -> Result<Self>
Create a simple connection provider with defaults
Useful for testing and simple use cases. Uses 10 connections, no auth.
§Examples
use nntp_proxy::pool::DeadpoolConnectionProvider;
let provider = DeadpoolConnectionProvider::simple("news.example.com", 119)?;§Errors
Returns any validation or pool-construction error from the builder.
Sourcepub fn with_auth(
host: impl Into<String>,
port: u16,
username: impl Into<String>,
password: impl Into<String>,
) -> Result<Self>
pub fn with_auth( host: impl Into<String>, port: u16, username: impl Into<String>, password: impl Into<String>, ) -> Result<Self>
Create a connection provider with authentication
Convenience constructor for the common case of username/password auth.
§Examples
use nntp_proxy::pool::DeadpoolConnectionProvider;
let provider = DeadpoolConnectionProvider::with_auth(
"news.example.com",
119,
"myuser",
"mypass",
)?;§Errors
Returns any validation or pool-construction error from the builder.
Sourcepub fn with_tls(host: impl Into<String>, port: u16) -> Result<Self>
pub fn with_tls(host: impl Into<String>, port: u16) -> Result<Self>
Create a TLS-enabled connection provider
Uses default TLS settings (verify certificates, system CA store). For NNTPS (port 563) or STARTTLS.
§Examples
use nntp_proxy::pool::DeadpoolConnectionProvider;
let provider = DeadpoolConnectionProvider::with_tls("news.example.com", 563)?;§Errors
Returns any TLS initialization, validation, or pool-construction error.
Sourcepub fn with_tls_auth(
host: impl Into<String>,
port: u16,
username: impl Into<String>,
password: impl Into<String>,
) -> Result<Self>
pub fn with_tls_auth( host: impl Into<String>, port: u16, username: impl Into<String>, password: impl Into<String>, ) -> Result<Self>
Create a TLS-enabled connection provider with authentication
Combines TLS with username/password auth - the most common setup for commercial Usenet providers.
§Examples
use nntp_proxy::pool::DeadpoolConnectionProvider;
let provider = DeadpoolConnectionProvider::with_tls_auth(
"news.example.com",
563,
"myuser",
"mypass",
)?;§Errors
Returns any TLS initialization, validation, or pool-construction error.
Sourcepub fn new(
host: String,
port: u16,
name: String,
max_size: usize,
username: Option<String>,
password: Option<String>,
) -> Self
pub fn new( host: String, port: u16, name: String, max_size: usize, username: Option<String>, password: Option<String>, ) -> Self
Create a new connection provider (plain TCP, no TLS)
For TLS support, use new_with_tls() or the builder API.
§Panics
Panics only if plain TcpManager construction unexpectedly becomes
fallible or deadpool rejects the requested pool size.
Sourcepub fn new_with_tls(
host: String,
port: u16,
name: String,
max_size: usize,
username: Option<String>,
password: Option<String>,
tls_config: TlsConfig,
) -> Result<Self>
pub fn new_with_tls( host: String, port: u16, name: String, max_size: usize, username: Option<String>, password: Option<String>, tls_config: TlsConfig, ) -> Result<Self>
Create a new connection provider with TLS support
§Errors
Returns any TLS initialization or provider-construction error.
Sourcepub fn from_server_config(
server: &Server,
recv_buffer_size: usize,
send_buffer_size: usize,
) -> Result<Self>
pub fn from_server_config( server: &Server, recv_buffer_size: usize, send_buffer_size: usize, ) -> Result<Self>
Sourcepub async fn get_pooled_connection(
&self,
) -> Result<Object<TcpManager>, ConnectionError>
pub async fn get_pooled_connection( &self, ) -> Result<Object<TcpManager>, ConnectionError>
Get a connection from the pool (automatically returned when dropped)
§Errors
Returns crate::connection_error::ConnectionError if deadpool cannot
provide a healthy backend connection.
Sourcepub fn clear_idle_connections(&self)
pub fn clear_idle_connections(&self)
Clear all idle connections from the pool
This drops all idle connections by resizing the pool to 0 and back. Active (checked-out) connections are not affected - they will be discarded when returned instead of being recycled.
Use this to clear potentially stale connections after an idle period.
Sourcepub fn remove_without_cooldown(&self, conn: Object<TcpManager>)
pub fn remove_without_cooldown(&self, conn: Object<TcpManager>)
Remove a connection without temporarily reducing pool size.
Use this when the connection cannot be safely returned to the pool, but the backend did not fail. For example, a client disconnect can leave unread backend response bytes in flight, making the socket dirty without implying that replacement connections should be throttled.
Sourcepub fn remove_with_cooldown(&self, conn: Object<TcpManager>)
pub fn remove_with_cooldown(&self, conn: Object<TcpManager>)
Remove a broken connection and temporarily reduce pool size.
Gives the backend time to release the old connection’s slot before deadpool creates a replacement. Prevents connection count from exceeding the backend’s limit during high churn.
If replacement_cooldown is None or Duration::ZERO (disabled), immediately drops
the connection without cooldown (behaves like normal pool removal).
CRITICAL: When cooldown is active, we resize the pool BEFORE dropping the
connection. Otherwise, between drop(conn) and pool.resize(), any waiter
calling pool.get() sees size < max_size and immediately creates a
replacement — defeating the cooldown entirely.
The ordering invariant is enforced at compile time: conn is moved into
either [shutdown_and_drop] or [resize_then_drop], so the caller cannot
accidentally drop(conn) before pool.resize(). Any attempt to reorder
would be a use-after-move error.
pub fn status_counts(&self) -> DeadpoolStatusCounts
Sourcepub fn health_check_metrics(&self) -> &HealthCheckMetrics
pub fn health_check_metrics(&self) -> &HealthCheckMetrics
Get a reference to the health check metrics
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Gracefully shutdown the periodic health check task
This sends a shutdown signal to the background health check task. The task will complete its current cycle and then terminate.
Sourcepub async fn graceful_shutdown(&self)
pub async fn graceful_shutdown(&self)
Gracefully shutdown the pool
Trait Implementations§
Source§impl Clone for DeadpoolConnectionProvider
impl Clone for DeadpoolConnectionProvider
Source§fn clone(&self) -> DeadpoolConnectionProvider
fn clone(&self) -> DeadpoolConnectionProvider
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConnectionProvider for DeadpoolConnectionProvider
impl ConnectionProvider for DeadpoolConnectionProvider
Source§fn status(&self) -> PoolStatus
fn status(&self) -> PoolStatus
Auto Trait Implementations§
impl !RefUnwindSafe for DeadpoolConnectionProvider
impl !UnwindSafe for DeadpoolConnectionProvider
impl Freeze for DeadpoolConnectionProvider
impl Send for DeadpoolConnectionProvider
impl Sync for DeadpoolConnectionProvider
impl Unpin for DeadpoolConnectionProvider
impl UnsafeUnpin for DeadpoolConnectionProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more