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 DMSCServiceContext) -> DMSCResult<()> { ... }
fn before_start(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()> { ... }
fn start(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()> { ... }
fn after_start(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()> { ... }
fn before_shutdown(
&mut self,
_ctx: &mut DMSCServiceContext,
) -> DMSCResult<()> { ... }
fn shutdown(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()> { ... }
fn after_shutdown(
&mut self,
_ctx: &mut DMSCServiceContext,
) -> DMSCResult<()> { ... }
}Expand description
Synchronous service module trait.
This trait defines the interface for synchronous service modules in DMSC. It provides a comprehensive lifecycle management system with multiple phases.
§Usage
use dmsc::core::{ServiceModule, DMSCResult, DMSCServiceContext};
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 DMSCServiceContext) -> DMSCResult<()> {
// 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 DMSCServiceContext) -> DMSCResult<()>
fn init(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
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 DMSCServiceContext) -> DMSCResult<()>
fn before_start(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
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 DMSCServiceContext) -> DMSCResult<()>
fn start(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
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 DMSCServiceContext) -> DMSCResult<()>
fn after_start(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
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 DMSCServiceContext) -> DMSCResult<()>
fn before_shutdown(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
Prepares the module for shutdown.
This method is called before the main shutdown phase.
Default: Ok(())
Sourcefn shutdown(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
fn shutdown(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
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 DMSCServiceContext) -> DMSCResult<()>
fn after_shutdown(&mut self, _ctx: &mut DMSCServiceContext) -> DMSCResult<()>
Performs post-shutdown cleanup.
This method is called after the main shutdown phase to clean up resources.
Default: Ok(())
Implementors§
impl ServiceModule for DMSCAuthModule
impl ServiceModule for DMSCCacheModule
impl ServiceModule for DMSCDeviceControlModule
impl ServiceModule for DMSCQueueModule
impl ServiceModule for DMSCLogAnalyticsModule
impl ServiceModule for DMSCLifecycleObserver
impl ServiceModule for DMSCPythonServiceModule
pyo3 only.