pub struct ModelSwitcher { /* private fields */ }Expand description
The model switcher coordinates wake/sleep transitions
Implementations§
Source§impl ModelSwitcher
impl ModelSwitcher
Sourcepub fn new(
orchestrator: Arc<Orchestrator>,
policy: Box<dyn SwitchPolicy>,
) -> Self
pub fn new( orchestrator: Arc<Orchestrator>, policy: Box<dyn SwitchPolicy>, ) -> Self
Create a new model switcher
Sourcepub async fn state(&self) -> SwitcherState
pub async fn state(&self) -> SwitcherState
Get the current state
Sourcepub async fn active_model(&self) -> Option<String>
pub async fn active_model(&self) -> Option<String>
Get the currently active model
Sourcepub async fn mode(&self) -> SwitchMode
pub async fn mode(&self) -> SwitchMode
Get the current switch mode
Sourcepub async fn set_mode(&self, mode: SwitchMode)
pub async fn set_mode(&self, mode: SwitchMode)
Set the switch mode
Sourcepub fn registered_models(&self) -> Vec<String>
pub fn registered_models(&self) -> Vec<String>
Get the list of registered model names
Sourcepub fn orchestrator(&self) -> &Arc<Orchestrator>
pub fn orchestrator(&self) -> &Arc<Orchestrator>
Get access to the orchestrator (for process state queries)
Sourcepub fn policy_eviction(&self) -> EvictionPolicy
pub fn policy_eviction(&self) -> EvictionPolicy
Get the policy’s default eviction policy
Sourcepub async fn force_switch(&self, model: &str) -> Result<(), SwitchError>
pub async fn force_switch(&self, model: &str) -> Result<(), SwitchError>
Force a switch to the given model, bypassing policy.
Reuses the full do_switch machinery (drain, sleep, wake) so all
safety guarantees still apply. Returns after the switch completes.
Sourcepub fn is_registered(&self, model: &str) -> bool
pub fn is_registered(&self, model: &str) -> bool
Check if a model is registered
Sourcepub fn in_flight_count(&self, model: &str) -> usize
pub fn in_flight_count(&self, model: &str) -> usize
Get in-flight count for a model
Sourcepub async fn ensure_model_ready(&self, model: &str) -> Result<(), SwitchError>
pub async fn ensure_model_ready(&self, model: &str) -> Result<(), SwitchError>
Ensure a model is ready for requests
This will:
- Return immediately if the model is already active
- In manual mode: reject if model doesn’t match pinned/active model
- Queue the request and trigger a switch if needed
- Wait for the switch to complete (up to timeout)
Sourcepub fn acquire_in_flight(&self, model: &str) -> Option<InFlightGuard>
pub fn acquire_in_flight(&self, model: &str) -> Option<InFlightGuard>
Acquire an in-flight guard.
Returns None if the model is not registered or if the model is
currently draining (about to be put to sleep). Uses increment-then-check
to close the TOCTOU window between notify_pending and the drain in
do_switch.
Sourcepub async fn queue_depths(&self) -> HashMap<String, usize>
pub async fn queue_depths(&self) -> HashMap<String, usize>
Get the queue depth for every registered model.
Sourcepub fn spawn_scheduler(self) -> Option<JoinHandle<()>>
pub fn spawn_scheduler(self) -> Option<JoinHandle<()>>
Spawn a background scheduler task if the policy requests one.
Returns Some(JoinHandle) if the scheduler was spawned, None
if the policy does not use a scheduler (i.e. scheduler_interval
returns None).