Skip to main content

ServiceRegistry

Struct ServiceRegistry 

Source
pub struct ServiceRegistry { /* private fields */ }
Expand description

Registry of system services with lifecycle management.

Uses DashMap for concurrent access from multiple kernel subsystems. Maintains two maps:

  • services: SystemService trait object implementations (existing)
  • entries: ServiceEntry metadata for service identity (D1, K2.1)

A service can have metadata before it has a running implementation (useful for external services), and vice versa.

Implementations§

Source§

impl ServiceRegistry

Source

pub fn new() -> Self

Create a new, empty service registry.

Source

pub fn register( &self, service: Arc<dyn SystemService>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register a service.

Returns an error if a service with the same name is already registered.

Source

pub fn unregister(&self, name: &str) -> Option<Arc<dyn SystemService>>

Unregister a service by name.

Source

pub fn get(&self, name: &str) -> Option<Arc<dyn SystemService>>

Get a service by name.

Source

pub fn list(&self) -> Vec<(String, ServiceType)>

List all registered services with their types.

Source

pub async fn start_all(&self) -> Result<(), Box<dyn Error + Send + Sync>>

Start all registered services.

Individual service failures are logged as warnings but do not prevent other services from starting.

Source

pub async fn stop_all(&self) -> Result<(), Box<dyn Error + Send + Sync>>

Stop all registered services.

Individual service failures are logged as warnings.

Source

pub fn snapshot(&self) -> Vec<(String, Arc<dyn SystemService>)>

Return a snapshot of all services as a Vec.

This copies all (name, Arc<dyn SystemService>) pairs out of the DashMap, so the returned collection owns no DashMap refs and is safe to hold across await points and send across threads.

Source

pub async fn health_all(&self) -> Vec<(String, HealthStatus)>

Run health checks on all registered services.

Source

pub fn register_entry( &self, entry: ServiceEntry, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register a service entry (metadata, not a running implementation).

Returns an error if an entry with the same name already exists.

Source

pub fn get_entry(&self, name: &str) -> Option<ServiceEntry>

Get a service entry by name.

Source

pub fn resolve_target(&self, name: &str) -> Option<Pid>

Resolve a service name to its owning agent PID.

Returns None if the service is not registered or has no owner_pid (e.g. external services).

Source

pub fn list_entries(&self) -> Vec<ServiceEntry>

List all registered service entries.

Source

pub fn unregister_entry(&self, name: &str) -> Option<ServiceEntry>

Remove a service entry by name.

Source

pub fn register_with_tree( &self, service: Arc<dyn SystemService>, tree_manager: &TreeManager, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register a service and create a resource tree node + chain event.

When the exochain feature is enabled and a tree manager is provided, creates a node at /kernel/services/{name} in the resource tree and appends a corresponding chain event via TreeManager.

Source

pub fn len(&self) -> usize

Get the number of registered services.

Source

pub fn is_empty(&self) -> bool

Check whether the registry is empty.

Source

pub fn register_with_contract( &self, service: Arc<dyn SystemService>, methods: Vec<String>, chain: &ChainManager, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register a service and automatically create a chain-anchored contract (C3).

This is the recommended registration path for K4+ services that want immutable API contracts stored on the ExoChain. It combines service registration, contract creation, and chain logging in one call.

Source

pub fn register_contract( &self, contract: &ServiceContract, chain: &ChainManager, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register a service contract and log it to the chain (K2 C3, K4 G2).

A service contract is a versioned interface declaration that is anchored in the ExoChain for immutability. Once a contract version is registered, it cannot be changed — only superseded by a new version.

Trait Implementations§

Source§

impl Default for ServiceRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Registry for ServiceRegistry

Source§

type Value = Arc<dyn SystemService>

The value returned by get. Read more
Source§

fn get(&self, key: &str) -> Option<Self::Value>

Look up a value by its string key.
Source§

fn list_keys(&self) -> Vec<String>

Return all keys currently in the registry. Read more
Source§

fn contains(&self, key: &str) -> bool

Check whether key is present. Read more
Source§

fn count(&self) -> usize

Number of entries in the registry.
Source§

fn is_empty(&self) -> bool

Whether the registry is empty.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more