pub struct JanusState {
pub config: Config,
pub signal_bus: SignalBus,
pub market_data_bus: MarketDataBus,
/* private fields */
}Expand description
Shared application state accessible by all modules
Fields§
§config: ConfigConfiguration
signal_bus: SignalBusSignal broadcast bus for inter-module communication
market_data_bus: MarketDataBusMarket data broadcast bus for live data streaming (Data → Forward)
The Data module publishes normalised MarketDataEvents
here when live market data ingestion is active. The Forward module
subscribes to consume them for indicator calculation and
strategy-driven signal generation.
Implementations§
Source§impl JanusState
impl JanusState
Sourcepub async fn new(config: Config) -> Result<Self>
pub async fn new(config: Config) -> Result<Self>
Create new application state.
Services start in ServiceState::Standby — the API module comes up
immediately but processing modules (Forward, Backward, CNS, Data) will
block on [wait_for_services_start] until an explicit start command is
issued through the API or web interface.
Sourcepub async fn current_regime(&self) -> Option<String>
pub async fn current_regime(&self) -> Option<String>
Get the most recently published market-regime label.
Returns the value most recently written via [set_current_regime],
or None if no producer has reported a regime yet. Used by the
JFLOW-A session metrics reporter.
Sourcepub async fn set_current_regime(&self, regime: impl Into<String>)
pub async fn set_current_regime(&self, regime: impl Into<String>)
Publish the latest market-regime label.
Intended to be called by the brain pipeline / regime detector as new decisions land. Overwrites whatever was there before — the field is a snapshot, not a history.
Sourcepub async fn current_threat(&self) -> Option<f64>
pub async fn current_threat(&self) -> Option<f64>
Get the most recently published amygdala threat / fear level.
A scalar in 0.0..=1.0 (higher = more fear), or None if no
producer has reported one yet. Consumed by position guidance to
escalate under stress. Kept as a plain f64 so janus-core stays
free of any dependency on the neuromorphic crate that produces it.
Sourcepub async fn set_current_threat(&self, fear: f64)
pub async fn set_current_threat(&self, fear: f64)
Publish the latest amygdala threat / fear level.
Intended to be called by the brain pipeline as new amygdala
assessments land. Snapshot semantics, like [set_current_regime].
Sourcepub async fn set_affinity_recorder(&self, recorder: Box<dyn AffinityRecorder>)
pub async fn set_affinity_recorder(&self, recorder: Box<dyn AffinityRecorder>)
Install a strategy-affinity recorder.
Called once by the forward service after its TradingPipeline is
constructed, so the API’s position-close handler can feed realized
outcomes into affinity learning. Replaces any previously installed
recorder.
Sourcepub async fn has_affinity_recorder(&self) -> bool
pub async fn has_affinity_recorder(&self) -> bool
Whether an affinity recorder is installed (for diagnostics / logging).
Sourcepub async fn record_affinity_outcome(
&self,
strategy: &str,
asset: &str,
pnl: f64,
is_winner: bool,
rr_ratio: Option<f64>,
) -> bool
pub async fn record_affinity_outcome( &self, strategy: &str, asset: &str, pnl: f64, is_winner: bool, rr_ratio: Option<f64>, ) -> bool
Record a closed trade into the affinity tracker, if a recorder is installed. No-op otherwise. Returns whether the outcome was recorded.
Sourcepub async fn set_log_level_controller(
&self,
controller: Box<dyn LogLevelController>,
)
pub async fn set_log_level_controller( &self, controller: Box<dyn LogLevelController>, )
Install a runtime log-level controller.
Called once from main() after init_logging() returns.
The controller is then available to the API via
set_log_level and
current_log_filter.
Sourcepub async fn set_log_level(&self, filter_str: &str) -> Result<(), String>
pub async fn set_log_level(&self, filter_str: &str) -> Result<(), String>
Change the runtime log filter.
Delegates to the installed LogLevelController. Returns an error
if no controller has been installed yet.
Sourcepub async fn current_log_filter(&self) -> Option<String>
pub async fn current_log_filter(&self) -> Option<String>
Returns the current log filter string, if a controller is installed.
Sourcepub fn uptime_seconds(&self) -> u64
pub fn uptime_seconds(&self) -> u64
Get uptime in seconds
Sourcepub fn is_shutdown_requested(&self) -> bool
pub fn is_shutdown_requested(&self) -> bool
Check if shutdown has been requested
Sourcepub fn request_shutdown(&self)
pub fn request_shutdown(&self)
Request shutdown
Sourcepub fn start_services(&self) -> bool
pub fn start_services(&self) -> bool
Transition processing services to ServiceState::Running.
All modules blocked on [wait_for_services_start] will proceed.
Returns true if the state actually changed.
Sourcepub fn stop_services(&self) -> bool
pub fn stop_services(&self) -> bool
Transition processing services to ServiceState::Stopped.
Modules should check [are_services_active] in their hot loops and
wind down gracefully when it returns false.
Returns true if the state actually changed.
Sourcepub fn service_state(&self) -> ServiceState
pub fn service_state(&self) -> ServiceState
Returns the current ServiceState.
Sourcepub fn are_services_active(&self) -> bool
pub fn are_services_active(&self) -> bool
Returns true when processing modules should be actively running.
Sourcepub async fn wait_for_services_start(&self) -> bool
pub async fn wait_for_services_start(&self) -> bool
Block until services are started (state becomes ServiceState::Running)
or a shutdown is requested.
Returns true if services were started, false if a shutdown was
requested while still waiting.
Sourcepub fn subscribe_service_state(&self) -> Receiver<ServiceState>
pub fn subscribe_service_state(&self) -> Receiver<ServiceState>
Subscribe to service-state changes.
Useful for modules that need to react to stop commands mid-loop.
Sourcepub async fn register_module_health(
&self,
name: impl Into<String>,
healthy: bool,
message: Option<String>,
)
pub async fn register_module_health( &self, name: impl Into<String>, healthy: bool, message: Option<String>, )
Register a module’s health status
Sourcepub async fn get_module_health(&self) -> Vec<ModuleHealth>
pub async fn get_module_health(&self) -> Vec<ModuleHealth>
Get all module health statuses
Sourcepub async fn all_modules_healthy(&self) -> bool
pub async fn all_modules_healthy(&self) -> bool
Check if all modules are healthy
Sourcepub fn increment_signals_generated(&self)
pub fn increment_signals_generated(&self)
Increment signals generated counter
Sourcepub fn signals_generated(&self) -> u64
pub fn signals_generated(&self) -> u64
Get signals generated count
Sourcepub fn increment_signals_persisted(&self)
pub fn increment_signals_persisted(&self)
Increment signals persisted counter
Sourcepub fn signals_persisted(&self) -> u64
pub fn signals_persisted(&self) -> u64
Get signals persisted count
Sourcepub async fn redis_client(&self) -> Result<Client>
pub async fn redis_client(&self) -> Result<Client>
Get or create the Redis client handle.
This is intentionally cheap — redis::Client::open only parses
the URL; it does not open a TCP connection. Callers obtain
an actual connection via client.get_multiplexed_async_connection().
Sourcepub async fn probe_redis(&self)
pub async fn probe_redis(&self)
Probe Redis connectivity and update the janus_redis_connected
Prometheus gauge.
Call once at startup (from main()) and optionally from periodic
health-check loops. The method never returns an error — it logs
warnings and sets the gauge to 0 on failure so the process can
continue booting even if Redis is temporarily unavailable.
Sourcepub async fn health_status(&self) -> HealthStatus
pub async fn health_status(&self) -> HealthStatus
Get comprehensive health status