pub trait ServiceModule: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn is_critical(&self) -> bool { ... }
fn priority(&self) -> i32 { ... }
fn dependencies(&self) -> Vec<&str> { ... }
fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> { ... }
fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> { ... }
fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> { ... }
fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> { ... }
fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> { ... }
fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> { ... }
fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> { ... }
}Expand description
Synchronous service module trait.
This trait defines the interface for synchronous service modules in Ri. It provides a comprehensive lifecycle management system with multiple phases.
§Usage
use ri::core::{ServiceModule, RiResult, RiServiceContext};
struct MySyncModule;
impl ServiceModule for MySyncModule {
fn name(&self) -> &str {
"my_sync_module"
}
fn is_critical(&self) -> bool {
false
}
fn priority(&self) -> i32 {
10
}
fn dependencies(&self) -> Vec<&str> {
vec!["dependency_module"]
}
fn start(&mut self, ctx: &mut RiServiceContext) -> RiResult<()> {
// Start module logic
Ok(())
}
}Required Methods§
Provided Methods§
Sourcefn is_critical(&self) -> bool
fn is_critical(&self) -> bool
Indicates if the module is critical to the operation of the system.
Critical modules will cause the entire system to fail if they encounter an error, while non-critical modules can fail independently.
Default: true
Sourcefn priority(&self) -> i32
fn priority(&self) -> i32
Returns the priority of the module.
Modules with higher priority are executed first within the same dependency level.
Default: 0
Sourcefn dependencies(&self) -> Vec<&str>
fn dependencies(&self) -> Vec<&str>
Returns the list of module dependencies.
Dependencies are module names that must be initialized and started before this module. The runtime will ensure dependencies are processed in the correct order.
Default: Vec::new()
Sourcefn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
Initializes the service module.
This method is called during the initialization phase to set up module resources.
Default: Ok(())
Sourcefn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
Prepares the module for startup.
This method is called after initialization but before the main start phase.
Default: Ok(())
Sourcefn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
Starts the service module.
This method is called to start the main functionality of the module.
Default: Ok(())
Sourcefn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
Performs post-startup operations.
This method is called after the main start phase but before the module is considered fully started.
Default: Ok(())
Sourcefn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
Prepares the module for shutdown.
This method is called before the main shutdown phase.
Default: Ok(())
Sourcefn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
Shuts down the service module.
This method is called to stop the main functionality of the module.
Default: Ok(())
Sourcefn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()>
Performs post-shutdown cleanup.
This method is called after the main shutdown phase to clean up resources.
Default: Ok(())
Implementors§
impl ServiceModule for RiAuthModule
impl ServiceModule for RiCacheModule
impl ServiceModule for RiDeviceControlModule
impl ServiceModule for RiQueueModule
impl ServiceModule for RiLogAnalyticsModule
impl ServiceModule for RiLifecycleObserver
impl ServiceModule for RiPythonServiceModule
pyo3 only.