pub struct DiscoveryService { /* private fields */ }Expand description
Discovery service for finding Mecha10 nodes
§Examples
ⓘ
use mecha10_cli::services::{DiscoveryService, DiscoveryConfig};
let service = DiscoveryService::new();
// Configure discovery
let config = DiscoveryConfig::default();
// Discover nodes
let nodes = service.discover(&config).await?;
for node in nodes {
println!("Found node: {} at {}:{}", node.node_id, node.host, node.port);
}
// Monitor for new nodes
service.monitor(&config, |node| {
println!("New node discovered: {}", node.node_id);
}).await?;Implementations§
Source§impl DiscoveryService
impl DiscoveryService
Sourcepub async fn monitor<F>(
&mut self,
config: &DiscoveryConfig,
callback: F,
) -> Result<()>
pub async fn monitor<F>( &mut self, config: &DiscoveryConfig, callback: F, ) -> Result<()>
Monitor for new nodes
§Arguments
config- Discovery configurationcallback- Function to call when a new node is discovered
Sourcepub fn cleanup_stale_nodes(&mut self, timeout: Duration) -> usize
pub fn cleanup_stale_nodes(&mut self, timeout: Duration) -> usize
Remove stale nodes that haven’t sent heartbeats
§Arguments
timeout- Maximum time since last heartbeat
Sourcepub async fn announce(
&self,
config: &DiscoveryConfig,
node_info: &NodeInfo,
) -> Result<()>
pub async fn announce( &self, config: &DiscoveryConfig, node_info: &NodeInfo, ) -> Result<()>
Broadcast presence announcement
§Arguments
config- Discovery configurationnode_info- Information about this node
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get node count
Sourcepub fn get_nodes_by_type(&self, node_type: &str) -> Vec<&NodeInfo>
pub fn get_nodes_by_type(&self, node_type: &str) -> Vec<&NodeInfo>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DiscoveryService
impl RefUnwindSafe for DiscoveryService
impl Send for DiscoveryService
impl Sync for DiscoveryService
impl Unpin for DiscoveryService
impl UnwindSafe for DiscoveryService
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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