mecha10-core 0.8.2

Mecha10 core runtime and foundational types
Documentation
//! Node execution context
//!
//! Provides a high-level API for nodes to interact with the framework,
//! including type-safe pub/sub, configuration access, and lifecycle management.
//!
//! This module has been refactored into smaller sub-modules for better organization:
//! - `infra_config`: Infrastructure configuration types
//! - `receiver`: Message receiver wrapper
//! - `builder`: Builder for constructing a `Context`
//! - `lifecycle`: Construction, instance naming, shutdown, logging span
//! - `config`: Infrastructure configuration loading (Redis URLs, control plane)
//! - `node_config`: Node-level configuration loading with environment fallback
//! - `pubsub`: Type-safe and raw publish/subscribe methods
//! - `aggregation`: Pattern-based topic discovery and aggregated subscriptions
//! - `topics`: Convenience helpers for well-known topic categories
//! - `state_mgmt`: Access to the per-node persistent state manager

mod aggregation;
mod builder;
mod config;
mod infra_config;
mod lifecycle;
mod node_config;
mod pubsub;
mod receiver;
mod state_mgmt;
mod topics;

pub use builder::ContextBuilder;
pub use infra_config::{BridgeConfig, InfrastructureConfig, MinioConfig, MlflowConfig, PostgresConfig, RedisConfig};
pub use node_config::split_base_and_custom;
pub use receiver::Receiver;

use std::sync::Arc;
use tokio::sync::RwLock;

pub struct Context {
    node_id: String,

    instance: Option<String>,

    #[cfg(feature = "messaging")]
    message_bus: Arc<RwLock<mecha10_messaging::MessageBus>>,

    #[cfg(feature = "messaging")]
    control_plane_bus: Arc<RwLock<Option<mecha10_messaging::MessageBus>>>,

    #[cfg(feature = "messaging")]
    redis_bridge: Arc<RwLock<Option<crate::redis_bridge::RedisBridge>>>,

    shutdown: Arc<RwLock<bool>>,

    state_manager: Arc<RwLock<Option<Arc<crate::state::ConcreteStateManager>>>>,
}
impl Clone for Context {
    fn clone(&self) -> Self {
        Self {
            node_id: self.node_id.clone(),
            instance: self.instance.clone(),
            #[cfg(feature = "messaging")]
            message_bus: Arc::clone(&self.message_bus),
            #[cfg(feature = "messaging")]
            control_plane_bus: Arc::clone(&self.control_plane_bus),
            #[cfg(feature = "messaging")]
            redis_bridge: Arc::clone(&self.redis_bridge),
            shutdown: Arc::clone(&self.shutdown),
            state_manager: Arc::clone(&self.state_manager),
        }
    }
}