pub struct SessionManager { /* private fields */ }Expand description
Manages V8 sessions with concurrency limiting. Each session runs on a dedicated OS thread with its own V8 isolate.
Implementations§
Source§impl SessionManager
impl SessionManager
pub fn new( max_concurrency: usize, event_tx: impl Into<RuntimeEventSender>, call_id_router: CallIdRouter, snapshot_cache: Arc<SnapshotCache>, runtime: RuntimeContext, ) -> Self
Sourcepub fn snapshot_cache(&self) -> &Arc<SnapshotCache> ⓘ
pub fn snapshot_cache(&self) -> &Arc<SnapshotCache> ⓘ
Get the snapshot cache for pre-warming from WarmSnapshot messages.
pub fn pre_warm_workers( &self, bridge_code: String, userland_code: String, heap_limit_mb: Option<u32>, count: usize, )
Sourcepub fn create_session(
&mut self,
session_id: String,
heap_limit_mb: Option<u32>,
cpu_time_limit_ms: Option<u32>,
wall_clock_limit_ms: Option<u32>,
) -> Result<(), String>
pub fn create_session( &mut self, session_id: String, heap_limit_mb: Option<u32>, cpu_time_limit_ms: Option<u32>, wall_clock_limit_ms: Option<u32>, ) -> Result<(), String>
Create a new session. Spawns a dedicated admitted thread with a V8 isolate. Admission happens before thread creation; overload returns a typed limit error.
pub fn create_session_with_output_generation( &mut self, session_id: String, heap_limit_mb: Option<u32>, cpu_time_limit_ms: Option<u32>, wall_clock_limit_ms: Option<u32>, output_generation: Option<u64>, warm_hint: Option<WarmSessionHint>, ) -> Result<(), String>
pub fn create_session_with_output_generation_and_sender( &mut self, session_id: String, heap_limit_mb: Option<u32>, cpu_time_limit_ms: Option<u32>, wall_clock_limit_ms: Option<u32>, output_generation: Option<u64>, warm_hint: Option<WarmSessionHint>, event_tx: Option<RuntimeEventSender>, ) -> Result<(), String>
Sourcepub fn create_session_with_output_generation_sender_and_runtime(
&mut self,
session_id: String,
heap_limit_mb: Option<u32>,
cpu_time_limit_ms: Option<u32>,
wall_clock_limit_ms: Option<u32>,
output_generation: Option<u64>,
warm_hint: Option<WarmSessionHint>,
event_tx: Option<RuntimeEventSender>,
session_runtime: RuntimeContext,
ready_batch_handle_limit: usize,
bridge_call_timeout: Duration,
) -> Result<(), String>
pub fn create_session_with_output_generation_sender_and_runtime( &mut self, session_id: String, heap_limit_mb: Option<u32>, cpu_time_limit_ms: Option<u32>, wall_clock_limit_ms: Option<u32>, output_generation: Option<u64>, warm_hint: Option<WarmSessionHint>, event_tx: Option<RuntimeEventSender>, session_runtime: RuntimeContext, ready_batch_handle_limit: usize, bridge_call_timeout: Duration, ) -> Result<(), String>
Create a session whose guest-owned work and resource reservations are
charged to session_runtime. The manager’s own runtime remains the
process-scoped context used for shared snapshot and warm-pool work.
pub fn destroy_session_if_output_generation( &mut self, session_id: &str, output_generation: u64, ) -> Result<bool, String>
pub fn begin_destroy_session_if_output_generation( &mut self, session_id: &str, output_generation: u64, ) -> Result<Option<SessionShutdown>, String>
pub fn detach_session_if_output_generation( &mut self, session_id: &str, output_generation: u64, ) -> Result<bool, String>
Sourcepub fn destroy_session(&mut self, session_id: &str) -> Result<(), String>
pub fn destroy_session(&mut self, session_id: &str) -> Result<(), String>
Destroy a session inline. Joins the session thread before returning, so
this must not be called while a shared lock on the manager is held. Lock
holders use begin_destroy_session and call finish() after unlocking.
Sourcepub fn begin_destroy_session(
&mut self,
session_id: &str,
) -> Result<SessionShutdown, String>
pub fn begin_destroy_session( &mut self, session_id: &str, ) -> Result<SessionShutdown, String>
First phase of destroying a session: terminate execution, signal abort, send shutdown, clear call routes, and remove the entry. The returned shutdown joins the session thread and must be finished after the SessionManager lock is released.
Sourcepub fn session_command_sender(
&self,
session_id: &str,
msg: &SessionMessage,
) -> Result<(Sender<SessionCommand>, usize), String>
pub fn session_command_sender( &self, session_id: &str, msg: &SessionMessage, ) -> Result<(Sender<SessionCommand>, usize), String>
Resolve a session’s command sender and apply message side effects that must happen under the manager lock (isolate termination, abort signal). The caller sends on the returned channel after releasing the lock so a full command channel cannot block the manager mutex.
Sourcepub fn try_send_to_session(
&self,
session_id: &str,
msg: SessionMessage,
) -> Result<(), String>
pub fn try_send_to_session( &self, session_id: &str, msg: SessionMessage, ) -> Result<(), String>
Admit an ordinary message without ever blocking the thread that also
routes call-specific bridge responses. Readiness must use
publish_readiness; ordinary events are never reclassified by name.
pub fn publish_readiness( &self, session_id: &str, capability_id: u64, capability_generation: u64, flags: ReadyFlags, ) -> Result<(), String>
pub fn publish_signal( &self, session_id: &str, signal: i32, ) -> Result<(), String>
pub fn remove_readiness( &self, session_id: &str, capability_id: u64, capability_generation: u64, ) -> Result<(), String>
pub fn set_application_read_interest( &self, session_id: &str, capability_id: u64, capability_generation: u64, enabled: bool, ) -> Result<(), String>
pub fn publish_timer( &self, session_id: &str, timer_id: u64, ) -> Result<(), String>
Sourcepub fn session_sender(
&self,
session_id: &str,
) -> Result<(Sender<SessionCommand>, usize), String>
pub fn session_sender( &self, session_id: &str, ) -> Result<(Sender<SessionCommand>, usize), String>
Get a session’s command sender without a message (used for control commands like SetModuleReader that aren’t a SessionMessage). Dispatch-thread only.
Sourcepub fn pause_session(&self, session_id: &str) -> Result<(), String>
pub fn pause_session(&self, session_id: &str) -> Result<(), String>
Pause a session at the V8 execution boundary. A running synchronous
script is interrupted on its isolate thread and remains parked with its
JavaScript stack intact until resume_session is called.
pub fn resume_session(&self, session_id: &str) -> Result<(), String>
Sourcepub fn send_to_session(
&self,
session_id: &str,
msg: SessionMessage,
) -> Result<(), String>
pub fn send_to_session( &self, session_id: &str, msg: SessionMessage, ) -> Result<(), String>
Send a message to a session without blocking response/control progress.
Sourcepub fn destroy_sessions<I>(&mut self, session_ids: I)where
I: IntoIterator<Item = String>,
pub fn destroy_sessions<I>(&mut self, session_ids: I)where
I: IntoIterator<Item = String>,
Destroy a set of sessions inline, ignoring sessions that were already removed. Joins session threads, so this must not be called while a shared lock on the manager is held.
Sourcepub fn begin_destroy_sessions<I>(
&mut self,
session_ids: I,
) -> Vec<SessionShutdown>where
I: IntoIterator<Item = String>,
pub fn begin_destroy_sessions<I>(
&mut self,
session_ids: I,
) -> Vec<SessionShutdown>where
I: IntoIterator<Item = String>,
Begin destroying a set of sessions, ignoring sessions that were already removed. Finish each returned shutdown after releasing the manager lock.
Sourcepub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Number of registered sessions (including those waiting for a slot).
pub fn quarantined_session_count(&mut self) -> usize
Sourcepub fn all_sessions(&self) -> Vec<String>
pub fn all_sessions(&self) -> Vec<String>
Return all session IDs.
Sourcepub fn active_slot_count(&self) -> usize
pub fn active_slot_count(&self) -> usize
Number of sessions that have acquired a concurrency slot.
pub fn session_output_generation(&self, session_id: &str) -> Option<u64>
Sourcepub fn call_id_router(&self) -> &CallIdRouter
pub fn call_id_router(&self) -> &CallIdRouter
Get the direct bridge-call response registry.