|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +#ifndef PULSAR_SAME_AUTH_PARAMS_LOOKUP_AUTO_CLUSTER_FAILOVER_H_ |
| 20 | +#define PULSAR_SAME_AUTH_PARAMS_LOOKUP_AUTO_CLUSTER_FAILOVER_H_ |
| 21 | + |
| 22 | +#include <pulsar/ClientConfiguration.h> |
| 23 | +#include <pulsar/ServiceInfoProvider.h> |
| 24 | + |
| 25 | +#include <chrono> |
| 26 | +#include <cstdint> |
| 27 | +#include <functional> |
| 28 | +#include <memory> |
| 29 | +#include <string> |
| 30 | +#include <vector> |
| 31 | + |
| 32 | +namespace pulsar { |
| 33 | + |
| 34 | +class SameAuthParamsLookupAutoClusterFailoverImpl; |
| 35 | + |
| 36 | +class PULSAR_PUBLIC SameAuthParamsLookupAutoClusterFailover final : public ServiceInfoProvider { |
| 37 | + public: |
| 38 | + struct Config { |
| 39 | + std::vector<std::string> serviceUrls; |
| 40 | + ClientConfiguration clientConfiguration; |
| 41 | + uint32_t failoverThreshold{5}; |
| 42 | + uint32_t recoverThreshold{5}; |
| 43 | + std::chrono::milliseconds checkHealthyInterval{1000}; |
| 44 | + bool markTopicNotFoundAsAvailable{true}; |
| 45 | + std::string testTopic{"public/default/tp_test"}; |
| 46 | + |
| 47 | + Config(std::vector<std::string> serviceUrls, ClientConfiguration clientConfiguration = {}); |
| 48 | + }; |
| 49 | + |
| 50 | + class Builder { |
| 51 | + public: |
| 52 | + explicit Builder(std::vector<std::string> serviceUrls, ClientConfiguration clientConfiguration = {}); |
| 53 | + |
| 54 | + Builder& withFailoverThreshold(uint32_t threshold); |
| 55 | + Builder& withRecoverThreshold(uint32_t threshold); |
| 56 | + Builder& withCheckHealthyInterval(std::chrono::milliseconds interval); |
| 57 | + Builder& withMarkTopicNotFoundAsAvailable(bool enabled); |
| 58 | + Builder& withTestTopic(std::string testTopic); |
| 59 | + |
| 60 | + SameAuthParamsLookupAutoClusterFailover build(); |
| 61 | + |
| 62 | + private: |
| 63 | + Config config_; |
| 64 | + }; |
| 65 | + |
| 66 | + explicit SameAuthParamsLookupAutoClusterFailover(Config&& config); |
| 67 | + |
| 68 | + ~SameAuthParamsLookupAutoClusterFailover() final; |
| 69 | + |
| 70 | + ServiceInfo initialServiceInfo() final; |
| 71 | + |
| 72 | + void initialize(std::function<void(ServiceInfo)> onServiceInfoUpdate) final; |
| 73 | + |
| 74 | + private: |
| 75 | + friend class SameAuthParamsLookupAutoClusterFailoverImpl; |
| 76 | + |
| 77 | + static ServiceInfo toServiceInfo(const ClientConfiguration& clientConfiguration, |
| 78 | + const std::string& serviceUrl); |
| 79 | + |
| 80 | + std::shared_ptr<SameAuthParamsLookupAutoClusterFailoverImpl> impl_; |
| 81 | +}; |
| 82 | + |
| 83 | +} // namespace pulsar |
| 84 | + |
| 85 | +#endif |
0 commit comments