Skip to main content

futu_gateway_core/bridge/
push_runtime.rs

1//! Push-runtime state boundary for [`super::GatewayBridge`].
2//!
3//! This is now the sole owner for metrics and push health state exposed by
4//! `GatewayBridge`. Startup, dispatcher, and handler registration paths should
5//! depend on this narrow runtime bundle instead of reaching back into the full
6//! bridge object.
7
8use std::sync::Arc;
9use std::sync::atomic::AtomicBool;
10
11use futu_server::metrics::GatewayMetrics;
12use tokio::sync::mpsc;
13
14use super::{PushEvent, PushHealth, QotLoginHealth, SharedPushHealth, SharedQotLoginHealth};
15
16#[derive(Clone)]
17pub struct PushRuntime {
18    metrics: Arc<GatewayMetrics>,
19    push_health: SharedPushHealth,
20    qot_login_health: SharedQotLoginHealth,
21    enable_price_reminder_push: Arc<AtomicBool>,
22    push_tx: Arc<parking_lot::RwLock<Option<mpsc::Sender<PushEvent>>>>,
23}
24
25impl PushRuntime {
26    pub fn new_default() -> Self {
27        Self::new(
28            Arc::new(GatewayMetrics::new()),
29            Arc::new(PushHealth::new()),
30            Arc::new(QotLoginHealth::new()),
31        )
32    }
33
34    pub fn new(
35        metrics: Arc<GatewayMetrics>,
36        push_health: SharedPushHealth,
37        qot_login_health: SharedQotLoginHealth,
38    ) -> Self {
39        Self {
40            metrics,
41            push_health,
42            qot_login_health,
43            enable_price_reminder_push: Arc::new(AtomicBool::new(true)),
44            push_tx: Arc::new(parking_lot::RwLock::new(None)),
45        }
46    }
47
48    pub fn set_push_tx(&self, push_tx: Option<mpsc::Sender<PushEvent>>) {
49        *self.push_tx.write() = push_tx;
50    }
51
52    pub fn metrics(&self) -> &Arc<GatewayMetrics> {
53        &self.metrics
54    }
55
56    pub fn push_health(&self) -> &SharedPushHealth {
57        &self.push_health
58    }
59
60    pub fn qot_login_health(&self) -> &SharedQotLoginHealth {
61        &self.qot_login_health
62    }
63
64    pub fn push_tx(&self) -> Option<mpsc::Sender<PushEvent>> {
65        self.push_tx.read().clone()
66    }
67
68    pub fn enable_price_reminder_push(&self) -> Arc<AtomicBool> {
69        Arc::clone(&self.enable_price_reminder_push)
70    }
71}
72
73impl Default for PushRuntime {
74    fn default() -> Self {
75        Self::new_default()
76    }
77}