futu_cache/
option_event_alert.rs1use std::sync::Arc;
2
3use futu_domain_qot_option_event::{
4 AlertCache, AlertGetTicket, AlertItem, AlertOwner, AlertWriteError, AlertWritePlan,
5 AlertWriteRequest,
6};
7use parking_lot::Mutex;
8
9#[derive(Debug, Default)]
10pub struct OptionEventAlertCache {
11 inner: Mutex<AlertCache>,
12}
13
14impl OptionEventAlertCache {
15 #[must_use]
16 pub fn new() -> Arc<Self> {
17 Arc::new(Self::default())
18 }
19
20 pub fn begin_get_for_owner(&self, now: i64, owner: AlertOwner) -> AlertGetTicket {
21 self.inner.lock().begin_get_for_owner(now, owner)
22 }
23
24 pub fn commit_get(&self, ticket: AlertGetTicket, now: i64, items: Vec<AlertItem>) -> bool {
25 self.inner.lock().commit_get(ticket, now, items)
26 }
27
28 pub fn invalidate_from_push(&self) {
29 self.inner.lock().invalidate_from_push();
30 }
31
32 pub fn is_ready_for_owner(&self, now: i64, owner: AlertOwner) -> bool {
33 self.inner.lock().is_ready_for_owner(now, owner)
34 }
35
36 pub fn plan_write_for_owner(
37 &self,
38 request_id: u64,
39 now: i64,
40 owner: AlertOwner,
41 request: AlertWriteRequest,
42 ) -> Result<AlertWritePlan, AlertWriteError> {
43 self.inner
44 .lock()
45 .plan_write_for_owner(request_id, now, owner, request)
46 }
47
48 pub fn apply_pending_success(&self, request_id: u64, now: i64) -> bool {
49 self.inner.lock().apply_pending_success(request_id, now)
50 }
51
52 pub fn reject_pending(&self, request_id: u64) {
53 self.inner.lock().reject_pending(request_id);
54 }
55}