pub struct AppServerSessionRegistry<Runtime> { /* private fields */ }Expand description
Shared runtime registry used by app-server providers.
Each session id maps to one idle runtime process. Workers temporarily remove
a runtime while executing a turn and register a cancellation token so
shutdown_session() can still interrupt in-flight runtimes.
Implementations§
Source§impl<Runtime> AppServerSessionRegistry<Runtime>
impl<Runtime> AppServerSessionRegistry<Runtime>
Sourcepub fn new(provider_name: &'static str) -> Self
pub fn new(provider_name: &'static str) -> Self
Creates an empty session runtime registry for one provider.
Sourcepub fn take_session(
&self,
session_id: &str,
) -> Result<Option<Runtime>, AppServerError>
pub fn take_session( &self, session_id: &str, ) -> Result<Option<Runtime>, AppServerError>
Removes and returns the runtime stored for session_id.
§Errors
Returns an error when the session map lock is poisoned.
Sourcepub fn store_session(
&self,
session_id: String,
session: Runtime,
) -> Result<(), AppServerError>
pub fn store_session( &self, session_id: String, session: Runtime, ) -> Result<(), AppServerError>
Stores or replaces the runtime for session_id.
§Errors
Returns an error when the session map lock is poisoned.
Sourcepub fn store_session_or_recover(
&self,
session_id: String,
session: Runtime,
) -> Result<(), (AppServerError, Runtime)>
pub fn store_session_or_recover( &self, session_id: String, session: Runtime, ) -> Result<(), (AppServerError, Runtime)>
Stores or replaces the runtime for session_id, returning ownership
back to the caller when lock acquisition fails.
This allows callers to shut down process-backed runtimes before returning an error, preventing orphaned child processes on early exits.
§Errors
Returns (error, session) when the session map lock is poisoned.
Sourcepub fn provider_name(&self) -> &'static str
pub fn provider_name(&self) -> &'static str
Returns the provider label used in user-facing retry errors.
Sourcepub fn register_active_turn(
&self,
session_id: &str,
) -> Result<ActiveAppServerTurn, AppServerError>
pub fn register_active_turn( &self, session_id: &str, ) -> Result<ActiveAppServerTurn, AppServerError>
Registers one in-flight app-server turn and returns its cancellation guard.
The returned guard unregisters itself on drop. This keeps
shutdown_session() able to signal a runtime even while the runtime is
temporarily owned by the running turn rather than stored in
AppServerSessionRegistry::sessions.
§Errors
Returns an error when the active-turn map lock is poisoned.
Sourcepub fn cancel_active_turn(
&self,
session_id: &str,
) -> Result<bool, AppServerError>
pub fn cancel_active_turn( &self, session_id: &str, ) -> Result<bool, AppServerError>
Signals an active app-server turn for session_id, if one is currently
registered.
§Errors
Returns an error when the active-turn map lock is poisoned.
Trait Implementations§
Source§impl<Runtime> Clone for AppServerSessionRegistry<Runtime>
Clones the registry handle by sharing the same underlying session map.
impl<Runtime> Clone for AppServerSessionRegistry<Runtime>
Clones the registry handle by sharing the same underlying session map.