BewareMyPower commented on code in PR #17410:
URL: https://github.com/apache/pulsar/pull/17410#discussion_r970916981


##########
pulsar-client-cpp/lib/RetryableLookupService.h:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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 <algorithm>
+#include <memory>
+#include "lib/Backoff.h"
+#include "lib/ExecutorService.h"
+#include "lib/LookupService.h"
+#include "lib/SynchronizedHashMap.h"
+#include "lib/LogUtils.h"
+
+namespace pulsar {
+
+class RetryableLookupService : public LookupService,
+                               public 
std::enable_shared_from_this<RetryableLookupService> {
+   private:
+    friend class PulsarFriend;
+    struct PassKey {
+        explicit PassKey() {}
+    };
+
+   public:
+    template <typename... Args>
+    explicit RetryableLookupService(PassKey, Args&&... args)
+        : RetryableLookupService(std::forward<Args>(args)...) {}
+
+    template <typename... Args>
+    static std::shared_ptr<RetryableLookupService> create(Args&&... args) {

Review Comment:
   It's a template code that leverages perfect forwarding to implement Passkey 
idiom. This wrapper will still work even if the constructor's signature changed 
in future.
   
   BTW, you can see the following blogs to learn more about the Passkey idiom:
   - 
https://www.spiria.com/en/blog/desktop-software/passkey-idiom-and-better-friendship-c/
   - 
https://stackoverflow.com/questions/8147027/how-do-i-call-stdmake-shared-on-a-class-with-only-protected-or-private-const
   - (Chinese) 
https://bewaremypower.github.io/2019/04/14/make-shared%E8%B0%83%E7%94%A8%E7%A7%81%E6%9C%89%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to