Skip to main content

appcore_gateway/
resolver.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: resolver.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/07/26 08:53:09 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/07/26 08:53:09 by dnettoRaw
8//      ###########      S: 1.0.1-rc.8
9// =============================================================================
10
11//! Capability resolver to locate appropriate workers.
12
13use crate::connection::WorkerConnectionKey;
14use crate::registry::CapabilityRegistry;
15use appcore_types::CapabilityName;
16
17/// Strategy to choose one worker from multiple candidates.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum SelectionPolicy {
20    /// Always picks the first available candidate.
21    FirstAvailable,
22}
23
24/// Resolves worker targets for capability requests within a tenant partition.
25#[derive(Debug, Clone)]
26pub struct CapabilityResolver {
27    policy: SelectionPolicy,
28}
29
30impl Default for CapabilityResolver {
31    fn default() -> Self {
32        Self {
33            policy: SelectionPolicy::FirstAvailable,
34        }
35    }
36}
37
38impl CapabilityResolver {
39    /// Creates a resolver with the default selection policy.
40    pub fn new() -> Self {
41        Self::default()
42    }
43
44    /// Resolves a worker connection key for a given capability using the registry.
45    pub fn resolve(
46        &self,
47        capability: &CapabilityName,
48        registry: &CapabilityRegistry,
49    ) -> Option<WorkerConnectionKey> {
50        let candidates = registry.resolve(capability)?;
51        match self.policy {
52            SelectionPolicy::FirstAvailable => candidates.iter().next().cloned(),
53        }
54    }
55}