Repository navigation
Expand file tree
/
Copy pathMessageExtImpl.cpp
More file actions
208 lines (165 loc) · 5.98 KB
/
Copy pathMessageExtImpl.cpp
File metadata and controls
208 lines (165 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "MessageExtImpl.h"
#include <sstream> // std::stringstream
#include "MessageClientIDSetter.h"
#include "MessageSysFlag.h"
#include "SocketUtil.h"
#include "UtilAll.h"
namespace rocketmq {
// ============================
// MessageExtImpl
// ============================
MessageExtImpl::MessageExtImpl() : MessageExtImpl(0, 0, nullptr, 0, nullptr, null) {}
MessageExtImpl::MessageExtImpl(int queueId,
int64_t bornTimestamp,
const struct sockaddr* bornHost,
int64_t storeTimestamp,
const struct sockaddr* storeHost,
const std::string& msgId)
: store_size_(0),
body_crc_(0),
queue_id_(queueId),
queue_offset_(0),
commit_log_offset_(0),
sys_flag_(0),
born_timestamp_(bornTimestamp),
born_host_(SockaddrToStorage(bornHost)),
store_timestamp_(storeTimestamp),
store_host_(SockaddrToStorage(storeHost)),
reconsume_times_(3),
prepared_transaction_offset_(0),
msg_id_(msgId) {}
MessageExtImpl::~MessageExtImpl() = default;
TopicFilterType MessageExtImpl::parseTopicFilterType(int32_t sysFlag) {
if ((sysFlag & MessageSysFlag::MULTI_TAGS_FLAG) == MessageSysFlag::MULTI_TAGS_FLAG) {
return MULTI_TAG;
}
return SINGLE_TAG;
}
int32_t MessageExtImpl::store_size() const {
return store_size_;
}
void MessageExtImpl::set_store_size(int32_t storeSize) {
store_size_ = storeSize;
}
int32_t MessageExtImpl::body_crc() const {
return body_crc_;
}
void MessageExtImpl::set_body_crc(int32_t bodyCRC) {
body_crc_ = bodyCRC;
}
int32_t MessageExtImpl::queue_id() const {
return queue_id_;
}
void MessageExtImpl::set_queue_id(int32_t queueId) {
queue_id_ = queueId;
}
int64_t MessageExtImpl::queue_offset() const {
return queue_offset_;
}
void MessageExtImpl::set_queue_offset(int64_t queueOffset) {
queue_offset_ = queueOffset;
}
int64_t MessageExtImpl::commit_log_offset() const {
return commit_log_offset_;
}
void MessageExtImpl::set_commit_log_offset(int64_t physicOffset) {
commit_log_offset_ = physicOffset;
}
int32_t MessageExtImpl::sys_flag() const {
return sys_flag_;
}
void MessageExtImpl::set_sys_flag(int32_t sysFlag) {
sys_flag_ = sysFlag;
}
int64_t MessageExtImpl::born_timestamp() const {
return born_timestamp_;
}
void MessageExtImpl::set_born_timestamp(int64_t bornTimestamp) {
born_timestamp_ = bornTimestamp;
}
const struct sockaddr* MessageExtImpl::born_host() const {
return reinterpret_cast<sockaddr*>(born_host_.get());
}
std::string MessageExtImpl::born_host_string() const {
return SockaddrToString(born_host());
}
void MessageExtImpl::set_born_host(const struct sockaddr* bornHost) {
born_host_ = SockaddrToStorage(bornHost);
}
int64_t MessageExtImpl::store_timestamp() const {
return store_timestamp_;
}
void MessageExtImpl::set_store_timestamp(int64_t storeTimestamp) {
store_timestamp_ = storeTimestamp;
}
const struct sockaddr* MessageExtImpl::store_host() const {
return reinterpret_cast<sockaddr*>(store_host_.get());
}
std::string MessageExtImpl::store_host_string() const {
return SockaddrToString(store_host());
}
void MessageExtImpl::set_store_host(const struct sockaddr* storeHost) {
store_host_ = SockaddrToStorage(storeHost);
}
const std::string& MessageExtImpl::msg_id() const {
return msg_id_;
}
void MessageExtImpl::set_msg_id(const std::string& msgId) {
msg_id_ = msgId;
}
int32_t MessageExtImpl::reconsume_times() const {
return reconsume_times_;
}
void MessageExtImpl::set_reconsume_times(int32_t reconsumeTimes) {
reconsume_times_ = reconsumeTimes;
}
int64_t MessageExtImpl::prepared_transaction_offset() const {
return prepared_transaction_offset_;
}
void MessageExtImpl::set_prepared_transaction_offset(int64_t preparedTransactionOffset) {
prepared_transaction_offset_ = preparedTransactionOffset;
}
std::string MessageExtImpl::toString() const {
std::stringstream ss;
ss << "MessageExt [queueId=" << queue_id_ << ", storeSize=" << store_size_ << ", queueOffset=" << queue_offset_
<< ", sysFlag=" << sys_flag_ << ", bornTimestamp=" << born_timestamp_ << ", bornHost=" << born_host_string()
<< ", storeTimestamp=" << store_timestamp_ << ", storeHost=" << store_host_string() << ", msgId=" << msg_id()
<< ", commitLogOffset=" << commit_log_offset_ << ", bodyCRC=" << body_crc_
<< ", reconsumeTimes=" << reconsume_times_ << ", preparedTransactionOffset=" << prepared_transaction_offset_
<< ", toString()=" << MessageImpl::toString() << "]";
return ss.str();
}
// ============================
// MessageClientExtImpl
// ============================
const std::string& MessageClientExtImpl::msg_id() const {
const auto& unique_id = MessageClientIDSetter::getUniqID(*this);
return unique_id.empty() ? offset_msg_id() : unique_id;
}
void MessageClientExtImpl::set_msg_id(const std::string& msgId) {
// DO NOTHING
// MessageClientIDSetter::setUniqID(*this);
}
const std::string& MessageClientExtImpl::offset_msg_id() const {
return MessageExtImpl::msg_id();
}
void MessageClientExtImpl::set_offset_msg_id(const std::string& offsetMsgId) {
return MessageExtImpl::set_msg_id(offsetMsgId);
}
} // namespace rocketmq