grafos_registry/
writer.rs

1//! Registry writer — mutating operations on the registry.
2
3extern crate alloc;
4use alloc::string::String;
5use alloc::vec::Vec;
6
7use grafos_std::error::Result;
8
9use crate::region::RegistryRegion;
10use crate::registration::{HealthStatus, ServiceRegistration};
11
12/// Write handle for the service registry.
13///
14/// Provides register, update, deregister, and health-management operations.
15/// All mutations bump the registry version for watcher notification.
16pub struct RegistryWriter {
17    region: RegistryRegion,
18}
19
20impl RegistryWriter {
21    /// Create a writer wrapping the given region.
22    pub fn new(region: RegistryRegion) -> Self {
23        RegistryWriter { region }
24    }
25
26    /// Register a service instance.
27    pub fn register(&mut self, reg: ServiceRegistration) -> Result<()> {
28        self.region.register(reg)
29    }
30
31    /// Remove a specific instance from the registry.
32    pub fn deregister(&mut self, name: &str, instance_id: u128) -> Result<bool> {
33        self.region.deregister(name, instance_id)
34    }
35
36    /// Update the health status of a specific instance.
37    pub fn set_health(
38        &mut self,
39        name: &str,
40        instance_id: u128,
41        health: HealthStatus,
42    ) -> Result<bool> {
43        self.region.set_health(name, instance_id, health)
44    }
45
46    /// Set a specific instance to draining.
47    pub fn set_draining(&mut self, name: &str, instance_id: u128) -> Result<bool> {
48        self.region.set_draining(name, instance_id)
49    }
50
51    /// Prune expired registrations. Returns the number pruned.
52    pub fn tick(&mut self) -> Result<usize> {
53        self.region.tick()
54    }
55
56    /// Return the current registry version.
57    pub fn version(&self) -> u64 {
58        self.region.version()
59    }
60
61    /// Look up registrations (convenience — delegates to the underlying region).
62    pub fn lookup(&self, name: &str) -> Result<Vec<ServiceRegistration>> {
63        self.region.lookup(name)
64    }
65
66    /// List all service names (convenience).
67    pub fn list_services(&self) -> Result<Vec<String>> {
68        self.region.list_services()
69    }
70}