pub struct ConnectionManager { /* private fields */ }Expand description
Central orchestrator for connection lifecycle management.
Wraps ClientConfig, EndpointList, ReconnectConfig,
AtomicConnectionState and ConnectionHealth.
Implementations§
Source§impl ConnectionManager
impl ConnectionManager
Sourcepub fn new(
config: ClientConfig,
endpoints: EndpointList,
reconnect_config: ReconnectConfig,
) -> Self
pub fn new( config: ClientConfig, endpoints: EndpointList, reconnect_config: ReconnectConfig, ) -> Self
Create a new manager from config and endpoints.
Sourcepub fn with_primary(config: ClientConfig) -> Self
pub fn with_primary(config: ClientConfig) -> Self
Convenience: create with a single primary endpoint.
Sourcepub fn with_health_check_interval(self, interval: Duration) -> Self
pub fn with_health_check_interval(self, interval: Duration) -> Self
Set the health-check interval.
Sourcepub fn on_state_change<F>(&self, f: F)
pub fn on_state_change<F>(&self, f: F)
Set a state-change callback.
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
Current connection state (lock-free).
Sourcepub fn health(&self) -> ConnectionHealth
pub fn health(&self) -> ConnectionHealth
Snapshot of connection health.
Sourcepub fn active_endpoint(&self) -> Option<String>
pub fn active_endpoint(&self) -> Option<String>
URL of the currently active endpoint, if any.
Sourcepub fn endpoints(&self) -> EndpointList
pub fn endpoints(&self) -> EndpointList
Reference to endpoint list (read-locked).
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Client config reference.
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Initiate a connection attempt.
Walks the endpoint list in priority order. On the first success the
state transitions to Connected. If all endpoints fail, the state
moves to Failed.
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Cleanly disconnect and reset state.
Sourcepub async fn failover(&self) -> Result<String>
pub async fn failover(&self) -> Result<String>
Manually trigger a failover to the next endpoint.
Sourcepub fn enable_auto_reconnect(&self)
pub fn enable_auto_reconnect(&self)
Enable automatic reconnection.
Sourcepub fn disable_auto_reconnect(&self)
pub fn disable_auto_reconnect(&self)
Disable automatic reconnection.
Sourcepub fn is_auto_reconnect_enabled(&self) -> bool
pub fn is_auto_reconnect_enabled(&self) -> bool
Whether auto-reconnect is currently enabled.
Sourcepub async fn reconnect_loop(&self) -> Result<()>
pub async fn reconnect_loop(&self) -> Result<()>
Run the reconnection loop (usually spawned as a background task).
Tries endpoints with exponential backoff until success or
max_attempts is exhausted.
Sourcepub async fn check_health(&self) -> Result<()>
pub async fn check_health(&self) -> Result<()>
Run a single health check against the active endpoint.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConnectionManager
impl !RefUnwindSafe for ConnectionManager
impl Send for ConnectionManager
impl Sync for ConnectionManager
impl Unpin for ConnectionManager
impl UnsafeUnpin for ConnectionManager
impl !UnwindSafe for ConnectionManager
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.