Skip to content

Commit 9b239c9

Browse files
jonnxuShannonDing
authored andcommitted
Format project with clang-format Chromium (#131)
* Format project with clang-format Chromium * Update the format of comment Update the format of comment
1 parent 6812341 commit 9b239c9

File tree

217 files changed

+7581
-8023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+7581
-8023
lines changed

.clang-format

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
BasedOnStyle: Chromium
22
ColumnLimit: 120
3-
IndentWidth: 4
4-
DerivePointerAlignment: false
5-
IndentCaseLabels: false
6-
PointerAlignment: Right
7-
SpaceAfterCStyleCast: true
3+
TabWidth: 2

example/AsyncProducer.cpp

100755100644
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ class MyAutoDeleteSendCallback : public AutoDeleteSendCallBack {
5757
g_finished.notify_one();
5858
}
5959
}
60-
virtual void onException(MQException& e) {
61-
std::cout << "send Exception" << e << "\n";
62-
}
60+
virtual void onException(MQException& e) { std::cout << "send Exception" << e << "\n"; }
6361
};
6462

65-
void AsyncProducerWorker(RocketmqSendAndConsumerArgs* info,
66-
DefaultMQProducer* producer) {
63+
void AsyncProducerWorker(RocketmqSendAndConsumerArgs* info, DefaultMQProducer* producer) {
6764
while (!g_quit.load()) {
6865
if (g_msgCount.load() <= 0) {
6966
std::unique_lock<std::mutex> lck(g_mtx);
@@ -99,7 +96,8 @@ int main(int argc, char* argv[]) {
9996

10097
PrintRocketmqSendAndConsumerArgs(info);
10198

102-
if (!info.namesrv.empty()) producer.setNamesrvAddr(info.namesrv);
99+
if (!info.namesrv.empty())
100+
producer.setNamesrvAddr(info.namesrv);
103101

104102
producer.setGroupName(info.groupname);
105103
producer.setInstanceName(info.groupname);
@@ -110,8 +108,7 @@ int main(int argc, char* argv[]) {
110108
auto start = std::chrono::system_clock::now();
111109
int msgcount = g_msgCount.load();
112110
for (int j = 0; j < info.thread_count; j++) {
113-
std::shared_ptr<std::thread> th =
114-
std::make_shared<std::thread>(AsyncProducerWorker, &info, &producer);
111+
std::shared_ptr<std::thread> th = std::make_shared<std::thread>(AsyncProducerWorker, &info, &producer);
115112
work_pool.push_back(th);
116113
}
117114

@@ -122,12 +119,10 @@ int main(int argc, char* argv[]) {
122119
}
123120

124121
auto end = std::chrono::system_clock::now();
125-
auto duration =
126-
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
122+
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
127123

128-
std::cout
129-
<< "per msg time: " << duration.count() / (double)msgcount << "ms \n"
130-
<< "========================finished==============================\n";
124+
std::cout << "per msg time: " << duration.count() / (double)msgcount << "ms \n"
125+
<< "========================finished==============================\n";
131126

132127
producer.shutdown();
133128
for (size_t th = 0; th != work_pool.size(); ++th) {

example/AsyncPushConsumer.cpp

100755100644
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MyMsgListener : public MessageListenerConcurrently {
3737
MyMsgListener() {}
3838
virtual ~MyMsgListener() {}
3939

40-
virtual ConsumeStatus consumeMessage(const std::vector<MQMessageExt> &msgs) {
40+
virtual ConsumeStatus consumeMessage(const std::vector<MQMessageExt>& msgs) {
4141
g_msgCount.store(g_msgCount.load() - msgs.size());
4242
for (size_t i = 0; i < msgs.size(); ++i) {
4343
g_tps.Increment();
@@ -51,7 +51,7 @@ class MyMsgListener : public MessageListenerConcurrently {
5151
}
5252
};
5353

54-
int main(int argc, char *argv[]) {
54+
int main(int argc, char* argv[]) {
5555
RocketmqSendAndConsumerArgs info;
5656
if (!ParseArgs(argc, argv, &info)) {
5757
exit(-1);
@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
8282

8383
try {
8484
consumer.start();
85-
} catch (MQClientException &e) {
85+
} catch (MQClientException& e) {
8686
cout << e << endl;
8787
}
8888
g_tps.start();
@@ -95,7 +95,7 @@ int main(int argc, char *argv[]) {
9595

9696
try {
9797
producer.send(msg);
98-
} catch (MQException &e) {
98+
} catch (MQException& e) {
9999
std::cout << e << endl; // if catch excepiton , need re-send this msg by
100100
// service
101101
}

example/BatchProducer.cpp

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -34,97 +34,91 @@ std::mutex g_mtx;
3434
std::condition_variable g_finished;
3535
TpsReportService g_tps;
3636

37-
void SyncProducerWorker(RocketmqSendAndConsumerArgs* info,
38-
DefaultMQProducer* producer) {
39-
while (!g_quit.load()) {
40-
if (g_msgCount.load() <= 0) {
41-
std::unique_lock<std::mutex> lck(g_mtx);
42-
g_finished.notify_one();
43-
break;
44-
}
37+
void SyncProducerWorker(RocketmqSendAndConsumerArgs* info, DefaultMQProducer* producer) {
38+
while (!g_quit.load()) {
39+
if (g_msgCount.load() <= 0) {
40+
std::unique_lock<std::mutex> lck(g_mtx);
41+
g_finished.notify_one();
42+
break;
43+
}
4544

46-
vector<MQMessage> msgs;
47-
MQMessage msg1(info->topic, "*", info->body);
48-
msg1.setProperty("property1", "value1");
49-
MQMessage msg2(info->topic, "*", info->body);
50-
msg2.setProperty("property1", "value1");
51-
msg2.setProperty("property2", "value2");
52-
MQMessage msg3(info->topic, "*", info->body);
53-
msg3.setProperty("property1", "value1");
54-
msg3.setProperty("property2", "value2");
55-
msg3.setProperty("property3", "value3");
56-
msgs.push_back(msg1);
57-
msgs.push_back(msg2);
58-
msgs.push_back(msg3);
59-
try {
60-
auto start = std::chrono::system_clock::now();
61-
SendResult sendResult = producer->send(msgs);
62-
g_tps.Increment();
63-
--g_msgCount;
64-
auto end = std::chrono::system_clock::now();
65-
auto duration =
66-
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
67-
if (duration.count() >= 500) {
68-
std::cout << "send RT more than: " << duration.count()
69-
<< " ms with msgid: " << sendResult.getMsgId() << endl;
70-
}
71-
} catch (const MQException& e) {
72-
std::cout << "send failed: " << e.what() << std::endl;
73-
std::unique_lock<std::mutex> lck(g_mtx);
74-
g_finished.notify_one();
75-
return;
76-
}
45+
vector<MQMessage> msgs;
46+
MQMessage msg1(info->topic, "*", info->body);
47+
msg1.setProperty("property1", "value1");
48+
MQMessage msg2(info->topic, "*", info->body);
49+
msg2.setProperty("property1", "value1");
50+
msg2.setProperty("property2", "value2");
51+
MQMessage msg3(info->topic, "*", info->body);
52+
msg3.setProperty("property1", "value1");
53+
msg3.setProperty("property2", "value2");
54+
msg3.setProperty("property3", "value3");
55+
msgs.push_back(msg1);
56+
msgs.push_back(msg2);
57+
msgs.push_back(msg3);
58+
try {
59+
auto start = std::chrono::system_clock::now();
60+
SendResult sendResult = producer->send(msgs);
61+
g_tps.Increment();
62+
--g_msgCount;
63+
auto end = std::chrono::system_clock::now();
64+
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
65+
if (duration.count() >= 500) {
66+
std::cout << "send RT more than: " << duration.count() << " ms with msgid: " << sendResult.getMsgId() << endl;
67+
}
68+
} catch (const MQException& e) {
69+
std::cout << "send failed: " << e.what() << std::endl;
70+
std::unique_lock<std::mutex> lck(g_mtx);
71+
g_finished.notify_one();
72+
return;
7773
}
74+
}
7875
}
7976

8077
int main(int argc, char* argv[]) {
81-
RocketmqSendAndConsumerArgs info;
82-
if (!ParseArgs(argc, argv, &info)) {
83-
exit(-1);
84-
}
85-
PrintRocketmqSendAndConsumerArgs(info);
86-
DefaultMQProducer producer("please_rename_unique_group_name");
87-
producer.setNamesrvAddr(info.namesrv);
88-
producer.setNamesrvDomain(info.namesrv_domain);
89-
producer.setGroupName(info.groupname);
90-
producer.setInstanceName(info.groupname);
91-
producer.setSessionCredentials("mq acesskey", "mq secretkey", "ALIYUN");
92-
producer.setSendMsgTimeout(500);
93-
producer.setTcpTransportTryLockTimeout(1000);
94-
producer.setTcpTransportConnectTimeout(400);
78+
RocketmqSendAndConsumerArgs info;
79+
if (!ParseArgs(argc, argv, &info)) {
80+
exit(-1);
81+
}
82+
PrintRocketmqSendAndConsumerArgs(info);
83+
DefaultMQProducer producer("please_rename_unique_group_name");
84+
producer.setNamesrvAddr(info.namesrv);
85+
producer.setNamesrvDomain(info.namesrv_domain);
86+
producer.setGroupName(info.groupname);
87+
producer.setInstanceName(info.groupname);
88+
producer.setSessionCredentials("mq acesskey", "mq secretkey", "ALIYUN");
89+
producer.setSendMsgTimeout(500);
90+
producer.setTcpTransportTryLockTimeout(1000);
91+
producer.setTcpTransportConnectTimeout(400);
9592

96-
producer.start();
97-
std::vector<std::shared_ptr<std::thread>> work_pool;
98-
auto start = std::chrono::system_clock::now();
99-
int msgcount = g_msgCount.load();
100-
g_tps.start();
93+
producer.start();
94+
std::vector<std::shared_ptr<std::thread>> work_pool;
95+
auto start = std::chrono::system_clock::now();
96+
int msgcount = g_msgCount.load();
97+
g_tps.start();
10198

102-
int threadCount = info.thread_count;
103-
for (int j = 0; j < threadCount; j++) {
104-
std::shared_ptr<std::thread> th =
105-
std::make_shared<std::thread>(SyncProducerWorker, &info, &producer);
106-
work_pool.push_back(th);
107-
}
99+
int threadCount = info.thread_count;
100+
for (int j = 0; j < threadCount; j++) {
101+
std::shared_ptr<std::thread> th = std::make_shared<std::thread>(SyncProducerWorker, &info, &producer);
102+
work_pool.push_back(th);
103+
}
108104

109-
{
110-
std::unique_lock<std::mutex> lck(g_mtx);
111-
g_finished.wait(lck);
112-
g_quit.store(true);
113-
}
105+
{
106+
std::unique_lock<std::mutex> lck(g_mtx);
107+
g_finished.wait(lck);
108+
g_quit.store(true);
109+
}
114110

115-
auto end = std::chrono::system_clock::now();
116-
auto duration =
117-
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
111+
auto end = std::chrono::system_clock::now();
112+
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
118113

119-
std::cout
120-
<< "per msg time: " << duration.count() / (double)msgcount << "ms \n"
114+
std::cout << "per msg time: " << duration.count() / (double)msgcount << "ms \n"
121115
<< "========================finished==============================\n";
122116

123-
for (size_t th = 0; th != work_pool.size(); ++th) {
124-
work_pool[th]->join();
125-
}
117+
for (size_t th = 0; th != work_pool.size(); ++th) {
118+
work_pool[th]->join();
119+
}
126120

127-
producer.shutdown();
121+
producer.shutdown();
128122

129-
return 0;
123+
return 0;
130124
}

example/CAsyncProducer.c

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,61 +29,60 @@
2929

3030
void thread_sleep(unsigned milliseconds) {
3131
#ifdef _WIN32
32-
Sleep(milliseconds);
32+
Sleep(milliseconds);
3333
#else
34-
usleep(milliseconds * 1000); // takes microseconds
34+
usleep(milliseconds * 1000); // takes microseconds
3535
#endif
3636
}
3737

38-
void SendSuccessCallback(CSendResult result){
39-
printf("async send success, msgid:%s\n", result.msgId);
38+
void SendSuccessCallback(CSendResult result) {
39+
printf("async send success, msgid:%s\n", result.msgId);
4040
}
4141

42-
void SendExceptionCallback(CMQException e){
43-
char msg[1024];
44-
snprintf(msg, sizeof(msg), "error:%d, msg:%s, file:%s:%d", e.error, e.msg, e.file, e.line);
45-
printf("async send exception %s\n", msg);
42+
void SendExceptionCallback(CMQException e) {
43+
char msg[1024];
44+
snprintf(msg, sizeof(msg), "error:%d, msg:%s, file:%s:%d", e.error, e.msg, e.file, e.line);
45+
printf("async send exception %s\n", msg);
4646
}
4747

48-
void StartSendMessage(CProducer *producer) {
49-
int i = 0;
50-
int ret_code = 0;
51-
char body[128];
52-
CMessage *msg = CreateMessage("T_TestTopic");
53-
SetMessageTags(msg, "Test_Tag");
54-
SetMessageKeys(msg, "Test_Keys");
55-
for (i = 0; i < 10; i++) {
56-
memset(body, 0, sizeof(body));
57-
snprintf(body, sizeof(body), "new message body, index %d", i);
58-
SetMessageBody(msg, body);
59-
ret_code = SendMessageAsync(producer, msg, SendSuccessCallback , SendExceptionCallback);
60-
printf("async send message[%d] return code: %d\n", i, ret_code);
61-
thread_sleep(1000);
62-
}
63-
DestroyMessage(msg);
48+
void StartSendMessage(CProducer* producer) {
49+
int i = 0;
50+
int ret_code = 0;
51+
char body[128];
52+
CMessage* msg = CreateMessage("T_TestTopic");
53+
SetMessageTags(msg, "Test_Tag");
54+
SetMessageKeys(msg, "Test_Keys");
55+
for (i = 0; i < 10; i++) {
56+
memset(body, 0, sizeof(body));
57+
snprintf(body, sizeof(body), "new message body, index %d", i);
58+
SetMessageBody(msg, body);
59+
ret_code = SendMessageAsync(producer, msg, SendSuccessCallback, SendExceptionCallback);
60+
printf("async send message[%d] return code: %d\n", i, ret_code);
61+
thread_sleep(1000);
62+
}
63+
DestroyMessage(msg);
6464
}
6565

66-
void CreateProducerAndStartSendMessage(int i){
67-
printf("Producer Initializing.....\n");
68-
CProducer *producer = CreateProducer("Group_producer");
69-
SetProducerNameServerAddress(producer, "127.0.0.1:9876");
70-
if(i == 1){
71-
SetProducerSendMsgTimeout(producer , 3);
72-
}
73-
StartProducer(producer);
74-
printf("Producer start.....\n");
75-
StartSendMessage(producer);
76-
ShutdownProducer(producer);
77-
DestroyProducer(producer);
78-
printf("Producer Shutdown!\n");
66+
void CreateProducerAndStartSendMessage(int i) {
67+
printf("Producer Initializing.....\n");
68+
CProducer* producer = CreateProducer("Group_producer");
69+
SetProducerNameServerAddress(producer, "127.0.0.1:9876");
70+
if (i == 1) {
71+
SetProducerSendMsgTimeout(producer, 3);
72+
}
73+
StartProducer(producer);
74+
printf("Producer start.....\n");
75+
StartSendMessage(producer);
76+
ShutdownProducer(producer);
77+
DestroyProducer(producer);
78+
printf("Producer Shutdown!\n");
7979
}
8080

81-
int main(int argc, char *argv[]) {
82-
printf("Send Async successCallback.....\n");
83-
CreateProducerAndStartSendMessage(0);
81+
int main(int argc, char* argv[]) {
82+
printf("Send Async successCallback.....\n");
83+
CreateProducerAndStartSendMessage(0);
8484

85-
printf("Send Async exceptionCallback.....\n");
86-
CreateProducerAndStartSendMessage(1);
87-
return 0;
85+
printf("Send Async exceptionCallback.....\n");
86+
CreateProducerAndStartSendMessage(1);
87+
return 0;
8888
}
89-

0 commit comments

Comments
 (0)