rocketmq_remoting/protocol/static_topic/
topic_remapping_detail_wrapper.rs

1use std::collections::HashMap;
2use std::collections::HashSet;
3
4use cheetah_string::CheetahString;
5use serde::Deserialize;
6use serde::Serialize;
7
8use crate::protocol::static_topic::topic_config_and_queue_mapping::TopicConfigAndQueueMapping;
9
10pub const TYPE_CREATE_OR_UPDATE: &str = "CREATE_OR_UPDATE";
11pub const TYPE_REMAPPING: &str = "REMAPPING";
12
13pub const SUFFIX_BEFORE: &str = ".before";
14pub const SUFFIX_AFTER: &str = ".after";
15#[derive(Debug, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct TopicRemappingDetailWrapper {
18    topic: CheetahString,
19    method: CheetahString,
20    epoch: u64,
21    broker_config_map: HashMap<CheetahString, TopicConfigAndQueueMapping>,
22    broker_to_map_in: HashSet<CheetahString>,
23    broker_to_map_out: HashSet<CheetahString>,
24}
25impl TopicRemappingDetailWrapper {
26    pub fn empty() -> Self {
27        Self {
28            topic: CheetahString::new(),
29            method: CheetahString::new(),
30            epoch: 0,
31            broker_config_map: HashMap::new(),
32            broker_to_map_in: HashSet::new(),
33            broker_to_map_out: HashSet::new(),
34        }
35    }
36
37    pub fn new(
38        topic: CheetahString,
39        method: CheetahString,
40        epoch: u64,
41        broker_config_map: HashMap<CheetahString, TopicConfigAndQueueMapping>,
42        broker_to_map_in: HashSet<CheetahString>,
43        broker_to_map_out: HashSet<CheetahString>,
44    ) -> Self {
45        Self {
46            topic,
47            method,
48            epoch,
49            broker_config_map,
50            broker_to_map_in,
51            broker_to_map_out,
52        }
53    }
54
55    pub fn topic(&self) -> &str {
56        &self.topic
57    }
58
59    pub fn method(&self) -> &str {
60        &self.method
61    }
62
63    pub fn get_epoch(&self) -> u64 {
64        self.epoch
65    }
66
67    pub fn broker_config_map(&self) -> &HashMap<CheetahString, TopicConfigAndQueueMapping> {
68        &self.broker_config_map
69    }
70
71    pub fn broker_to_map_in(&self) -> &HashSet<CheetahString> {
72        &self.broker_to_map_in
73    }
74
75    pub fn broker_to_map_out(&self) -> &HashSet<CheetahString> {
76        &self.broker_to_map_out
77    }
78
79    pub fn set_broker_config_map(
80        &mut self,
81        broker_config_map: HashMap<CheetahString, TopicConfigAndQueueMapping>,
82    ) {
83        self.broker_config_map = broker_config_map;
84    }
85
86    pub fn set_broker_to_map_in(&mut self, broker_to_map_in: HashSet<CheetahString>) {
87        self.broker_to_map_in = broker_to_map_in;
88    }
89
90    pub fn set_broker_to_map_out(&mut self, broker_to_map_out: HashSet<CheetahString>) {
91        self.broker_to_map_out = broker_to_map_out;
92    }
93
94    pub fn set_topic(&mut self, topic: CheetahString) {
95        self.topic = topic;
96    }
97
98    pub fn set_method(&mut self, method: CheetahString) {
99        self.method = method;
100    }
101
102    pub fn set_epoch(&mut self, epoch: u64) {
103        self.epoch = epoch;
104    }
105}