pub struct SubscriptionManager { /* private fields */ }Expand description
订阅管理器
Implementations§
Source§impl SubscriptionManager
impl SubscriptionManager
Sourcepub fn register_push_broker(
&self,
conn_id: u64,
sec_key: &QotSecurityKey,
sub_type: i32,
rehab_type: i32,
)
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).
Sourcepub fn unregister_push_broker(
&self,
conn_id: u64,
sec_key: &QotSecurityKey,
sub_type: i32,
rehab_type: i32,
)
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.
Sourcepub fn get_qot_push_subscribers_broker(
&self,
sec_key: &QotSecurityKey,
sub_type: i32,
rehab_type: i32,
) -> Vec<u64>
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.
Sourcepub fn get_qot_push_subscribers_by_cache_key(
&self,
cache_key: &str,
sub_type: i32,
rehab_type: i32,
) -> Vec<u64>
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.
Sourcepub fn is_push_registered_any_rehab_broker(
&self,
conn_id: u64,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> bool
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§impl SubscriptionManager
impl SubscriptionManager
Sourcepub fn get_conn_used_quota(&self, conn_id: u64) -> u32
pub fn get_conn_used_quota(&self, conn_id: u64) -> u32
per-conn used quota — count 该 conn 的 (security_key, sub_type) 对数.
Sourcepub fn get_conn_used_quota_by<F>(&self, conn_id: u64, include: F) -> u32
pub fn get_conn_used_quota_by<F>(&self, conn_id: u64, include: F) -> u32
per-conn used quota with a caller-provided key classifier.
C++ 10.7 separates normal subscription quota from option-chain quota:
QotSubscribe::GetUsedQuota skips keys resolvable by
ResolveOptionChainKey; GetUsedOptionQuota handles those separately.
Rust keeps the option classifier outside SubscriptionManager because
it depends on StaticDataCache metadata.
Sourcepub fn get_total_used_quota(&self) -> u32
pub fn get_total_used_quota(&self) -> u32
全局 used quota — 对齐 C++ m_nAllUsedQuota (累加全局唯一
SubKey count). 不重复计 conn — 多 conn 订同 (stock, sub_type) 全局算 1.
Sourcepub fn get_total_used_quota_by<F>(&self, include: F) -> u32
pub fn get_total_used_quota_by<F>(&self, include: F) -> u32
Global used quota with a caller-provided key classifier.
Sourcepub fn get_option_total_quota(&self) -> u32
pub fn get_option_total_quota(&self) -> u32
C++ INNData_APIInterLimit::GetOptionSubQuota() is GetSubQuota()/5.
Sourcepub fn get_total_used_option_quota_by<F, K>(&self, option_bill_key: F) -> u32
pub fn get_total_used_option_quota_by<F, K>(&self, option_bill_key: F) -> u32
Global option-chain quota, deduped by (option_chain_key, sub_type).
The supplied closure mirrors C++ ResolveOptionChainKey: None means
the key is a normal security; Some(chain) means it participates in the
option quota bill set.
Sourcepub fn get_conn_used_option_quota_by<F, K>(
&self,
conn_id: u64,
option_bill_key: F,
) -> u32
pub fn get_conn_used_option_quota_by<F, K>( &self, conn_id: u64, option_bill_key: F, ) -> u32
Per-connection option-chain quota, deduped by (option_chain_key, sub_type).
Sourcepub fn get_total_quota(&self) -> u32
pub fn get_total_quota(&self) -> u32
获取 total quota (动态, backend 下发后更新).
Sourcepub fn set_total_quota_from_backend(&self, value: u32)
pub fn set_total_quota_from_backend(&self, value: u32)
v1.4.106 codex 1131 F5 [P2]: backend 下发的 quota 真值 setter.
pub fn get_remain_quota(&self) -> u32
pub fn get_conn_qot_subs(&self, conn_id: u64) -> HashMap<i32, Vec<String>>
pub fn get_all_qot_conn_ids(&self) -> HashSet<u64>
Sourcepub fn get_all_trd_conn_ids(&self) -> HashSet<u64>
pub fn get_all_trd_conn_ids(&self) -> HashSet<u64>
v1.4.106 codex 0932 F5 [P2]: 获取所有连接 ID(有交易账户订阅的).
Sourcepub fn compute_global_desired_set(&self) -> Vec<(String, i32)>
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}").
Sourcepub fn qot_global_desired_keys(&self) -> Vec<(String, i32)>
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 应做的事:
- 调本 fn 拿当前全集
- 应用 delta (sub: 加; unsub: 减; unsub_all: 移除本 conn 独占的)
- resolve sec_key → stock_id (cache); cache miss → loud warn (本 fn 不 替 caller 决定 — 由 caller 选择 fail-loud 还是 partial-submit)
- 调
submit_global_desired_set(NEW set)让 backend ack
命名: keys = (sec_key, sub_type) 二元组, 不是 (stock_id, market) —
stock_id resolve 是 caller 责任 (因为依赖 StaticDataCache).
Sourcepub fn qot_sub_elapsed_at_least_broker(
&self,
sec_key: &QotSecurityKey,
sub_type: i32,
elapsed: Duration,
) -> bool
pub fn qot_sub_elapsed_at_least_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, elapsed: Duration, ) -> bool
C++ delay-statistics gate equivalent for QOT push reporting.
Ref: APIServer_Qot_StockBasic.cpp:218-223,
APIServer_Qot_OrderBook.cpp:238-243, and
APIServer_Qot_Broker.cpp:194-199: IsHasSubFewTime(..., 3) must be
true before Push_Count_Add.
Source§impl SubscriptionManager
impl SubscriptionManager
pub fn new() -> Self
pub fn subscribe_notify(&self, conn_id: u64)
pub fn unsubscribe_notify(&self, conn_id: u64)
pub fn is_subscribed_notify(&self, conn_id: u64) -> bool
pub fn register_api_page_req_key(&self, conn_id: u64, key: &[u8]) -> bool
pub fn is_api_page_req_key_registered(&self, conn_id: u64, key: &[u8]) -> bool
pub fn subscribe_trd_acc(&self, conn_id: u64, acc_id: u64)
pub fn unsubscribe_trd_acc(&self, conn_id: u64, acc_id: u64)
pub fn get_acc_subscribers(&self, acc_id: u64) -> Vec<u64>
Sourcepub fn subscribe_qot_broker(
&self,
conn_id: u64,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> SubResult
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 回滚.
Sourcepub fn unsubscribe_qot_broker(
&self,
conn_id: u64,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> UnsubResult
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.
Sourcepub fn is_qot_subscribed_broker(
&self,
conn_id: u64,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> bool
pub fn is_qot_subscribed_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, ) -> bool
是否 (conn_id, key, sub_type) 已订阅.
Sourcepub fn is_globally_subscribed_broker(
&self,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> bool
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).
Sourcepub fn qot_min_unsub_elapsed_broker(
&self,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> bool
pub fn qot_min_unsub_elapsed_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> bool
min-unsub window for broker-aware subscription keys.
Sourcepub fn qot_min_unsub_remaining_secs_broker(
&self,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> u64
pub fn qot_min_unsub_remaining_secs_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> u64
remaining min-unsub window for broker-aware keys.
Sourcepub fn qot_disconnect_sync_generation(&self) -> u64
pub fn qot_disconnect_sync_generation(&self) -> u64
断线延迟清理后需要 gateway 同步 CMD6211 的 generation。
Sourcepub fn unsubscribe_all_qot_collect_global_empty(
&self,
conn_id: u64,
) -> Vec<(String, i32)>
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}").
Sourcepub fn cleanup_due_disconnected_qot(&self) -> Vec<(String, i32)>
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。
Sourcepub fn unsubscribe_all_qot_dry_run(&self, conn_id: u64) -> Vec<(String, i32)>
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 替代.
Sourcepub fn unsubscribe_all_qot_commit(&self, conn_id: u64) -> Vec<(String, i32)>
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.
Sourcepub fn get_qot_subscribers_broker(
&self,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> Vec<u64>
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).
Sourcepub fn qot_owner_lease_broker(
&self,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> Vec<(u64, u64, i32, u64)>
pub fn qot_owner_lease_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> Vec<(u64, u64, i32, u64)>
Snapshot active owners for generation-fenced async quote work.
pub fn qot_owner_lease_is_current( &self, sec_key: &QotSecurityKey, sub_type: i32, captured: &[(u64, u64, i32, u64)], request_section: Option<i32>, ) -> bool
pub fn with_current_qot_owner_lease<R>( &self, sec_key: &QotSecurityKey, sub_type: i32, captured: &[(u64, u64, i32, u64)], request_section: Option<i32>, publish: impl FnOnce() -> R, ) -> Option<R>
Sourcepub fn crypto_stock_globally_unsubscribed(&self, stock_id: u64) -> bool
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_cache 按 stock_id keyed (broker 无关), 只有该
stock 全 broker 全 sub_type 都退掉才能安全清.
返 true ⟺ 该 stock_id 在 qot_subs 中无任何带 subscriber 的 entry.
Sourcepub fn crypto_stock_broker_globally_unsubscribed(
&self,
stock_id: u64,
broker_id: u32,
) -> bool
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 不适用).
返 true ⟺ 该 (stock_id, broker_id) 在 qot_subs 无任何带 subscriber 的 entry.
pub fn set_conn_session_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, session: i32, )
pub fn get_global_session_broker( &self, sec_key: &QotSecurityKey, sub_type: i32, ) -> i32
Sourcepub fn get_conn_session_broker(
&self,
conn_id: u64,
sec_key: &QotSecurityKey,
sub_type: i32,
) -> i32
pub fn get_conn_session_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, sub_type: i32, ) -> i32
获取单连接订阅 session(没有显式记录时按 C++ 默认 RTH)。
Sourcepub fn get_conn_session_by_cache_key(
&self,
conn_id: u64,
cache_key: &str,
sub_type: i32,
) -> i32
pub fn get_conn_session_by_cache_key( &self, conn_id: u64, cache_key: &str, sub_type: i32, ) -> i32
Lookup the FTAPI connection session from the internal cache-key carried by a live push. Missing entries retain the C++ default RTH session.
pub fn set_conn_orderbook_detail_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, detail: bool, )
pub fn is_global_orderbook_detail_broker( &self, sec_key: &QotSecurityKey, ) -> bool
pub fn set_conn_broker_detail_broker( &self, conn_id: u64, sec_key: &QotSecurityKey, detail: bool, )
pub fn is_global_broker_detail_broker(&self, sec_key: &QotSecurityKey) -> bool
pub fn register_connection_open_observer( &self, observer: ConnectionOpenObserver, )
pub fn register_disconnect_observer( &self, observer: ConnectionDisconnectObserver, )
pub fn on_disconnect(&self, conn_id: u64) -> Vec<(String, i32)>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SubscriptionManager
impl !RefUnwindSafe for SubscriptionManager
impl !UnwindSafe for SubscriptionManager
impl Send for SubscriptionManager
impl Sync for SubscriptionManager
impl Unpin for SubscriptionManager
impl UnsafeUnpin for SubscriptionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more