You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2022/07/11 03:39:20 UTC
[rocketmq-clients] branch cpp_dev updated: BugFix: add an layer of indirection to fit with unique_ptr and shared_ptr
This is an automated email from the ASF dual-hosted git repository.
lizhanhui pushed a commit to branch cpp_dev
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
The following commit(s) were added to refs/heads/cpp_dev by this push:
new 0bf0947 BugFix: add an layer of indirection to fit with unique_ptr and shared_ptr
0bf0947 is described below
commit 0bf0947baec5ecc8a6e07ba1f533d93937b2edc0
Author: Li Zhanhui <li...@gmail.com>
AuthorDate: Mon Jul 11 11:39:12 2022 +0800
BugFix: add an layer of indirection to fit with unique_ptr and shared_ptr
---
cpp/src/main/cpp/rocketmq/ClientImpl.cpp | 5 ++--
cpp/src/main/cpp/rocketmq/include/ClientImpl.h | 2 +-
cpp/src/main/cpp/stats/OpencensusHandler.cpp | 31 +++++++++++++++++++++
cpp/src/main/cpp/stats/include/OpencensusHandler.h | 32 ++++++++++++++++++++++
4 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/cpp/src/main/cpp/rocketmq/ClientImpl.cpp b/cpp/src/main/cpp/rocketmq/ClientImpl.cpp
index 9ef47be..ec3de9e 100644
--- a/cpp/src/main/cpp/rocketmq/ClientImpl.cpp
+++ b/cpp/src/main/cpp/rocketmq/ClientImpl.cpp
@@ -36,7 +36,6 @@
#include "InvocationContext.h"
#include "LoggerImpl.h"
#include "MessageExt.h"
-#include "MetricBidiReactor.h"
#include "NamingScheme.h"
#include "SessionImpl.h"
#include "Signature.h"
@@ -186,7 +185,7 @@ void ClientImpl::start() {
break;
}
default: {
- SPDLOG_ERROR("Unknown address scheme");
+ SPDLOG_ERROR("Unknown metric address scheme");
}
}
@@ -210,7 +209,7 @@ void ClientImpl::start() {
opencensus::stats::StatsExporter::SetInterval(absl::Minutes(1));
#endif
- opencensus::stats::StatsExporter::RegisterPushHandler(absl::make_unique<OpencensusExporter>(target, client_weak_ptr));
+ opencensus::stats::StatsExporter::RegisterPushHandler(absl::make_unique<OpencensusHandler>(target, client_weak_ptr));
}
void ClientImpl::shutdown() {
diff --git a/cpp/src/main/cpp/rocketmq/include/ClientImpl.h b/cpp/src/main/cpp/rocketmq/include/ClientImpl.h
index e820351..b9912dc 100644
--- a/cpp/src/main/cpp/rocketmq/include/ClientImpl.h
+++ b/cpp/src/main/cpp/rocketmq/include/ClientImpl.h
@@ -30,7 +30,7 @@
#include "InvocationContext.h"
#include "MessageExt.h"
#include "NameServerResolver.h"
-#include "OpencensusExporter.h"
+#include "OpencensusHandler.h"
#include "RpcClient.h"
#include "Session.h"
#include "TelemetryBidiReactor.h"
diff --git a/cpp/src/main/cpp/stats/OpencensusHandler.cpp b/cpp/src/main/cpp/stats/OpencensusHandler.cpp
new file mode 100644
index 0000000..422108d
--- /dev/null
+++ b/cpp/src/main/cpp/stats/OpencensusHandler.cpp
@@ -0,0 +1,31 @@
+/*
+ * 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 "OpencensusHandler.h"
+
+#include "MetricBidiReactor.h"
+
+ROCKETMQ_NAMESPACE_BEGIN
+
+OpencensusHandler::OpencensusHandler(std::string endpoints, std::weak_ptr<Client> client)
+ : exporter_(std::make_shared<OpencensusExporter>(std::move(endpoints), std::move(client))) {
+}
+
+void OpencensusHandler::ExportViewData(const MetricData& data) {
+ exporter_->ExportViewData(data);
+}
+
+ROCKETMQ_NAMESPACE_END
\ No newline at end of file
diff --git a/cpp/src/main/cpp/stats/include/OpencensusHandler.h b/cpp/src/main/cpp/stats/include/OpencensusHandler.h
new file mode 100644
index 0000000..5c6ec1f
--- /dev/null
+++ b/cpp/src/main/cpp/stats/include/OpencensusHandler.h
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+#pragma once
+
+#include "OpencensusExporter.h"
+
+ROCKETMQ_NAMESPACE_BEGIN
+
+class OpencensusHandler : public opencensus::stats::StatsExporter::Handler {
+public:
+ OpencensusHandler(std::string endpoints, std::weak_ptr<Client> client);
+
+ void ExportViewData(const MetricData& data) override;
+
+ std::shared_ptr<OpencensusExporter> exporter_;
+};
+
+ROCKETMQ_NAMESPACE_END
\ No newline at end of file