Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
load_balancer.h
1/*
2 * Copyright (c) 2008-2025, Hazelcast, Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include "hazelcast/util/export.h"
19#include "hazelcast/client/member.h"
20
21namespace hazelcast {
22namespace client {
23
24class cluster;
25
26namespace connection {
27class ClientConnectionManagerImpl;
28}
29
40class HAZELCAST_API load_balancer final
41{
42public:
50 template<typename Handler,
51 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
52 load_balancer& init(Handler&& h) &
53 {
54 init_ = std::forward<Handler>(h);
55 return *this;
56 }
57
58 template<typename Handler,
59 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
60 load_balancer&& init(Handler&& h) &&
61 {
62 init_ = std::forward<Handler>(h);
63 return std::move(*this);
64 }
65
71 template<typename Handler,
72 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
73 load_balancer& next(Handler&& h) &
74 {
75 next_ = std::forward<Handler>(h);
76 return *this;
77 }
78
79 template<typename Handler,
80 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
81 load_balancer&& next(Handler&& h) &&
82 {
83 next_ = std::forward<Handler>(h);
84 return std::move(*this);
85 }
86
87private:
92 std::function<void(cluster&)> init_ = util::noop<cluster&>;
93 std::function<boost::optional<member>(cluster&)> next_ = [](cluster&) {
94 return boost::none;
95 };
96
97 friend class connection::ClientConnectionManagerImpl;
98};
99} // namespace client
100} // namespace hazelcast
Hazelcast cluster interface.
Definition cluster.h:37
load_balancer allows you to send operations to one of a number of endpoints(Members).
load_balancer & init(Handler &&h) &
Sets the function to be called when load balancer is initialized.
load_balancer & next(Handler &&h) &
The function returns the next member to route to.