Skip to main content

SubscriptionManager

Struct SubscriptionManager 

Source
pub struct SubscriptionManager { /* private fields */ }
Expand description

订阅管理器

Implementations§

Source§

impl SubscriptionManager

Source

pub fn new() -> Self

Source

pub fn subscribe_notify(&self, conn_id: u64)

Source

pub fn unsubscribe_notify(&self, conn_id: u64)

Source

pub fn is_subscribed_notify(&self, conn_id: u64) -> bool

Source

pub fn subscribe_trd_acc(&self, conn_id: u64, acc_id: u64)

Source

pub fn unsubscribe_trd_acc(&self, conn_id: u64, acc_id: u64)

Source

pub fn get_acc_subscribers(&self, acc_id: u64) -> Vec<u64>

Source

pub fn make_qot_key(market: i32, code: &str, sub_type: i32) -> String

生成行情订阅 key.

Source

pub fn subscribe_qot_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, ) -> SubResult

v1.4.106 codex 1131 F1+F5 [P1+P2]: 订阅行情. 返 SubResult 表示是否新加全局订阅 (caller 据此累 quota). 重复订阅 (同 conn_id 同 key) 不影响 set, 不影响 quota. NOTE: caller 必须先 backend ack-then-commit (F1) — 本方法仅写 local state. 失败 caller 应调 unsubscribe_qot_broker 回滚.

Source

pub fn unsubscribe_qot_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, ) -> UnsubResult

退订并返结构化结果. caller 据 LastSubscriber 决定是否发 backend fresh CMD 6211 with new desired set.

Source

pub fn is_qot_subscribed_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, ) -> bool

是否 (conn_id, key, sub_type) 已订阅.

Source

pub fn is_globally_subscribed_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> bool

v1.4.106 codex 1131 F3 [P1]: 全局 (ignore conn) 是否有订阅 — RegQotPush 的 precondition. 对齐 C++ QotSubscribe::IsSub(stockID, subType).

Source

pub fn qot_min_unsub_elapsed_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> bool

min-unsub window for broker-aware subscription keys.

Source

pub fn qot_min_unsub_remaining_secs_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> u64

remaining min-unsub window for broker-aware keys.

Source

pub fn qot_disconnect_sync_generation(&self) -> u64

断线延迟清理后需要 gateway 同步 CMD6211 的 generation。

Source

pub fn unsubscribe_all_qot_collect_global_empty( &self, conn_id: u64, ) -> Vec<(String, i32)>

v1.4.106 codex 1131 F2: clear all qot subs for a single conn_id. 返 (sec_key, sub_type) 列表 of “本 conn 退订后变成全局空的” — caller 据此构 backend new desired set. 返的 sec_key 是 cache_key display string ("market_code" or "market_code@b{id}").

Source

pub fn cleanup_due_disconnected_qot(&self) -> Vec<(String, i32)>

清理已断开且已满足 C++ 最短退订窗口的 QOT conn。

返回本次清理后 global desired set 变空的 (sec_key, sub_type) 列表 (sec_key 是 cache_key display string: "market_code" or "market_code@b{id}"). 若列表非空,会 bump qot_disconnect_sync_generation,由 gateway 后台 任务负责把新的全局 desired set 发到 backend。

Source

pub fn unsubscribe_all_qot_dry_run(&self, conn_id: u64) -> Vec<(String, i32)>

v1.4.106 codex 0631 F1 [P1]: ack-then-commit unsub_all 的“干跑“半段.

计算: 本 conn 退订全部, 哪些 (sec_key, sub_type) 在 global desired set 中变空 (= backend 该真退). 不修 state, 不动 detail flag, 不动 push_regs. 用在 ack-then-commit pipeline:

dry_run -> submit_global_desired_set (backend ack) -> commit (清 state)

backend reject → caller 不调 commit, state 保留 → 客户端可重试幂等. 老 unsubscribe_all_qot_collect_global_empty 是先清后算 — 失败时 state 已 mutate, 不能 rollback (split-brain 风险). 本 helper 替代.

Source

pub fn unsubscribe_all_qot_commit(&self, conn_id: u64) -> Vec<(String, i32)>

v1.4.106 codex 0631 F1 [P1]: ack-then-commit unsub_all 的“提交“半段. 等价于老 unsubscribe_all_qot_collect_global_empty (语义不变, 仅在 backend ack OK 后才调). 同时清 session / detail / push_regs.

Source

pub fn get_qot_subscribers_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> Vec<u64>

获取订阅了指定行情的连接列表 (subscribers, 用作 push 路由). 用于 apply_unsubscribe_delta 判断 broker-aware key 上是否还有其他 conn 订阅 (last-subscriber gate for desired-set remove).

Source

pub fn crypto_stock_globally_unsubscribed(&self, stock_id: u64) -> bool

v1.4.110 codex audit Round3 P2 #21: 给定 stock_id, 判断该 stock 是否 全局已无任何 conn 订阅 (跨所有 broker_id + 所有 sub_type).

用途: Qot_Sub 退订路径在 commit 之后判断 crypto symbol 是否真正全空, 决定是否调 CryptoExchangeCache::clear_stock(stock_id) 清 stale entry — 因为 crypto_exchange_cachestock_id keyed (broker 无关), 只有该 stock 全 broker 全 sub_type 都退掉才能安全清.

qot_subs 找任意 key 满足 QotStockKey.stock_id == stock_id; broker 1007 退订但 1008 仍订阅时返 false (不能清).

true ⟺ 该 stock_id 在 qot_subs 中无任何带 subscriber 的 entry.

Source

pub fn crypto_stock_broker_globally_unsubscribed( &self, stock_id: u64, broker_id: u32, ) -> bool

v1.4.110 R6-8: (stock_id, broker_id)-级版 crypto_stock_globally_unsubscribed.

用途: 部分 broker 退订时, 判断某具体 (stock_id, broker_id) 是否已无任何 conn 订阅 → 决定是否调 CryptoExchangeCache::clear_stock_broker 清该 broker 的 stale by_broker entry (整 stock 仍有别的 broker 在订时 clear_stock 不适用).

stock_key.stock_id + stock_key.broker_id 双字段匹配.

true ⟺ 该 (stock_id, broker_id)qot_subs 无任何带 subscriber 的 entry.

Source

pub fn register_push_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, rehab_type: i32, )

v1.4.106 codex 1131 F3 [P1]: 注册接收 push (对齐 C++ RegPush). 仅写本 map, 不动 qot_subs. caller (RegQotPushHandler) 必须在 调本方法前确认已订阅 (is_globally_subscribed_broker).

Source

pub fn unregister_push_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, rehab_type: i32, )

v1.4.106 codex 1131 F3 [P1]: 取消 push 注册 — 不删 qot_subs.

Source

pub fn get_qot_push_subscribers_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, rehab_type: i32, ) -> Vec<u64>

v1.4.106 codex 1131 F4 [P1]: push delivery filter. 对齐 C++ QotSubscribe::GetPushConn.

Source

pub fn get_qot_push_subscribers_by_cache_key( &self, cache_key: &str, sub_type: i32, rehab_type: i32, ) -> Vec<u64>

Lookup by internal cache-key display string carried by push events ("market_code" or "market_code@b{id}").

PushEvent::QuotePush does not carry stock_id, so dispatch cannot reconstruct a full QotSecurityKey. Instead, match the already stored subscription keys by their cache-key display string.

Source

pub fn is_push_registered_any_rehab_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, ) -> bool

v1.4.106 codex 1131 F3 [P1]: 是否注册过 push (任意 rehab).

Source

pub fn set_conn_session_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, session: i32, )

Source

pub fn get_global_session_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> i32

Source

pub fn get_conn_session_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, ) -> i32

获取单连接订阅 session(没有显式记录时按 C++ 默认 RTH)。

Source

pub fn set_conn_orderbook_detail_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, detail: bool, )

Source

pub fn is_global_orderbook_detail_broker( &self, sec_key: &QotSecurityKey, ) -> bool

Source

pub fn set_conn_broker_detail_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, detail: bool, )

Source

pub fn is_global_broker_detail_broker(&self, sec_key: &QotSecurityKey) -> bool

Source

pub fn get_conn_used_quota(&self, conn_id: u64) -> u32

per-conn used quota — count 该 conn 的 (security_key, sub_type) 对数.

Source

pub fn get_total_used_quota(&self) -> u32

全局 used quota — 对齐 C++ m_nAllUsedQuota (累加全局唯一 SubKey count). 不重复计 conn — 多 conn 订同 (stock, sub_type) 全局算 1.

Source

pub fn get_total_quota(&self) -> u32

获取 total quota (动态, backend 下发后更新).

Source

pub fn set_total_quota_from_backend(&self, value: u32)

v1.4.106 codex 1131 F5 [P2]: backend 下发的 quota 真值 setter.

Source

pub fn get_remain_quota(&self) -> u32

Source

pub fn get_conn_qot_subs(&self, conn_id: u64) -> HashMap<i32, Vec<String>>

Source

pub fn get_all_qot_conn_ids(&self) -> HashSet<u64>

Source

pub fn get_all_trd_conn_ids(&self) -> HashSet<u64>

v1.4.106 codex 0932 F5 [P2]: 获取所有连接 ID(有交易账户订阅的).

Source

pub fn compute_global_desired_set(&self) -> Vec<(String, i32)>

v1.4.106 codex 1131 F2 [P1]: 计算全局 desired set. 返 (sec_key_display, sub_type), sec_key_display 是 cache_key 形态 ("market_code" or "market_code@b{id}").

Source

pub fn qot_global_desired_keys(&self) -> Vec<(String, i32)>

v1.4.106 codex 0631 F2 [P2]: shared global desired-set keys helper.

返当前全集 Vec<(sec_key, sub_type)> (与 compute_global_desired_set 等价, 命名对齐 codex 0631 audit 习惯). 共享给 SubHandler / unsub / unsub_all / resubscribe_quotes 三路径, 不再每条 sub 单独发 delta — 对齐 CMD 6211 set-state 协议 (per-market full set replaces).

caller 应做的事:

  1. 调本 fn 拿当前全集
  2. 应用 delta (sub: 加; unsub: 减; unsub_all: 移除本 conn 独占的)
  3. resolve sec_key → stock_id (cache); cache miss → loud warn (本 fn 不 替 caller 决定 — 由 caller 选择 fail-loud 还是 partial-submit)
  4. submit_global_desired_set(NEW set) 让 backend ack

命名: keys = (sec_key, sub_type) 二元组, 不是 (stock_id, market) — stock_id resolve 是 caller 责任 (因为依赖 StaticDataCache).

Source

pub fn on_disconnect(&self, conn_id: u64) -> Vec<(String, i32)>

Trait Implementations§

Source§

impl Default for SubscriptionManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more