ServiceModule

Trait ServiceModule 

Source
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§

Source

fn name(&self) -> &str

Returns the name of the service module.

This name is used for identification, dependency resolution, and logging purposes.

Provided Methods§

Source

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

Source

fn priority(&self) -> i32

Returns the priority of the module.

Modules with higher priority are executed first within the same dependency level.

Default: 0

Source

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()

Source

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(())

Source

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(())

Source

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(())

Source

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(())

Source

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(())

Source

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(())

Source

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§