pub struct ClientSessionBuilder { /* private fields */ }Expand description
Builder for constructing ClientSession instances
Provides a fluent API for creating client sessions with different routing modes.
§Examples
use std::net::SocketAddr;
use std::sync::Arc;
use nntp_proxy::session::ClientSession;
use nntp_proxy::pool::BufferPool;
use nntp_proxy::router::BackendSelector;
use nntp_proxy::config::RoutingMode;
use nntp_proxy::types::BufferSize;
use nntp_proxy::auth::AuthHandler;
use nntp_proxy::metrics::MetricsCollector;
let addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
let buffer_pool = BufferPool::new(BufferSize::try_new(8192).unwrap(), 10);
let auth_handler = Arc::new(AuthHandler::new(None, None).unwrap());
let metrics = MetricsCollector::new(1);
// Stateful 1:1 routing mode
let session = ClientSession::builder(addr.into(), buffer_pool.clone(), auth_handler.clone(), metrics.clone())
.build();
// Per-command routing mode
let router = Arc::new(BackendSelector::new());
let session = ClientSession::builder(addr.into(), buffer_pool.clone(), auth_handler, metrics)
.with_router(router)
.with_routing_mode(RoutingMode::PerCommand)
.build();Implementations§
Source§impl ClientSessionBuilder
impl ClientSessionBuilder
Sourcepub fn with_router(self, router: Arc<BackendSelector>) -> Self
pub fn with_router(self, router: Arc<BackendSelector>) -> Self
Configure the session to use per-command routing with a backend router
When a router is provided, the session will route each command independently to potentially different backend servers.
Sourcepub const fn with_routing_mode(self, mode: RoutingMode) -> Self
pub const fn with_routing_mode(self, mode: RoutingMode) -> Self
Set the routing mode for this session
§Arguments
mode- The routing mode (Stateful,PerCommand, or Hybrid)
Note: If you use with_router(), you typically want PerCommand or Hybrid mode.
Sourcepub fn with_auth_handler(self, auth_handler: Arc<AuthHandler>) -> Self
pub fn with_auth_handler(self, auth_handler: Arc<AuthHandler>) -> Self
Set the authentication handler
Sourcepub fn with_connection_stats(
self,
connection_stats: ConnectionStatsAggregator,
) -> Self
pub fn with_connection_stats( self, connection_stats: ConnectionStatsAggregator, ) -> Self
Add connection stats aggregation to this session
Sourcepub fn with_cache(self, cache: Arc<UnifiedCache>) -> Self
pub fn with_cache(self, cache: Arc<UnifiedCache>) -> Self
Add article cache to this session (always present for backend availability tracking)
Sourcepub const fn with_cache_articles(self, cache: bool) -> Self
pub const fn with_cache_articles(self, cache: bool) -> Self
Set whether to cache article bodies.
When false, only backend availability is tracked (saves memory). When true, full article bodies are cached.
Sourcepub const fn with_adaptive_precheck(self, enable: bool) -> Self
pub const fn with_adaptive_precheck(self, enable: bool) -> Self
Configure adaptive availability prechecking
Sourcepub fn build(self) -> ClientSession
pub fn build(self) -> ClientSession
Build the client session
Creates a new ClientSession with a unique client ID and the configured
routing mode.
Auto Trait Implementations§
impl !RefUnwindSafe for ClientSessionBuilder
impl !UnwindSafe for ClientSessionBuilder
impl Freeze for ClientSessionBuilder
impl Send for ClientSessionBuilder
impl Sync for ClientSessionBuilder
impl Unpin for ClientSessionBuilder
impl UnsafeUnpin for ClientSessionBuilder
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> 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