Apache Ignite C++ Client
Loading...
Searching...
No Matches
ignite_client_configuration.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <ignite/client/ignite_client_authenticator.h>
21#include <ignite/client/ignite_logger.h>
23
24#include <ignite/common/ignite_error.h>
25
26#include <initializer_list>
27#include <memory>
28#include <chrono>
29#include <string>
30#include <vector>
31#include <detail/config.h>
32
33namespace ignite {
34
38class ignite_client_configuration {
39public:
43 static constexpr std::uint16_t DEFAULT_PORT = 10800;
44
48 static constexpr std::chrono::microseconds DEFAULT_HEARTBEAT_INTERVAL = std::chrono::seconds(30);
49
50 // Default
51 ignite_client_configuration() = default;
52
58 ignite_client_configuration(std::initializer_list<std::string_view> endpoints)
59 : m_endpoints(endpoints.begin(), endpoints.end()) {
60 check_endpoints_non_empty(m_endpoints);
61 }
62
68 ignite_client_configuration(std::vector<std::string> endpoints) // NOLINT(google-explicit-constructor)
69 : m_endpoints(std::move(endpoints)) {
70 check_endpoints_non_empty(m_endpoints);
71 }
72
80 [[nodiscard]] const std::vector<std::string> &get_endpoints() const { return m_endpoints; }
81
95 void set_endpoints(std::initializer_list<std::string_view> endpoints) {
96 std::vector<std::string> endpoints0(endpoints.begin(), endpoints.end());
97 set_endpoints(endpoints0);
98 }
99
113 void set_endpoints(std::vector<std::string> endpoints) {
114 check_endpoints_non_empty(endpoints);
115 m_endpoints = std::move(endpoints);
116 }
117
123 [[nodiscard]] const std::shared_ptr<ignite_logger> &get_logger() const { return m_logger; }
124
132 void set_logger(std::shared_ptr<ignite_logger> logger) { m_logger = std::move(logger); }
133
147 [[nodiscard]] std::uint32_t get_connection_limit() const { return m_connection_limit; }
148
156 void set_connection_limit(std::uint32_t limit) { m_connection_limit = limit; }
157
172 [[nodiscard]] std::chrono::microseconds get_heartbeat_interval() const { return m_heartbeat_interval; }
173
181 void set_heartbeat_interval(std::chrono::microseconds heartbeat_interval) {
182 if (heartbeat_interval.count() < 0) {
183 throw ignite_error(error::code::ILLEGAL_ARGUMENT, "Heartbeat interval can not be negative: "
184 + std::to_string(heartbeat_interval.count()) + " microseconds");
185 }
186
187 m_heartbeat_interval = heartbeat_interval;
188 }
189
197 [[nodiscard]] std::shared_ptr<ignite_client_authenticator> get_authenticator() const { return m_authenticator; }
198
204 void set_authenticator(std::shared_ptr<ignite_client_authenticator> authenticator) {
205 m_authenticator = std::move(authenticator);
206 }
207
215 [[nodiscard]] ssl_mode get_ssl_mode() const {
216 return m_ssl_mode;
217 }
218
227 m_ssl_mode = ssl_mode;
228 }
229
235 [[nodiscard]] const std::string& get_ssl_cert_file() const {
236 return m_ssl_cert_file;
237 }
238
244 void set_ssl_cert_file(const std::string& ssl_cert_file) {
245 m_ssl_cert_file = ssl_cert_file;
246 }
247
253 [[nodiscard]] const std::string& get_ssl_key_file() const {
254 return m_ssl_key_file;
255 }
256
262 void set_ssl_key_file(const std::string& ssl_key_file) {
263 m_ssl_key_file = ssl_key_file;
264 }
265
272 [[nodiscard]] const std::string& get_ssl_ca_file() const {
273 return m_ssl_ca_file;
274 }
275
282 void set_ssl_ca_file(const std::string& ssl_ca_file) {
283 m_ssl_ca_file = ssl_ca_file;
284 }
285
286private:
292 IGNITE_API static void check_endpoints_non_empty(const std::vector<std::string>& endpoints);
293
295 std::vector<std::string> m_endpoints{"localhost"};
296
298 std::shared_ptr<ignite_logger> m_logger{};
299
301 std::shared_ptr<ignite_client_authenticator> m_authenticator{};
302
304 std::uint32_t m_connection_limit{0};
305
307 std::chrono::microseconds m_heartbeat_interval{DEFAULT_HEARTBEAT_INTERVAL};
308
310 ssl_mode m_ssl_mode{ssl_mode::DISABLE};
311
313 std::string m_ssl_cert_file;
314
316 std::string m_ssl_key_file;
317
319 std::string m_ssl_ca_file;
320};
321
322} // namespace ignite
void set_heartbeat_interval(std::chrono::microseconds heartbeat_interval)
Definition ignite_client_configuration.h:181
void set_ssl_mode(ssl_mode ssl_mode)
Definition ignite_client_configuration.h:226
static constexpr std::uint16_t DEFAULT_PORT
Definition ignite_client_configuration.h:43
const std::shared_ptr< ignite_logger > & get_logger() const
Definition ignite_client_configuration.h:123
static constexpr std::chrono::microseconds DEFAULT_HEARTBEAT_INTERVAL
Definition ignite_client_configuration.h:48
void set_endpoints(std::vector< std::string > endpoints)
Definition ignite_client_configuration.h:113
ignite_client_configuration(std::initializer_list< std::string_view > endpoints)
Definition ignite_client_configuration.h:58
const std::string & get_ssl_cert_file() const
Definition ignite_client_configuration.h:235
void set_ssl_ca_file(const std::string &ssl_ca_file)
Definition ignite_client_configuration.h:282
const std::vector< std::string > & get_endpoints() const
Definition ignite_client_configuration.h:80
std::shared_ptr< ignite_client_authenticator > get_authenticator() const
Definition ignite_client_configuration.h:197
void set_logger(std::shared_ptr< ignite_logger > logger)
Definition ignite_client_configuration.h:132
std::uint32_t get_connection_limit() const
Definition ignite_client_configuration.h:147
void set_connection_limit(std::uint32_t limit)
Definition ignite_client_configuration.h:156
void set_authenticator(std::shared_ptr< ignite_client_authenticator > authenticator)
Definition ignite_client_configuration.h:204
void set_ssl_cert_file(const std::string &ssl_cert_file)
Definition ignite_client_configuration.h:244
ssl_mode get_ssl_mode() const
Definition ignite_client_configuration.h:215
const std::string & get_ssl_ca_file() const
Definition ignite_client_configuration.h:272
std::chrono::microseconds get_heartbeat_interval() const
Definition ignite_client_configuration.h:172
ignite_client_configuration(std::vector< std::string > endpoints)
Definition ignite_client_configuration.h:68
void set_ssl_key_file(const std::string &ssl_key_file)
Definition ignite_client_configuration.h:262
void set_endpoints(std::initializer_list< std::string_view > endpoints)
Definition ignite_client_configuration.h:95
const std::string & get_ssl_key_file() const
Definition ignite_client_configuration.h:253
Definition ignite_error.h:35
ssl_mode
Definition ssl_mode.h:30